Skip to content

Commit

Permalink
feat: Make react-native-config work with white labels
Browse files Browse the repository at this point in the history
During build phase, `react-native-config` generates a `.BuildConfig`
class from the project `.env` file

Then on runtime, it will try to reconstruct this classe name by
querying its package name from app's resources using the following code
```java
int resId = context.getResources().getIdentifier("build_config_package", "string", context.getPackageName());
className = context.getString(resId);
```

This would work only if the app's `packageId` and `namespace` are the
same

But since we implemented the new white label mechanism, those values
can now be different. This is the case for the MaBulle version that
has `io.cozy.flagship.mobile.mabulle` as package name but
`io.cozy.flagship.mobile` as namespace

In the previous code, the resource would be searched in
`getPackageName()` which would return the `packageId` but the resource
would be stored in the `namespace`, so `build_config_package` would not
be found

The result is that the app won't find any config value (i.e. Safetynet
API key and Sentry auth token)

To fix that we add a new instruction in the `build.gradle` file to set
`build_config_package` in the `packageId` too

As our white label mechanism always set `io.cozy.flagship.mobile` as
`namespace`, so we use this value for `build_config_package`

Related commit: d08fd4b
  • Loading branch information
Ldoppea committed Sep 19, 2023
1 parent 5bbaeb7 commit 969d966
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ android {
versionCode 101134
versionName "1.1.13"
multiDexEnabled true
resValue "string", "build_config_package", "io.cozy.flagship.mobile"
}
splits {
abi {
Expand Down

0 comments on commit 969d966

Please sign in to comment.