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

Gradle build failed for the Expo Android Fix Pre-release #546

Closed
4 tasks done
haibert opened this issue Oct 21, 2021 · 16 comments · Fixed by #694
Closed
4 tasks done

Gradle build failed for the Expo Android Fix Pre-release #546

haibert opened this issue Oct 21, 2021 · 16 comments · Fixed by #694
Labels
🐛 bug Something isn't working

Comments

@haibert
Copy link

haibert commented Oct 21, 2021

What were you trying to do?

Trying to install Vision Camera on android and do a successful expo build.

Reproduceable Code

No response

What happened instead?

FAILURE: Build failed with an exception.

Relevant log output

[stderr] FAILURE: Build failed with an exception. [stderr] * What went wrong: [stderr] Execution failed for task ':app:mergeDebugNativeLibs'. [stderr] > A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade [stderr] > More than one file was found with OS independent path 'lib/x86_64/libreactnativejni.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake [stderr] * Try: [stderr] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. [stderr] * Get more help at https://help.gradle.org [stderr] BUILD FAILED in 7m 29s🐛

Device

iPhone 12 iOS 14

VisionCamera Version

2.9.4@expo

Additional information

@haibert haibert added the 🐛 bug Something isn't working label Oct 21, 2021
@mrousavy
Copy link
Owner

Thanks for the bug report!
If you want to fix it, add libreactnativejni.so there:

packagingOptions {
excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so"]
}

@TooAngel
Copy link

I ran into the same issue (without expo), the solution works for me, thanks.

@haibert
Copy link
Author

haibert commented Oct 22, 2021

@mrousavy can we please get a update with the change you need mentioned since expo people can't touch the gradle❤️🙏🏻

@yoann84
Copy link

yoann84 commented Nov 19, 2021

@haibert Did you find a workaround for that ?

@haibert
Copy link
Author

haibert commented Nov 19, 2021

@yoann84 im pretty sure yesterday my build was successful while using the expo .11 version with no problems, are you on expo v43 ?

@yoann84
Copy link

yoann84 commented Nov 19, 2021

Sorry but what is expo 0.11 ? yes i'm on sdk43 and on android I have similar error. When I try to fix one I got another one and wtih expo as we can't modify gradle files and configuration even if I found a workaround it won't work in production

@haibert
Copy link
Author

haibert commented Nov 19, 2021

@yoann84 no worries, just run the following expo install react-native-vision-camera@expo

Heres the full discussion.
#545

@hirbod
Copy link
Contributor

hirbod commented Dec 20, 2021

I can't for my life build the android app on SDK 44 (custom dev client)
Works flawless on iOS but android keeps crashing. I've installed the expo tag, appield JHashMap patches and followed every thing I could find:

* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'lib/x86/libc++_shared.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake

@haibert
Copy link
Author

haibert commented Dec 21, 2021

@hirbod Marc is working on a fix he just doesn't have enough time to dedicate to backwards compatibility.(because I think vision camera works fine with RN .65 and above) He might work on the fix when he finds free time. Also soon expo will allow us to have more complex managed work flow which will make supporting complex modules like this easier. This is according to the man him self Evan Bacon. Hope this gives you some hope until a fix is provided either from Marc or from expo!

@hirbod
Copy link
Contributor

hirbod commented Dec 21, 2021

@haibert I just talked with Marc today via twitter. He tries to fix this in the holidays.

@sandlands
Copy link

Thanks for the bug report! If you want to fix it, add libreactnativejni.so there:

packagingOptions {
excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so"]
}

Thanks, @mrousavy. I stumbled upon similar error messages for other libraries. I ended up with:
excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so", "**/libreactnativejni.so", "**/libfolly_json.so", "**/libreanimated.so", "**/libjscexecutor.so"]

Finally, I managed to build for Android, using Expo's eas build in my case. This is what I did:

  • I'm using Expo SDK 44 and built a Development Client (using eas build).
  • I'm using [email protected] (and [email protected])
  • I installed patch-package in my project (see patch-package Setup section)
  • I patched node_modules/react-native-vision-camera (with the patch above and these JSI patches, setting VisionCamera_compileSdkVersion=30), which resulted in an added patches/react-native-vision-camera+2.9.4.patch to my app home directory (which will be used by eas build). Below you find the complete content of this patch.
  • Add these changes to the bottom of my-app/android/app/build.gradle.

I hope this helps anyone.

Kind regards,
Sander

my-app/patches/react-native-vision-camera+2.9.4.patch:

diff --git a/node_modules/react-native-vision-camera/android/CMakeLists.txt b/node_modules/react-native-vision-camera/android/CMakeLists.txt
index ab15dc3..844e768 100644
--- a/node_modules/react-native-vision-camera/android/CMakeLists.txt
+++ b/node_modules/react-native-vision-camera/android/CMakeLists.txt
@@ -22,6 +22,7 @@ add_library(
         src/main/cpp/java-bindings/JFrameProcessorPlugin.cpp
         src/main/cpp/java-bindings/JImageProxy.cpp
         src/main/cpp/java-bindings/JHashMap.cpp
+        ${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp
 )
 
 # includes
@@ -87,12 +88,6 @@ find_library(
         PATHS ${LIBRN_DIR}
         NO_CMAKE_FIND_ROOT_PATH
 )
-find_library(
-        JSI_LIB
-        jsi
-        PATHS ${LIBRN_DIR}
-        NO_CMAKE_FIND_ROOT_PATH
-)
 find_library(
         FOLLY_JSON_LIB
         folly_json
@@ -125,7 +120,6 @@ message(WARNING "VisionCamera linking: FOR_HERMES=${FOR_HERMES}")
 target_link_libraries(
         ${PACKAGE_NAME}
         ${LOG_LIB}
-        ${JSI_LIB}
         ${JS_ENGINE_LIB} # <-- Hermes or JSC
         ${REANIMATED_LIB}
         ${REACT_NATIVE_JNI_LIB}
diff --git a/node_modules/react-native-vision-camera/android/build.gradle b/node_modules/react-native-vision-camera/android/build.gradle
index f3ffea4..ed987e4 100644
--- a/node_modules/react-native-vision-camera/android/build.gradle
+++ b/node_modules/react-native-vision-camera/android/build.gradle
@@ -111,7 +111,7 @@ android {
   }
 
   packagingOptions {
-    excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so"]
+    excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so", "**/libreactnativejni.so", "**/libfolly_json.so", "**/libreanimated.so", "**/libjscexecutor.so"]
   }
 
   buildTypes {
@@ -466,7 +466,7 @@ extractJNIFiles.mustRunAfter extractAARHeaders
 // pre-native build pipeline
 
 tasks.whenTaskAdded { task ->
-  if (task.name == 'externalNativeBuildDebug' || task.name == 'externalNativeBuildRelease') {
+  if (task.name.contains('externalNative') || task.name.contains('CMake')) {
     task.dependsOn(extractAARHeaders)
     task.dependsOn(extractJNIFiles)
     task.dependsOn(prepareJSC)
diff --git a/node_modules/react-native-vision-camera/android/gradle.properties b/node_modules/react-native-vision-camera/android/gradle.properties
index d171611..b08ddc8 100644
--- a/node_modules/react-native-vision-camera/android/gradle.properties
+++ b/node_modules/react-native-vision-camera/android/gradle.properties
@@ -12,7 +12,7 @@
 # org.gradle.parallel=true
 #Fri Feb 19 20:46:14 CET 2021
 VisionCamera_buildToolsVersion=30.0.0
-VisionCamera_compileSdkVersion=31
+VisionCamera_compileSdkVersion=30
 VisionCamera_kotlinVersion=1.5.30
 VisionCamera_targetSdkVersion=31
 VisionCamera_ndkVersion=21.4.7075529

@haibert
Copy link
Author

haibert commented Dec 24, 2021

@sandlands I can confirm that this approach works! Thanks a lot Sander.
I did one thing differently, instead of modifying my apps build.gradle manually I used a config plug in to keep my work flow in the managed state. I also should mention this still fails if you have hermes enabled on android. I had to disable it to stop the builds from failing.

to do this you will need the following config plugin. Courtesy of @mercyaj

const { withProjectBuildGradle } = require('@expo/config-plugins')

const setCompileSdkVersion = (buildGradle, sdkVersion) => {
    const regexpCompileSdkVersion = /\bcompileSdkVersion\s*=\s*(\d+)/
    const match = buildGradle.match(regexpCompileSdkVersion)

    if (match) {
        const existingVersion = parseInt(match[1], 10)

        if (existingVersion < sdkVersion) {
            buildGradle = buildGradle.replace(
                /\bcompileSdkVersion\s*=\s*\d+/,
                `compileSdkVersion = ${sdkVersion}`
            )
        } else {
            throw new Error(`minSdkVersion is already >= ${sdkVersion}`)
        }
    }

    return buildGradle
}

module.exports = (config, sdkVersion) => {
    return withProjectBuildGradle(config, (config) => {
        if (config.modResults.language === 'groovy') {
            config.modResults.contents = setCompileSdkVersion(
                config.modResults.contents,
                sdkVersion
            )
        } else {
            throw new Error(
                "Can't set minSdkVersion in the project build.gradle, because it's not groovy"
            )
        }
        return config
    })
}

Then inside of app.json
//---------------IN APP.JSON-----------------

"plugins": [
            "react-native-vision-camera",
            ["./withCompileSdkVersion", 31]
        ]

//---------------IN APP.JSON-----------------

BTW you can use the most recent release with these diffs, you dont need to use 2.9.4.

@hirbod
Copy link
Contributor

hirbod commented Dec 24, 2021

That’s awesome news. I will try this later. Haven’t been able to build Android for days

@hirbod
Copy link
Contributor

hirbod commented Dec 24, 2021

@haibert did you still use the same patch file or did you edit it? I see the patchfile contains change to the minSdkVersion from 31 to 30 and you supplied a configPlugin to set 30 to 31 :D

@haibert
Copy link
Author

haibert commented Dec 25, 2021

@hirbod yea I made a mistake there lol but it still works. You can ignore that step if you use the plugin.. and I should also mention I had to turn off hermes engine on android or else the build was still failing.. make sure you dont have "jsEngine": "hermes" in your app.jsons android property.

@hirbod
Copy link
Contributor

hirbod commented Dec 25, 2021

Oh no. I won’t build my app without Hermes this time. Going to wait for a real fix by Marc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
6 participants