【发布时间】:2020-09-17 03:33:31
【问题描述】:
将 Android Studio 更新到 4.0 后,项目构建完成并出现错误
找到多个文件,其独立于操作系统的路径为“lib/armeabi-v7a/libdlib.so”。如果您使用 jniLibs 和 CMake IMPORTED 目标,请参阅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})
【问题讨论】:
-
在这里打开了一个错误:issuetracker.google.com/issues/157901344
-
抱歉文档问题。出于某种原因,它已从 4.0 发行说明中删除。得到那个固定的atm。
-
在添加
packagingOptions块之前,我可以重现该问题。这使问题消失了。这是您为解决问题而添加的内容吗? -
不幸的是,谷歌缓存链接现在是 404。这个链接今天有效:developer.android.com/studio/releases/…
标签: android android-studio android-ndk android-studio-4.0