Search code examples
androidandroid-gradle-pluginbuild.gradlegradle-plugincrashlytics-android

Gardle fails to build on sync


I am trying below tutorial to make my api key secure

http://www.techjini.com/blog/securing-api-key-and-secret-key-in-android/

But when I click on "sync now", I get below error

Error:org.gradle.api.GradleException: Crashlytics Developer Tools error.
Error:com.crashlytics.tools.android.exception.PluginException: Crashlytics Developer Tools error.
Error:java.lang.IllegalArgumentException: Crashlytics found an invalid API key: "xxxxxMYFABRICKEYxxxxx".

gradle.properties

####################
#Fabric
FabricKey=my fabric key
####################

Gradle file

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
def FABRIC_KEY = '"' + FabricKey + '"' ?: '"Error occurs..."'
android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"

    defaultConfig {
        //... other info

        manifestPlaceholders = [
                FABRIC_KEY : FABRIC_KEY
        ]
    }
    }

AndroidManifest.xml

    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="${FABRIC_KEY}" />

Solution

  • Double quote was the culprit '""'

    Replaced

    def FABRIC_KEY = '"' + FabricKey + '"' ?: '"Error occurs..."'
    

    by

    def FABRIC_KEY = FabricKey ?: '"Error occurs..."'
    

    And Thanks to @Selvin for comment