React-native-config: Not working on build.gradle when using applicationIdSuffix

Created on 7 Dec 2017  路  6Comments  路  Source: luggit/react-native-config

When I read from Config on my JS code, all the properties are undefined.

On my build.gradle I have (just copied the important stuff):

project.ext.envConfigFiles = [
        debug: ".env",
        release: ".env.prd"
]

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

buildTypes {
        debug {
            applicationIdSuffix ".dev"
            resValue "string", "app_name", "Arena.im.DEV"
        }
        release {
            resValue "string", "app_name", "Arena.im"
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }

When I run react-native run-android --variant=release it works fine. When I run react-native run-android , the problem occurs.

I put some println on dotenv.gradle and I see that the file and the key/values are being picked up correctly.. do you guys have any idea what I'm missing?

Most helpful comment

@rodrigoreis22 @danielbm You will need to add this to your app/build.gradle file in order to support different application IDs or suffixes:

defaultConfig {
    ...
    resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST.XML"
}

All 6 comments

I did some further testing and it looks like when I remove:
applicationIdSuffix ".dev"

It works fine.. so the problem is when I use applicationIdSuffix

I use this so I can have both versions installed on the device: the DEV app and the PRD app..

This is also happening to me.

@rodrigoreis22 , were you able to implement a workaround?

int resId = context.getResources().getIdentifier("build_config_package", "string", context.getPackageName());

Apparently this line gets the application ID from the package name. However, on our case, they are different. The application ID is com.something.dev and the package name is com.something.

@rodrigoreis22 @danielbm You will need to add this to your app/build.gradle file in order to support different application IDs or suffixes:

defaultConfig {
    ...
    resValue "string", "build_config_package", "YOUR_PACKAGE_NAME_IN_ANDROIDMANIFEST.XML"
}

@armanatz Thanks! It works now.

This does work, and since it's apparently already mentioned in the README, it seems like this issue could be closed. Right, @rodrigoreis22?

@armanatz @Rovack this works.. we can close this issue.

Was this page helpful?
0 / 5 - 0 ratings