gpt4 book ai didi

android - 从 3.6 更新到 Android Studio 4.0 后构建具有 NDK 支持的项目时出错

转载 作者:行者123 更新时间:2023-12-03 13:25:14 27 4
gpt4 key购买 nike

将 Android Studio 更新到 4.0 后,项目构建完成并出现错误

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



该链接指向具有 Android Studio Preview 中的新功能的页面,即 4.1

编辑
实际上,您可以在 Google 缓存中找到链接的信息:
Automatic packaging of prebuilt dependencies used by CMake
那里说的是:

Prior versions of the Android Gradle Plugin required that you explicitly package any prebuilt libraries used by your CMake external native build by using jniLibs. With Android Gradle Plugin 4.0, the above configuration is no longer necessary and will result in a build failure:



但对我来说不是这样

这里是 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})

最佳答案

好的,所以我找到了解决方案,我已将其添加到带有 native 库的模块中:

 packagingOptions {
pickFirst "**/libdlib.so"
}
我不喜欢它,因为它解决了后果,而不是根本原因。
如果有人有更好的解决方案,请在此处发布。
另一种解决方案 @GavinAndre answer 中指出了有效的方法
要点是,如果您使用 Cmake,请不要存储您的 .sojniLibs文件夹。
将它们移动到另一个文件夹,例如 cmakeLibs .
例如:
set_target_properties( dlib
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/../cmakeLibs/${ANDROID_ABI}/libdlib.so )

关于android - 从 3.6 更新到 Android Studio 4.0 后构建具有 NDK 支持的项目时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62088079/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com