React-native-config: Could not get unknown property 'env' for project ':app' of type org.gradle.api.Project.

Created on 9 Jan 2019  路  3Comments  路  Source: luggit/react-native-config

.env file
LIB_KEY=xxx

build.gradle

android {
    defaultConfig {
        ...
        manifestPlaceholders = [LIB_KEY: project.env.get("LIB_KEY")]
    }
}

Running react-native run-android returns
Could not get unknown property 'env' for project ':app' of type org.gradle.api.Project.

Most helpful comment

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

All 3 comments

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

The problem for me was that the installation was off, there's PR with manual Android linking instructions, the last bit we had to add was this:

```
MainApplication.java

import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;

@Override
protected List getPackages() {
return Arrays.asList(
new MainReactPackage()
new ReactNativeConfigPackage()
);
}

Here's the PR for reference: https://github.com/luggit/react-native-config/pull/303/files

I am using the "autolinking" process (react-native 0.60+) so no code exists to "move around" when doing the gradlew assembleApp

Shouldn't it just work? What should we do when "autolinking" exists?

Thanks!

UPDATE:
I had to add this line in "build.gradle" and it worked (I thought this was only for the manual linking process):
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"

Was this page helpful?
0 / 5 - 0 ratings