Build failed with Nativescript Android 8.5: Execution failed for task ':app:mergeDebugNativeLibs'.
alexander-mai opened this issue · comments
Environment
Provide version numbers for the following components (information can be retrieved by running tns info
in your project folder or by inspecting the package.json
of the project):
- CLI: 8.5.3
- Nativescript Core: 8.5.3
- Nativescript Angulat 15.2.0
- Android Runtime: 8.5.0
- Plugin(s): ñativescript/pdf 1.0.1
Describe the bug
Build fails in Step Gradle Build when / after adding plugin dependencies
Building project...
Gradle build...
+ applying user-defined configuration from <PROJECT-PATH>/App_Resources/Android/before-plugins.gradle
+ applying user-defined configuration from <PROJECT-PATH>/App_Resources/Android/before-plugins.gradle
+ setting applicationId
+ applying user-defined configuration from <PROJECT-PATH>/App_Resources/Android/app.gradle
+ adding nativescript runtime package dependency: nativescript-optimized-with-inspector
+ adding aar plugin dependency: <PROJECT-PATH>/node_modules/@nativescript/core/platforms/android/core.aar
+ adding aar plugin dependency: <PROJECT-PATH>/node_modules/@nativescript/core/platforms/android/widgets-release.aar
Execution failed for task ':app:mergeDebugNativeLibs'.
2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs:
- <HOME-DIR>/.gradle/caches/transforms-3/cd760d28106a1b4d4e96396bcec235da/transformed/jetified-nativescript-optimized-with-inspector/jni/arm64-v8a/libc++_shared.so
- <HOME-DIR>/.gradle/caches/transforms-3/5f9aea1bacbd967e47cda037c65bd0e3/transformed/jetified-PdfiumAndroid-1.0.1/jni/arm64-v8a/libc++_shared.so
If you are using jniLibs and CMake IMPORTED targets, see
https://developer.android.com/r/tools/jniLibs-vs-imported-targets
Unable to apply changes on device: emulator-5554. Error is: Command ./gradlew failed with exit code 1.
Changing the devDependency @nativescript/android
to 8.4.0
is working well.
To Reproduce
Create an empty nativescript project and just add the plugin @nativescript/pdf
Expected behavior
The app schould build
package.json dependencies
{
"name": "example",
"main": "src/main.ts",
"version": "1.0.0",
"private": true,
"dependencies": {
"@angular/animations": "~15.2.0",
"@angular/common": "~15.2.0",
"@angular/compiler": "~15.2.0",
"@angular/core": "~15.2.0",
"@angular/forms": "~15.2.0",
"@angular/platform-browser": "~15.2.0",
"@angular/platform-browser-dynamic": "~15.2.0",
"@angular/router": "~15.2.0",
"@nativescript/angular": "^15.2.0",
"@nativescript/core": "~8.5.0",
"@nativescript/pdf": "~1.0.0",
"@nativescript/theme": "~3.0.0",
"rxjs": "~7.6.0",
"zone.js": "~0.13.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "~15.2.0",
"@angular/compiler-cli": "~15.2.0",
"@nativescript/android": "~8.5.0",
"@nativescript/types": "~8.5.0",
"@nativescript/webpack": "~5.0.14",
"@ngtools/webpack": "~15.2.0",
"typescript": "~4.9.0"
}
}
We're also receiving an error like this when building for Android in NativeScript 8.5
Execution failed for task ':app:mergeDebugNativeLibs'.
2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs:
- {home directory}/.gradle/caches/transforms-3/5f9aea1bacbd967e47cda037c65bd0e3/transformed/jetified-PdfiumAndroid-1.0.1/jni/arm64-v8a/libc++_shared.so
- {home directory}/.gradle/caches/transforms-3/cd760d28106a1b4d4e96396bcec235da/transformed/jetified-nativescript-optimized-with-inspector/jni/arm64-v8a/libc++_shared.so
If you are using jniLibs and CMake IMPORTED targets, see
https://developer.android.com/r/tools/jniLibs-vs-imported-targets
Command ./gradlew failed with exit code 1
There is a workaround: add this at the end of the android
block of your app.gradle file:
EDIT: Use the packagingOptions from the following post by @alexander-mai
This works, but it's only a workaround. This issue still needs to be addressed inside NativeScript.
EDIT: This appears to be caused by the @nativescript/pdf dependency.
Different versions of the libc++ library are used in @nativescript/android and the PDF library used in @nativescript/pdf. This leads to the mentioned conflict. The used library 'TalbotGooday:AndroidPdfViewer' would have to be updated so that the same libc++ is used. It was last updated 3 years ago, but there are updated forks.
My workaround is
packagingOptions {
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
}
@alexander-mai Thanks, I actually switched to doing that after posting the above. I should have gone back and updated my post.
If there are updated forks, then that's what @nativescript/pdf should use, right? I entered this same issue over there too. I'd rather not have to leave this in the app.gradle.
There is already a an open issue for @nativescript/pdf on plugin repository: NativeScript/plugins#503 facing this problem.