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

Fix Android behaviour with Android Gradle Plugin >=4.2.0 #609

Merged
merged 1 commit into from
Aug 26, 2021

Conversation

bwindsor
Copy link
Contributor

React Native 0.65 upgraded the Android Gradle Plugin to 4.2.1, which causes anything using react-native-config to fail with the following error:

The value for property 'buildConfigFields' is final and cannot be changed any further.

Gradle has multiple phases: https://docs.gradle.org/current/userguide/build_lifecycle.html. The reason for this error is that Gradle executes the contents of task.doFirst during the execution phase. However, during execution then buildConfigFields is final so cannot be modified. It can only be modified during the configure phase.

This PR removes the task.doFirst callback, and simply executes the code inside the callback immediately during the configure phase. This has been tested by myself and some other users (see #567) and still works with multiple build types and multiple flavors, both with gradle plugin 4.1.x and 4.2.x.

My assumption as to why this upgrade broke react-native-config is that Gradle decided to strictly enforce that buildConfigFields is final during the execution phase, whereas in previous versions it probably wasn't enforced but should have been. Google are aware of this change in behaviour (https://issuetracker.google.com/issues/172657565) and closed the issue with a Won't fix (intended behaviour) response. So it's up to react-native-config to change to be compatible with this new behaviour.

Fixes #567
Fixes #578
Fixes #608

@octsiri
Copy link

octsiri commented Aug 23, 2021

May I know which version of gradle plugin you use for this fixing? For RN-0.65.1 they used 4.2.1. I try to implement but still got some errors, Need help, thanks

@mlazari
Copy link

mlazari commented Aug 23, 2021

May I know which version of gradle plugin you use for this fixing? For RN-0.65.1 they used 4.2.1. I try to implement but still got some errors, Need help, thanks

I've verified this with classpath 'com.android.tools.build:gradle:4.2.1', distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip and worked fine for me.

@bwindsor
Copy link
Contributor Author

@octsiri I'm using the same as @mlazari is using. It's the same versions as RN-0.65.1 uses. You also get errors when updating to 4.2.x if you're using an old version of Android Studio, make sure you're on the latest. I expect your errors are likely due to something different. If you're using the "quick fix" way of editing a file in node_modules to implement this PR just to see if it works, make sure you clean your build to ensure the changes are definitely picked up as well.

@bwindsor
Copy link
Contributor Author

@sanduluca Thanks for approving - what needs to be done to merge this?

@luancurti
Copy link
Collaborator

Thank you @bwindsor

@luancurti luancurti merged commit e70d68b into lugg:master Aug 26, 2021
@virajverlekar-tm
Copy link

When will this change be added to a release tag?

@luancurti
Copy link
Collaborator

Published 🚀

sumi-svmx added a commit to sumi-svmx/react-native-config that referenced this pull request Jan 13, 2023
Cherry pick commit from lugg#609
saravanaraj-svmx pushed a commit to ServiceMax-Engineering/react-native-config that referenced this pull request Jan 13, 2023
Cherry pick commit from lugg#609
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants