react-native-ultimate-config
react-native-ultimate-config copied to clipboard
Product Flavors | Value null for applicationId in defaultConfig (works without flavors implementation)
Describe the bug
When using product flavors implementation, applicationId project.config.get("APP_ID")
in defaultConfig
is null
.
Steps to Reproduce
- Follow product flavors installation instructions
- configure
app/build.gradle
like this:
project.ext.flavorEnvMapping = [
dev: "../.env.staging.yaml",
...
]
...
defaultConfig {
...
applicationId project.config.get("APP_ID")
}
buildTypes {
...
debug { ... }
}
flavorDimensions "default"
productFlavors {
dev {
dimension "default"
...
}
}
- Run
react-native run-android --variant devDebug
(orcd android; ./gradlew assembleDevDebug
) to see build fail with
* What went wrong:
Execution failed for task ':app:processDevDebugGoogleServices'.
> No matching client found for package name <my_package_name> // because applicationId is 'null'
If I change to applicationId String.format("%s", project.config.get("APP_ID"))
then it trows an error about how applicationId is null
- If I remove
project.ext.flavorEnvMapping
, runyarn rnuc env.staging.yaml
, then runreact-native run-android --variant devDebug
(orcd android; ./gradlew assembleDevDebug
), everything works perfectly without any other changes.
Expected behavior
I expect product flavors to work just the same as using the yarn rnuc
cli
Integration option
- [ ] I am using
rnuc
CLI to inject environment (default integration option from quickstart guide) - [x] I am using scheme/flavor based integration (experimental integration option from cookbook: scheme, flavors)
- [ ] I am using
react-native-ultimate-config
within monorepo managed with Lerna or Yarn Workspaces Monorepo support
Env file
- [ ] I am using dotenv file as a source for variables
- [x] I am using YAML file as a source for variables
Example of env file that is causing problems
APP_ID: "com.my.application"
OS
- [ ] ios
- [x] android
Packages
- version of
react-native
: 0.64.2 - version of
react-native-ultimate-config
: 3.4.1
Run react-native info
and post below:
System:
OS: macOS 11.5.2
CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
Memory: 490.96 MB / 32.00 GB
Shell: 5.8 - /usr/local/bin/zsh
Binaries:
Node: 14.15.4 - ~/.nvm/versions/node/v14.15.4/bin/node
Yarn: 3.0.2 - ~/.nvm/versions/node/v14.15.4/bin/yarn
npm: 7.21.1 - ~/.nvm/versions/node/v14.15.4/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.2 - /Users/wkoutre/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
Build Tools: 19.1.0, 20.0.0, 21.1.2, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.0, 24.0.1, 24.0.2, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.2, 27.0.3, 28.0.0, 28.0.1, 28.0.2, 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3
System Images: android-23 | Google APIs Intel x86 Atom, android-24 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom_64, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-30 | Google APIs Intel x86 Atom_64, android-30 | Google Play Intel x86 Atom, android-30 | Google Play Intel x86 Atom_64
Android NDK: 22.1.7171670
IDEs:
Android Studio: 2020.3 AI-203.7717.56.2031.7678000
Xcode: 13.0/13A233 - /usr/bin/xcodebuild
Languages:
Java: 11.0.10 - /usr/bin/javac
npmPackages:
@react-native-community/cli: Not Found
react: 17.0.2 => 17.0.2
react-native: 0.64.2 => 0.64.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
@wkoutre any update?
@pcaro10 I haven't heard anything about this one, no, nor have I looked into it further.
In the production apps I manage, I've just been using the workaround I've mentioned above:
If I remove project.ext.flavorEnvMapping, run yarn rnuc env.staging.yaml, then run react-native run-android --variant devDebug (or cd android; ./gradlew assembleDevDebug), everything works perfectly without any other changes.
@wkoutre thanks! I will try
I am having the same problem and tried various steps with no avail. I had to run the yarn rnuc .env.staging.yaml
first.
I had a similar issue, but for me I needed to adjust the android versionCode
dynamically based on the flavor (dev / prod).
I have two yaml files, which are setup in the following way:
project.ext.flavorEnvMapping = [
prod: "../.env.prod.yaml",
staging: "../.env.staging.yaml",
]
and I attempted to do something like the following:
defaultConfig {
applicationId <MY_APP_ID>
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode project.config.get("APP_BUILD_NUMBER")
versionName project.config.get("APP_VERSION")
}
This however, failed when created an app bundle, with the error: "Version code not found in manifest".
Apparently, project.config.get
is null, and both APP_BUILD_NUMBER
and APP_VERSION
came back as null as well (Obviously).
I traced the code back to "../../node_modules/react-native-ultimate-config/android/rnuc.gradle"
.
There, you can see that at the end of the script, the following is being done: project.ext.set("config", rootConfig)
.
rootConfig
is a map containing all the flavors with all their keys.
I went on to print it, inside defaultConfig
like so:
defaultConfig {
println "MY CONFIG ${project.config}"
applicationId <MY_APP_ID>
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode project.config.get("APP_BUILD_NUMBER")
versionName project.config.get("APP_VERSION")
}
The result looked like so:
MY CONFIG [prod:[BASE_URL:<OMITTED>, IS_PROD:true, ENVIRONMENT:production, TARGET_NAME:<OMITTED>, APP_NAME:<OMITTED>, APP_BUILD_NUMBER:36, APP_VERSION:1.1.3], staging:[BASE_URL:<OMITTED> IS_PROD:false, ENVIRONMENT:staging, TARGET_NAME:<OMITTED>, APP_NAME:<OMITTED>, APP_BUILD_NUMBER:40, APP_VERSION:1.2.0]]
so the project.config
is just a dictionary containing the values per flavor.
My end working solution now looks like this:
productFlavors {
prod {
applicationId <PROD_BUNDLE_ID>
versionName project.config.prod.APP_VERION
versionCode project.config.prod.APP_BUILD_NUMBER
}
staging {
applicationId <STAGING_BUNDLE_ID>
versionName project.config.staging.APP_VERION
versionCode project.config.staging.APP_BUILD_NUMBER
}
}
Granted, this is not Ideal, but it works, and achieves the needed result.
I hope this helps someone.
Although it is kind of a bug to be honest, I would've expected the lib to deliver these values automatically
I had the same issue when trying to set applicationId
with flavors. This is what I ended up doing:
productFlavors {
dev {
}
production {
}
all { flavor ->
applicationId project.ext.config.get(flavor.name).get("APP_ID")
}
}