React-native-config: Env Variables in AndroidManifest.xml not accessible

Created on 7 Jul 2016  路  9Comments  路  Source: luggit/react-native-config

Hi there,
First of all thanks for this great library, I have been searching for something like this for quite a while.

My problem is I have an env like this:

ANDROID_FABRIC_KEY=xxxxxxxxx
ANDROID_MAPS_KEY=xxxxxxxxxx

and I would like to use the key in my AndroidManifest.xml, which I currently do like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wu.xxx">
    ...
    <application ...>
      <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/ANDROID_MAPS_KEY" />
      <meta-data android:name="io.fabric.ApiKey" android:value="@string/ANDROID_FABRIC_KEY" />
      .....
    </application>
</manifest>

When I build it I get an error like this:

ERROR - Crashlytics Developer Tools error.
java.lang.IllegalArgumentException: Crashlytics found an invalid API key: @string/ANDROID_FABRIC_KEY.

I am currently using

  • react-native-config: v0.0.7
  • react-native: v0.21 ( I know, it is outdated, but shouldn't be the problem here)

Thanks for your time!

Most helpful comment

I fixed it like this

In .env file
FABRIC_API_KEY=<YOUR_API_KEY>

In build.gradle file add manifestPlaceholder
defaultConfig { manifestPlaceholders = [ FABRIC_API_KEY:project.env.get("FABRIC_API_KEY") ] }

In AndroidManifest.xml
<meta-data android:name="io.fabric.ApiKey" android:value="${FABRIC_API_KEY}" />

All 9 comments

Hey Daniel!

Odd, did you apply this plugin in your Gradle config? In android/app/build.gradle:

apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

I guess I forgot to do so, it seems to work now. Thanks for your help!

I face exactly the same problem?
I already applied the plugin in the Gradle config.

I'm also experiencing this issue, even though I too have applied the plugin in the gradle config. Using react-native-config: 0.2.1.

Thanks for the very helpful library otherwise!

I fixed it like this

In .env file
FABRIC_API_KEY=<YOUR_API_KEY>

In build.gradle file add manifestPlaceholder
defaultConfig { manifestPlaceholders = [ FABRIC_API_KEY:project.env.get("FABRIC_API_KEY") ] }

In AndroidManifest.xml
<meta-data android:name="io.fabric.ApiKey" android:value="${FABRIC_API_KEY}" />

Not working for me too.
@prtkkmrsngh it's only workaround, but it should be fixed in react-native-config library.

Same problem for me. I have apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle" set in my android/app/build.gradle file.

But I still get invalid API key: @string/FABRIC_KEY unless I added to the manifestPlaceholders manually as per the solution from @prtkkmrsngh

However this might be a problem with Fabric as <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/GOOGLE_MAPS_KEY" /> works in the same file...

@prtkkmrsngh's solution worked for me. Thanks

We are getting the same issue. For us it is working with the manifest placeholder, so we assume react-native-config is properly integrated and it is some issue with the library.

Was this page helpful?
0 / 5 - 0 ratings