What is the best way to hide Crashlytics key?

Viewed 1281

I put my crashlytics key in xml and I got this error:

Error:Execution failed for task ':app:fabricGenerateResourcesDebug'.

Crashlytics Developer Tools error.

The following is my intended code in AndroidManifest.xml.

<meta-data
    android:name="io.fabric.ApiKey"
    android:value="@string/crashlytics_key" />

What is the best way to hide it?

3 Answers

Well placing both keys to fabric.properties didn't work for me and fabric could not found api key there and wanted, me to put it in Manifest. Then I discovered this solution:

Place io.fabric.ApiKey=676897890789790... to your local.properties

To AndroidManifest add this:

<meta-data
            android:name="io.fabric.ApiKey"
            android:value="@string/fabric_api_key" />

Then in app module build.gradle

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def fabricApiKey = properties.getProperty('io.fabric.ApiKey')
if (fabricApiKey == null) fabricApiKey = "Place io.fabric.ApiKey to local.properties"

then in defaultConfig closure:

defaultConfig {
   .....
         resValue "string", "fabric_api_key", fabricApiKey
    }

This way you can hide also google maps key from source control for open source projects and still keep application buildable for continuous integration or people wanting to try it out...

Related