将Android Studio更新为4.0项目后,构建完成并出现错误
[与操作系统无关的路径'lib / armeabi-v7a / libdlib.so'找到了多个文件。如果您正在使用jniLib和CMake导入目标,请参见https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake
该链接指向具有Android Studio Preview中的新功能为4.1]的页面>
编辑
实际上,您可以找到Google缓存中链接的信息:Automatic packaging of prebuilt dependencies used by CMake这里所说的是:Android Gradle插件的早期版本要求您使用jniLibs显式打包CMake外部本机版本使用的所有预编译库。使用Android Gradle Plugin 4.0时,不再需要上述配置,并且会导致构建失败:
但对我而言并非如此
这里是build.gradle
apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { compileSdkVersion 29 buildToolsVersion "29.0.2" defaultConfig { minSdkVersion 21 targetSdkVersion 29 versionCode 1 versionName "1.0" externalNativeBuild { cmake { cFlags "-O3" cppFlags "-std=c++11 -frtti -fexceptions -mfpu=neon" arguments "-DANDROID_PLATFORM=android-16", "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_CPP_FEATURES=rtti exceptions" } } } buildTypes { debug {} stage { debuggable true minifyEnabled false } release { minifyEnabled false } } kotlinOptions { jvmTarget = "1.8" } externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" version "3.10.2" } } packagingOptions { pickFirst "**/libc++_shared.so" pickFirst "**/libdlib.so" } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.annotation:annotation:1.1.0' implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }
和
CMakeLists.txt
set(LIB_DIR ${CMAKE_SOURCE_DIR}/src/main/jniLibs)
#
cmake_minimum_required(VERSION 3.4.1)
add_library(dlib SHARED IMPORTED)
# sets the location of the prebuilt dlib .so
set_target_properties( dlib
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libdlib.so )
# ------------------------------------------------------------------
add_library( # Sets the name of the library.
face-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
face-lib.cpp)
target_include_directories(
face-lib PRIVATE
${CMAKE_SOURCE_DIR}/include
)
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log)
target_link_libraries( # Specifies the target library.
face-lib
dlib
# Links the target library to the log library
# included in the NDK.
${log-lib})
将Android Studio更新为4.0后,项目构建完成并出现错误,并发现多个文件与OS无关,路径为'lib / armeabi-v7a / libdlib.so'。如果您正在使用jniLibs和CMake ...
好,所以我找到了解决方案,已将其与本机库一起添加到模块中: