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/’. If you are using jniLibs and CMake IMPORTED targets, see

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


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$ActionFacade
   > More than one file was found with OS independent path 'lib/x86/'

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.