Is it possible to access my values in config file
--- .env.staging file ---
LIB_KEY=xxx
--- android/app/build.gradle ---
android {
defaultConfig {
applicationId "com.axinan.galadriel"
manifestPlaceHolder: [libKey: <config value here>]
}
}
So I can use the config value in my manifest file
--- Android.manifest ---
<application
<meta-data
android:name="com.lib.key"
android:value="@{libKey} />
/>
Is this possible or got another way?
You can use the value directly into the AndroidManifest without creating those manifestPlaceHolder value
Just put android:value="@string/LIB_KEY" like this
@raizal u mean defining libkey in strings.xml right?
But I want to get the value from config and not from strings.xml
@iadcg no, it's generated automatically
See this url
@raizal link is broken

@iadcg recheck the url
@raizal It doesnt work.
throws error:
AndroidManifest.xml:78:28-50: AAPT: No resource found that matches the given name (at 'value' with value '@string/LIB_KEY').
@iadcg it works fine on mine
Maybe you miss some step before it.
Are you sure your .env.stagging is loaded?
It seems its only works when you pass the config like
ENVFILE=.env.staging react-native run-android --variant devReleaseStaging
But not when you run in dev mode like
react-native run-android --variant devDebug
So I cannot use this cos some of team mates are working on dev mode in their local and they will get the compile error =/
@iadcg it will use .env default-ly if you didn't define which one you use.
You can define it on your app\build.gradle per-variant(see here. I use this one) or by what you just describe above.
@raizal Hi again. I managed to access the config values from the Manifest. But still cannot access it from app/build.gradle.
Sample usage from the doc is like this:
defaultConfig {
applicationId project.env.get("APP_ID")
}
But I get this error:
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'env' for project ':app' of type org.gradle.api.Project.
anyupdate on this?
@iadcg did u manage to fix it?
If anyone stumbled across this issue, for me it helped to move line
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
to the very top (right below import com.android.build.OutputFile) of android/app/build.gradle file
I tried to upgrade to v0.11.7 and it still doesn't work.
Thanks to @Asvarox and everyone else on this thread. It worked great on our app. Tested on Android and iOS.
.env
GOOGLE_CLOUD_API_KEY=some-string-here
build.gradle
apply plugin: "com.android.application"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
AndroidManifest.xml
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/GOOGLE_CLOUD_API_KEY"
/>
AppDelegate.m
NSString *gCloudApiKey = [ReactNativeConfig envFor:@"GOOGLE_CLOUD_API_KEY"];
[GMSServices provideAPIKey:gCloudApiKey];
@martinvol we use v0.11.7 as well
I had some issues getting this work with @string/key in Android manifest.
If anyone else has a similar problem, you can do a workaround
// in app/build.gradle
android {
// ...
defaultConfig {
//...
manifestPlaceholders = [
KEY: project.env.get("KEY")
]
}
}
// in AndroidManifest.xml
<meta-data
android:name="io.demo.ApiKey"
android:value="${KEY}" />
/>
It seems its only works when you pass the config like
ENVFILE=.env.staging react-native run-android --variant devReleaseStagingBut not when you run in dev mode like
react-native run-android --variant devDebugSo I cannot use this cos some of team mates are working on dev mode in their local and they will get the compile error =/
Hi, @iadcg. Did u manage to fix it?
I'm using v0.11.7. I also get trouble when using BUGSNAG_API_KEY in AndroidManifest.xml.
However, i've tested that the variable app_name defined in .env.prod file can be accessed correctly in AndroidManifest.xml. So I suspect the issue might from 3rd library (Bugsnag in my case).
In the end, I use the workaround provided by @youngern and it works.
// AndroidManifest.xml
<meta-data android:name="com.bugsnag.android.API_KEY" android:value="${BUGSNAG_API_KEY}" />
<activity android:name=".MainActivity" android:label="@string/app_name" ....
// .env.prod
BUGSNAG_API_KEY=xxxxxxx
app_name=AN_APP_NAME
// andoird/app/build.gradle
apply plugin: "com.android.application"
project.ext.envConfigFiles = [
debug: ".env",
release: ".env.prod",
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
Most helpful comment
Thanks to @Asvarox and everyone else on this thread. It worked great on our app. Tested on Android and iOS.
.env
build.gradle
AndroidManifest.xml
AppDelegate.m
@martinvol we use
v0.11.7as well