firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.28k stars 578 forks source link

Missing AppId #4479

Closed mandrachek closed 1 year ago

mandrachek commented 1 year ago

[READ] Step 1: Are you in the right place?

I believe this is the correct location. If it is not, please point me in the proper direction.

[REQUIRED] Step 2: Describe your environment

[REQUIRED] Step 3: Describe the problem

Unable to deploy the build to firebase. This is the output:


Uploading APK to Firebase App Distribution...
Using service credentials file specified by the serviceCredentialsFile property in your app's build.gradle file: firebase-credentials.json
Uploading the APK.

> Task :app:appDistributionUploadDevDebug FAILED

FAILURE: Build failed with an exception.

Execution failed for task ':app:appDistributionUploadDevDebug'.
> Cannot query the value of task ':app:appDistributionUploadDevDebug' property 'appId' because it has no value available.

Steps to reproduce:

Create a new app, ensure gradle is up to date. Add signingConfigs, buildTypes, and product flavors. Add google services gradle plugin Create firebase project and add apps for all your versions (e.g., $packageName.$flavorSuffix and $packageName.$flavorSuffix.debug) Download google-services.json file, place it app folder. Add firebase-appdistribution gradle plugin.

Project is configured to use google play services, and firebase app distribution with authentication via a serviceCredentialsFile.

2 build types, release and debug, and several product flavors (dev, qa, staging, and prod). All combinations are registered in firebase (com.app.type.flavor + com.app.flavor.debug).

run ./gradlew assembleDevDebug appDistributionUploadDevDebug

The google-services.json file is located in app/, and google services generates app/build/generated/res/google-services/dev/debug/values/values.xml - this contains an entry for google_app_id, which has the proper appId from google-services.json.

For some reason the appDistributionUploadDevDebug task fails to read the value. It doesn't matter if I run the assemble and distribution together, or as separate steps - the same error occurs.

Relevant Code:

top level build.gradle:

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
    id 'com.google.gms.google-services' version '4.3.13' apply false
    id 'com.google.firebase.appdistribution' version '3.1.1' apply false
}

app build.grade:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.appdistribution'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.myapp.myapplication'
    compileSdk 33

    defaultConfig {
        applicationId "com.myapp.myapplication"
        minSdk 29
        targetSdk 33
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }

    signingConfigs {

        release {
            storeFile file(project.findProperty('release_signing_keystore') ?: "${project.rootProject.projectDir}/config/keys/debug.keystore")
            storePassword project.findProperty('release_signing_store_password') ?: 'android'
            keyAlias project.findProperty('release_signing_key_alias') ?: 'androiddebugkey'
            keyPassword project.findProperty('release_signing_key_password') ?: 'android'
        }

        debug {
            storeFile file("${project.rootProject.projectDir}/config/keys/debug.keystore")
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }

        debug {
            debuggable = true
            signingConfig signingConfigs.debug
            applicationIdSuffix = ".debug"
        }
    }

    flavorDimensions "default"

    productFlavors {
        dev {
            applicationIdSuffix ".dev"
            dimension "default"
            firebaseAppDistribution {
                serviceCredentialsFile="${project.rootDir}/config/distribution-credentials.json"
            }
        }
        prod {
            dimension "default"
            firebaseAppDistribution {
                serviceCredentialsFile="${project.rootDir}/config/distribution-credentials.json"
            }
        }
        staging {
            dimension "default"
            firebaseAppDistribution {
                serviceCredentialsFile="${project.rootDir}/config/distribution-credentials.json"
            }
        }
        qa {
            dimension "default"
            firebaseAppDistribution {
                serviceCredentialsFile="${project.rootDir}/config/distribution-credentials.json"
            }
        }
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation platform('com.google.firebase:firebase-bom:31.1.1')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
}
google-oss-bot commented 1 year ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

mandrachek commented 1 year ago

If I downgrade the appdistribution plugin to 3.1.0, I get a different error:

App Distribution halted because it had a problem uploading the APK: [404] Requested entity was not found.

argzdev commented 1 year ago

Hi @mandrachek, thanks for reporting. While we investigate this, any chance you could provide a minimal reproducible example of your issue? It'll greatly help us investigate this further. Thanks!

mandrachek commented 1 year ago

@argzdev I explained how to setup a project to reproduce. You can use https://github.com/mandrachek/FirebaseDistributionExample but will need to configure your own firebase project, add the google-services.json, copy your debug keystore, and add your firebase service credentials.

argzdev commented 1 year ago

Hi @mandrachek, sorry for the delayed response here. I was able to reproduce the same behavior. That said, this seems to be similar to #4013. One of the solutions recommended here was:

caching values.xml between build stage to the firebase stage does resolve the issue with missing appId.

Could you try that and see if that works for you? Thanks!

mandrachek commented 1 year ago

@argzdev Not sure what you mean by "caching values.xml between build stage to the firebase stage". There's no example code on that tick on how to perform that. AFAIK, gradle doesn't have stages, it has tasks - not clear at all on how to do what you're asking.

mandrachek commented 1 year ago

@argzdev I noticed that what's called firebase stage on that ticket (./gradlew assembleDebug appDistributionUploadDebug), which the author of the ticket claims works. With the addition of the flavor, e.g., ./gradlew assembleDevDebug appDistributionUploadDevDebug, it does not work.

mandrachek commented 1 year ago

Oh my gosh. I tried adding --appId on the command line and specifying it that way. That too failed, but came up with an apparently useful error message:

App Distribution could not find your app ${appId}." Make sure to onboard your app by pressing the "Get started" button on the App Distribution page in the Firebase console:

   https://console.firebase.google.com/project/_/appdistribution

So I went to the app in app distribution, and sure enough there was a "Get started" button. Clicked it, and now ./gradlew appDistributionUploadDevDebug works just fine. So the error message when manually specifying the appId is correct, and useful, but the error message when using the values.xml is misleading and unhelpful.

argzdev commented 1 year ago

I'm glad you were able to resolve your issue, @mandrachek. I agree, the error message should be updated, even I got confused what was wrong here. And thanks for the follow up! I'm sure this'll help a lot of our fellow developers in the future once the error message is updated. I'll notify our engineers to have the error message fixed.

bearlysophisticated commented 1 year ago

@argzdev Why is that manual action "Get started" needed? Even after setting up the whole Firebase project and app distribution using CLI, the developer has to open the project page and dismiss a completely unhelpful landing page.

argzdev commented 1 year ago

Hi @bearlysophisticated, this is due to a Terms of Service check, but it's an area that we'd like to simplify in the future.

kaibolay commented 1 year ago

Hi @mandrachek

Thanks for the report and you patience while we worked on this.

The error message should be improved with version 3.2.0 of the plugin.

@bearlysophisticated We're working on making onboarding simpler - hopefully making the detour via the Firebase Console and pressing a button unnecessary.

bearlysophisticated commented 1 year ago

@kaibolay Thanks, this is much better!

I noticed that the URL in the error message has an underscore _ in place of the project id: https://console.firebase.google.com/project/_/appdistribution. Could you fix this as well ,so it points to the absolute location of the distribution page?

kaibolay commented 1 year ago

@bearlysophisticated Unfortunately (and surprisingly) it's not straightforward to replace that _ with an actual project id. The reasons are arcane: We'd need to translate the project number to a project id which would require an RPC which could fail. Also, we'd have to trust the project number (or app id) passed in as an argument - and that could be wrong - causing the link we'd output to be wrong.

So instead of trying to make that link more specific we'll focus our energy on making the click on ""Get started" obsolete - which in turn will make the link obsolete.