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

Android build error, trying to read hermesEnabled property added in gradle.properties from react-native 0.71.0 #112

Open
eisodev opened this issue Sep 5, 2023 · 2 comments

Comments

@eisodev
Copy link

eisodev commented Sep 5, 2023

Error:

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/eisodev/rubic/rubic-connect/node_modules/react-native-worklets-core/android/build.gradle' line: 38

* What went wrong:
A problem occurred evaluating project ':react-native-worklets-core'.
> Could not get unknown property 'hermesEnabled' for project ':app' of type org.gradle.api.Project.

Cause:
The hermesEnabled property was only added from react-native version 0.71.0 in gradle.properties (https://react-native-community.github.io/upgrade-helper/?from=0.68.7&to=0.71.0), which you can see toggling the upgrade helper to lower versions than 0.71.0.

Fix for the user:
Add the property to gradle.properties like in the upgrade helper.

Potential fix for the package owner:
Set min version on react-native in peerDependencies, or if you intend to support any version like now (*), make sure you read this prop using the old way too. It's declared (from older upgrade guides) like this:

app/build.gradle

....
project.ext.react = [
    entryFile: "index.js",
    enableHermes: true,  // clean and rebuild if changing
    devDisabledInStaging: true,
]
...
/**
 * Whether to enable the Hermes VM.
 *
 * This should be set on project.ext.react and that value will be read here. If it is not set
 * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
 * and the benefits of using Hermes will therefore be sharply reduced.
 */
def enableHermes = project.ext.react.get("enableHermes", true);

If going by ChatGPT4 (which helped me find the root of this problem). PS! This following code is not vetted nor tested by me!

Instead of directly accessing hermesEnabled, 
the proper way to check if Hermes is enabled in
modern React Native versions is via enableHermes. 
You can update the worklets package's check to:

if (appProject?.ext?.get("react")?.get("enableHermes")) {
    return "hermes"
}
@eisodev
Copy link
Author

eisodev commented Sep 6, 2023

It will also not build to Android device (Android 11)/emulator (Android 13) but iOS works on React Native 0.69.12:

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not find com.facebook.react:hermes-android:.
     Required by:
         project :app

This is probably because of the change made in 0.71.0 related to:

if (enableHermes) {
    // These lines instruct Gradle to consume the bundled version of Hermes.
    // For further information on Bundled Hermes and how this mechanism works,
    // look here: https://reactnative.dev/architecture/bundled-hermes
    // noinspection GradleDynamicVersion
    implementation("com.facebook.react:hermes-engine:+") { // From node_modules
        exclude group:'com.facebook.fbjni'
    }
} else {
    implementation jscFlavor
}

replaced by

if (hermesEnabled.toBoolean()) {
    implementation("com.facebook.react:hermes-android")
} else {
    implementation jscFlavor
}

This change can be seen in upgrade helper here:
https://react-native-community.github.io/upgrade-helper/?from=0.69.12&to=0.71.0

@cfbadr
Copy link

cfbadr commented Nov 30, 2023

I have this error too.

Does anyone find something, because it's quite a big one.

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

No branches or pull requests

2 participants