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

近日,在将一个旧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:

* 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即可通过

博主友情提示:

如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。