Search code examples
androidfirebasegradlefirebase-app-distribution

Firebase App Distribution failed to fetch app information: [400] Request contains an invalid argument on multi-firebase Android project setup


I have an Android app that has 2 different firebase projects, one for DEBUG builds and one for RELEASE and they have their google-services.json file respectively.

app
|-src/main/debug
| |-google-services.json (Points to Firebase with ID: `myapp-debug`)
|-src/main/release
| |-google-services.json (Points to Firebase with ID: `myapp-release`)

I have the app/build.gradle setup such that both RELEASE and DEBUG builds are posted to the myapp-debug Firebase project. The GOOGLE_APPLICATION_CREDENTIALS environment variable is set to service account JSON for myapp-debug Firebase project.

android {
    // ... more configs here
    buildTypes/debug {
        firebaseAppDistribution {
            releaseNotes = "DEBUG"
            apkPath = "/path/to/debug.apk"
            groups = "qa, devs"
        }


        buildTypes/release {
            firebaseAppDistribution {
                appId="myapp-debug" // Force release builds to same debug Firebase project
                releaseNotes = "RELEASE"
                apkPath = "/path/to/release.apk"
                groups = "qa, devs"
            }
        }
    }
}

However, when I build app, and try to publish using appDistributionUpload* command I get an error for RELEASE build.

./gradlew clean assembleDebug
./gradlew assembleRelease

./gradlew appDistributionUploadDebug         # This command succeeds
./gradlew appDistributionUploadRelease       # This one fails with failed to fetch app information

So, I am confused about what could go wrong here. What is the role of appId config inside firebaseAppDistribution block?


For reference, here is the log for each appDistributionUpload command.

> Task :ClassifiedsApp:appDistributionUploadDebug
Using APK path specified by the apkPath parameter in your app's build.gradle: /myapp/build/outputs/apk/debug/debug-app.apk.
Uploading APK to Firebase App Distribution...
Getting appId from output of google services plugin
Using credentials file specified by environment variable GOOGLE_APPLICATION_CREDENTIALS: ****
This APK has not been uploaded before.
Uploading the APK.
Uploaded APK successfully 202
Added release notes successfully 200
Added testers/groups successfully 200
App Distribution upload finished successfully!



> Task :ClassifiedsApp:appDistributionUploadRelease FAILED
Using APK path specified by the apkPath parameter in your app's build.gradle: /myapp/build/outputs/apk/release/release-app.apk.
Uploading APK to Firebase App Distribution...
Getting appId from build.gradle file
Using credentials file specified by environment variable GOOGLE_APPLICATION_CREDENTIALS: ****
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':ClassifiedsApp:appDistributionUploadRelease'.
> App Distribution failed to fetch app information: [400] Request contains an invalid argument.

Solution

  • I have contacted Firebase support team and Kyle from support team have reached back to me.

    My mistake was, based on documentation for appId it was referring to the mobilesdk_app_id, and NOT the Firebase project_id that I have used.

    See simplified google-services.json file below.

    {
       "project_info":{
          "project_id":"firebase-project-id"
       },
       "client":[
          {
             "client_info":{
                "mobilesdk_app_id":"1:543212345:android:93690bfb936b9c",
                "android_client_info":{
                   "package_name":"app.package.name"
                }
             }
          }
       ]
    }
    

    So, the fix was to use the mobilesdk_app_id value as appId in the firebaseAppDistribution block.

        buildTypes/release {
            firebaseAppDistribution {
                appId="1:543212345:android:93690bfb936b9c" // Force release builds to same debug Firebase project
                releaseNotes = "RELEASE"
                apkPath = "/path/to/release.apk"
                groups = "qa, devs"
            }
        }