当前位置: 首页 > 工具软件 > One OS > 使用案例 >

Android Studio带C++项目提示More than one file was found with OS independent path

危飞文
2023-12-01

 

近日,在将一个旧Android Studio项目(带native c/c++)升级了新版本gradle 4.0.1后(Android Studio版本4.0.1),发现重新clean再构建时,提示:

More than one file was found with OS independent path ‘lib/armeabi-v7a/xxx.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

虽然一开始也是一脸茫然,但既然提示信息里都提供了连接了,那就看一下吧,顺带一提,给出的链接我写这篇博文的时候并不是最终信息位置,最终链接在这里:https://developer.android.com/studio/releases/gradle-plugin#cmake-imported-targets ,仔细阅读了一下,发现实际上是从gradle 4.0开始就对jni的预编译依赖引用方式做出了修改:

原来的直接放在“src/main/jniLibs”中的方法已经作废了:

With Android Gradle Plugin 4.0, the above configuration is no longer necessary and will result in a build failure:

1

2

3

4

* 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/libprebuilt.so'

External native build now automatically packages those libraries, so explicitly packaging the library with jniLibs results in a duplicate. To avoid the build error, move the prebuilt library to a location outside jniLibs or remove the jniLibs configuration from your build.gradle file.

所以,解决方法就是把jniLibs里的预编译库换个位置,比如把jniLibs改为nativeLibs,当然,CMakeLists.txt中的IMPORTED路径也要做出相应修改,完事再次build即可通过

如果不想改动任何代码,直接将gradle插件版本修改为3.6.4,gradle版本为5.6.4即可。

参考链接

 类似资料: