Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make react-native-config work with white labels #941

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Sep 19, 2023

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

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

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
@Ldoppea Ldoppea merged commit 088f9af into master Sep 20, 2023
1 check passed
@Ldoppea Ldoppea deleted the fix/mabulle_config branch September 20, 2023 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants