firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

Incorrect path selection for buildType + productFlavor combinations in AGP 8.7.0+

Open denzap opened this issue 1 year ago • 4 comments

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: Android Studio Ladybug | 2024.2.1 Patch 2
  • Firebase Component: App Distribution Gradle Plugin
  • Component version: 5.0.0

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

My project uses multiple buildType and productFlavor configurations as well as a dynamic feature module. I am using the com.google.firebase.appdistribution Gradle plugin to distribute a universal APK (due to the dynamic feature) through Firebase App Distribution.

To locate the correct APK, I override artifactPath in the AppDistributionExtension. Previously, this worked as expected, setting the appropriate path based on the buildType + productFlavor combination. However, after upgrading to AGP 8.7.0 or above, the artifactPath always retains the value of the last configured combination of buildType + productFlavor. As a result, when publishing to App Distribution, the plugin attempts to locate the APK at an incorrect path.

To illustrate the issue, I am attaching an archive with the project (I removed the dynamic feature setup for simplicity) TestApplication.zip, where two tasks can be run:

  1. ./gradlew :app:packageGoogleDebugUniversalApk - to build the universal APK.
  2. ./gradlew :app:appDistributionUploadGoogleDebug - to attempt to publish it.

If agp = 8.6.1 is specified in gradle/libs.versions.toml, everything works correctly, and the console displays a message like:

Using APK path specified by the artifactPath parameter in your app's build.gradle: some_path/app/build/outputs/apk_from_bundle/googleDebug/app-google-debug-universal.apk.

The subsequent error is expected since I haven’t configured publishing settings for the test.

However, if agp = 8.7.0 is specified in gradle/libs.versions.toml, the console shows a message like:

Using APK path specified by the artifactPath parameter in your app's build.gradle: some_path/app/build/outputs/apk_from_bundle/huaweiStore/app-huawei-store-universal.apk.

Regardless of the variant passed to appDistributionUpload, the plugin always attempts to locate the APK for the huaweiStore variant.

Question: How can I now set the artifactPath parameter of AppDistributionExtension so that it depends on both buildType and productFlavor?

denzap avatar Nov 13 '24 09:11 denzap

Hi @denzap, thank you for reaching out and sharing an MCVE. I was able to reproduce the issue you raised. I'll raise this to our engineers and see what we can do here.

As a workaround, for now, I suggest specifying the artifactPath on the command.

./gradlew appDistributionUploadGoogleDebug --artifactPath="<YOUR_BUILD_DIRECTORY>/outputs/apk_from_bundle/googleDebug/app-google-debug-universal.apk"

lehcar09 avatar Nov 13 '24 14:11 lehcar09

It's possible that you are affected by #6655 - please make sure that you use

import com.google.firebase.appdistribution.gradle.firebaseAppDistribution

in your build.gradle.kts file. See the documentation for more details.

I apologize for the confusing behavior.

kaibolay avatar Feb 07 '25 00:02 kaibolay

@kaibolay I'm using

import com.google.firebase.appdistribution.gradle.AppDistributionExtension

in my Plugin<Project> class, because I setup firebase plugin through convention gradle plugin.

You can see the setup in my MCVE attached to initial message of this topic.

denzap avatar Feb 10 '25 06:02 denzap

Thanks for clarifying. Sorry I didn't look closely enough.

The MCVE is very helpful..

kaibolay avatar Feb 10 '25 16:02 kaibolay