firebase / quickstart-android

Firebase Quickstart Samples for Android
https://firebase.google.com
Apache License 2.0
8.9k stars 7.33k forks source link

Crashlytics found an invalid API key: null. #1000

Closed paulsUsername closed 4 years ago

paulsUsername commented 5 years ago

Step 1: Describe your environment

Step 2: Describe the problem:

If I try to run an instrument test I get the following error: Crashlytics found an invalid API key: null.

Steps to reproduce:

Install firebase crashlytics. Run Instrument Test.

Observed Results:

Crashlytics found an invalid API key: null.

Expected Results:

Test to run

Relevant Code:

@RunWith(AndroidJUnit4::class)
@SmallTest
class ExampleInstrumentedTest {

    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = InstrumentationRegistry.getInstrumentation().context
        assertEquals("com.mypackage", appContext.packageName)
    }
}
google-oss-bot commented 5 years ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

samtstern commented 5 years ago

@paulsUsername this sounds a bit like this issue: https://stackoverflow.com/questions/52614015/invalid-crashlytics-api-key-error-when-upgrading-to-android-gradle-plugin-3-3-0

Could you show me your build.gradle and app/build.gradle files in full so I can see if anything sticks out?

paulsUsername commented 5 years ago

Really sorry about the delay getting back to you. It's causing a lot of problems now. The only way we can release new builds, otherwise, we get:

No value has been specified for this provider.

Completely removing crashlytics resolves the issue

App Build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply from: '../common.gradle'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'

android {

    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 75
        versionName "2.0"
        multiDexEnabled true
        resConfigs 'en', 'fr', 'de', 'nl'
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        buildConfigField "String", "TILESERVER_URL", "\"" + project.ext.tileServerUrl + "\""
        signingConfig signingConfigs.debug
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }

    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            signingConfig signingConfigs.debug
            pseudoLocalesEnabled true
            ext.enableCrashlytics = true
        }
        paul {
            signingConfig signingConfigs.debug
            pseudoLocalesEnabled true
            ext.enableCrashlytics = false
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    useLibrary 'android.test.runner'
    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0'
    }
}

repositories {
    flatDir {
        dirs '../mapbox-gl-native/platform/android/MapboxGLAndroidSDK/build/outputs/aar'
    }
}

dependencies {

    implementation fileTree(dir: '../libs', include: ["*.jar", "*.aar"])
    implementation fileTree(dir: '../mapbox-gl-native/platform/android/MapboxGLAndroidSDK/build/outputs/aar', include: ["*.jar", "*.aar"])
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.2.0-alpha02'
    implementation 'androidx.viewpager:viewpager:1.0.0'

    // Required -- JUnit 4 framework
    testImplementation 'junit:junit:4.12'
    // Optional -- Robolectric environment
    // Optional -- Mockito framework
    testImplementation 'org.mockito:mockito-core:1.10.19'
    //Testing
    // Core library
    androidTestImplementation 'androidx.test:core:1.2.0'

    // AndroidJUnitRunner and JUnit Rules
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test:rules:1.2.0'

    // Assertions
//    androidTestImplementation 'androidx.test.ext:junit:1.2.0'
    androidTestImplementation 'androidx.test.ext:truth:1.2.0'
    androidTestImplementation 'com.google.truth:truth:0.42'

    // Espresso dependencies
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
    androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.2.0'

    // The following Espresso dependency can be either "implementation"
    // or "androidTestImplementation", depending on whether you want the
    // dependency to appear on your APK's compile classpath or the test APK
    // classpath.

    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'com.google.code.gson:gson:2.8.5'

    //Mapbox
    implementation("com.mapbox.mapboxsdk:mapbox-sdk-core:4.5.0")
    implementation("com.mapbox.mapboxsdk:mapbox-sdk-services:4.5.0")
    implementation("com.mapbox.mapboxsdk:mapbox-sdk-geojson:4.5.0")
    implementation("com.mapbox.mapboxsdk:mapbox-android-telemetry:4.2.0")
    implementation("com.mapbox.mapboxsdk:mapbox-android-gestures:0.4.0")

    implementation("com.google.maps.android:android-maps-utils:0.5")
    implementation("com.google.android.gms:play-services-maps:17.0.0")
    implementation("com.google.android.gms:play-services-auth:17.0.0")
    implementation("com.google.android.gms:play-services-location:17.0.0")

    //Glide
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    kapt 'com.github.bumptech.glide:compiler:4.9.0'

    //Firebase
    implementation 'com.firebaseui:firebase-ui-auth:4.3.2'
    implementation 'com.firebaseui:firebase-ui-storage:4.3.2'
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation 'com.google.firebase:firebase-storage:19.1.0'
    implementation 'com.google.firebase:firebase-database:19.2.0'
    implementation 'com.google.firebase:firebase-auth:19.2.0'
    implementation 'com.google.firebase:firebase-messaging:20.0.1'
    implementation 'com.google.firebase:firebase-dynamic-links:19.0.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'

    implementation 'androidx.cardview:cardview:1.0.0'

    //Charts
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'

    //Database
    implementation "android.arch.persistence.room:runtime:${roomVersion}"
    kapt "android.arch.persistence.room:compiler:${roomVersion}" // use kapt for Kotlin

    implementation "android.arch.lifecycle:extensions:1.1.1"
    implementation "androidx.lifecycle:lifecycle-common-java8:2.1.0"

    // Test helpers
    androidTestImplementation "android.arch.persistence.room:testing:${roomVersion}"

    //Range SeekBar
    implementation 'com.crystal:crystalrangeseekbar:1.1.3'

    implementation 'de.hdodenhof:circleimageview:3.0.0'

    //Facebook
    implementation 'com.facebook.android:facebook-android-sdk:5.0.1'
    implementation 'com.facebook.network.connectionclass:connectionclass:1.0.1'

    //ImageView FullScreen
//    implementation 'com.github.stfalcon:stfalcon-imageviewer:0.1.0'

    //Billing
    implementation "com.android.billingclient:billing:$version_billing"

    //EventBus
    implementation 'org.greenrobot:eventbus:3.1.1'
    //

    //Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-rc02'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-rc02'
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-2'

    //What 3 words
//    implementation project(path: ':imageviewer')

    implementation 'com.github.string-areeb:StfalconImageViewer:lateinit-check-SNAPSHOT'

    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
    implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.50"

}
apply plugin: 'com.google.gms.google-services'

Build.gradle:


buildscript {
    ext.kotlin_version = '1.3.50'
    ext.version_billing = '2.0.2'
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven {
            url 'https://jitpack.io'
        }
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'com.android.tools.build:gradle:3.6.0-beta04'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.novoda:bintray-release:0.9'

        classpath 'io.fabric.tools:gradle:1.31.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

common.gradle:

ext {

    gmsVersion = '9.8.0'
    roomVersion = "1.1.1"
    Properties props = new Properties()
    def propFile = file("${rootProject.projectDir}/config/config.properties")

    if (propFile.canRead()){
        props.load(new FileInputStream(propFile))

        if (props.containsKey('TileServerUrl')) {
            tileServerUrl = props['TileServerUrl']
        }else{
            throw new Exception("You need to create config.properties file with proper API keys")
        }
    }else{
        throw new Exception("You need to create config.properties file with proper API keys")
    }
}
paulsUsername commented 5 years ago

Further information:

If I downgrade Gradle to 'com.android.tools.build:gradle:3.5.1' it resolves to issue. Any version past that and it won't work If I have crashlytics as part of the project. With Crashlytics removed from the project, I can sync perfectly with any gradle version.

paulsUsername commented 4 years ago

This is still causing major headaches here. We have to completely remove Crashlytics in order to run a test

samtstern commented 4 years ago

@paulsUsername sorry about my slow response here. So it looks like this is an incompatibility between two things:

I have to be honest that I am not familiar enough with the fabric plugin (or the AGP beta) to debug this myself but let me try to find someone on the Crashlytics team who can.

kevinkokomani commented 4 years ago

I tested creating a brand new Fabric project with 3.6.0-beta05 and was able to onboard a fresh Fabric app - does this resolve the issue for anyone else?

kevinkokomani commented 4 years ago

@paulsUsername We were able to get this working with 3.6.0-beta05 and 3.6.0-beta04. We found that integrating Firebase Crashlytics with a fresh app, and making sure to include the right google-services.json file as well as the google-services dependency in the build.gradle, resulted in no errors.

Are you doing anything custom with your setup in terms of how you add your google-services.json file?

paulsUsername commented 4 years ago

It seemed to resolve that initial error in regards to Crashlytics API key but I am get a provider error then.

“No value has been provided for this provider”

There is no clarity provided on which producer this refers to.

Nothing fancy with our google services json.

paulsUsername commented 4 years ago

I meant to follow on from the above. The issue wasn't actually resolved, we were using an earlier version of Gradle. Anything past 3.5.1 returns error:

“No value has been provided for this provider”

The only way to resolve the issue on 3.6.0-rc01 is to remove the line:

apply plugin: 'io.fabric'

kevinkokomani commented 4 years ago

Hey, sorry for the delay here. I was wondering if you'd be able to share the full stacktrace for the issue you're seeing here? Can you run

./gradlew clean assembleDebug --stacktrace

and attach the output? Thanks!

For visibility, we're still unable to reproduce this behavior, so we'd like a better idea of exactly what's going on so we can try to build a reproduction case.

samtstern commented 4 years ago

Since there has been no response in a while I assume this bug has been fixed. @paulsUsername if that is not the case I am happy to re-open it