Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fabric not accepting @string/... reference for its API key in manifest.xml

I'm trying to hide my fabric API key from source control by putting the key in an un-tracked string resource XML file. But for some reason, fabric is not accepting the key vie @string/FABRIC_API_KEY reference in the manifest.

The XML file is as follows -

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="NASA_API_KEY">abcd</string>
    <string name="FABRIC_API_KEY">xyz</string>
</resources>

The reference in the manifest -

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

And, here is the error I get on an attempt to build -

Error:Execution failed for task ':app:fabricGenerateResourcesDebug'. Crashlytics Developer Tools error.

I have tried accessing the API key via BuildConfig and it still does not work.

like image 510
krtkush Avatar asked Mar 09 '23 20:03

krtkush


2 Answers

According to Fabric,

You should stop adding this key field in AndroidManifest.xml. Instead you should add it in fabric.properties.

Basically fabric library will automatically merge this key later in your merged AndroidManifest.xml.

REF : https://docs.fabric.io/android/fabric/settings/working-in-teams.html#android-projects

Hope this helps.

like image 156
albeee Avatar answered Apr 25 '23 12:04

albeee


In build.gradle add manifestPlaceholders:

defaultConfig {
    manifestPlaceholders = [
        FABRIC_API_KEY:"Your Key"
    ]
}

Use it in AndroidManifest.xml like

<meta-data
    android:name="io.fabric.ApiKey"
    android:value="${FABRIC_API_KEY}"
/>
like image 26
Prateek Kumar Singh Avatar answered Apr 25 '23 11:04

Prateek Kumar Singh