Closed aminy closed 6 years ago
I'm using react-native-config with code-push without any issue so far.
I guess you're missing buildTypes -> releaseStaging section in android/app/build.gradle
buildTypes {
debug {
applicationIdSuffix ".debug"
// Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key.
buildConfigField "String", "CODEPUSH_KEY", '""'
}
releaseStaging {
minifyEnabled enableProguardInReleaseBuilds
signingConfig signingConfigs.releaseStaging
buildConfigField "String", "CODEPUSH_KEY", '"staging_key_here"'
}
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
buildConfigField "String", "CODEPUSH_KEY", '"production_key_here"'
}
And following entry in defaultConfig section (replace com.yourapp.appId with applicationId):
defaultConfig {
...
// required by react-native-config
resValue "string", "build_config_package", "com.yourapp.appId"
...
}
I was running in to the same issue. I tried the above and it didn't work. What eventually worked for me was changing
project.ext.envConfigFiles = [
...
releaseStaging : ".env.staging",
...
]
To
project.ext.envConfigFiles = [
...
stagingrelease : ".env.staging",
...
]
Then adding stagingrelease under buildtypes and running react-native run-android --variant=stagingrelease. They put emphasis on making all custom builds all lowercase. Not sure why it matters but using stagingrelease vs releaseStaging fixed it for me (I also reversed the words to make sure there wasnt a naming conflict).
:+1:! @connercms solution above should work.
I think we compare variants in lowercase because depending on how you invoke Gradle the names could be mixed up. We can probably enhance how we extract the variant to avoid this issue in 1st place, but not too familiar with Gradle to know 😬
@pedro any best practice?
Yeah react source expects the release token in the built variant or hilarity ensues:
def devEnabled = !targetName.toLowerCase().contains("release")
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("cmd", "/c", *nodeExecutableAndArgs, "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, *extraPackagerArgs)
} else {
commandLine(*nodeExecutableAndArgs, "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, *extraPackagerArgs)
}
Make sure you have the "release" token at the end of each custom variant. This took a good 4 hours for me to uncover. Thanks to @chase-seibert at Dropbox on this one:
https://chase-seibert.github.io/blog/2016/12/09/react-native-android-staging-variant.html
Regarding @kodayashi comment, this is not entirely true anymore. React Native now has another option to toggle the release variant.
To use it, you must declare a project.ext.react
at the top of your android/app/build.gradle
file. An example usage looks like this:
project.ext.react = [
...
// Staging build example
devDisabledInStaging: true,
]
Notice the "Staging" suffix. It needs to match you build type.
project.ext.envConfigFiles = [
debug : ".env.debug",
release : ".env.release",
releasestaging : ".env.staging"
]
To
project.ext.envConfigFiles = [
debug : ".env.debug",
releasestaging : ".env.staging",
release : ".env.release"
]
just switch order of release
and releasestaging
(releasestaging
must be lowercase)
On android, I have a two 3 env files: .env -> for debug/local .env.staging -> for staging environment .env.production -> for production environment
The difference between the staging and production as basically the end points they use, but I can't get the react-native-config to read the staging file.
I also have 3 build type:
I'm using code push with different keys for release and releaseStaging variants.
Here is what I have in my build.gradle file for envConfigFiles:
When I build/run the app using variant releaseStaging
I expect to use
.env.staging
file but it's using.env.production
.I think the issue is in
dotenv.gradle
file were we are looking at the flavour of the build and matchingreleaseStaging
withrelease