2 files found with path ‘lib/arm64-v8a/xxx.so‘ 问题

Android 开发 NDK 调用第三方so以及编译自己的so时,

报错:2 files found with path 'lib/arm64-v8a/libaesutil.so'. 几费周折解决了,记录下。

我的工程结构如图,在独立的module里写native层代码,依赖了一个外部的so , 并且通过cmake 编译自己的cpp文件和外部依赖的so.

cmake文件如下:

#构建库文件所需要CMake最小版本
cmake_minimum_required(VERSION 3.4.1)
# 设置生成的so动态库输出的路径
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/jniLibs/${ANDROID_ABI})
#添加自己的C/C++源文件
add_library( # Sets the name of the library.
        native_test
        # Sets the library as a shared library.
        SHARED
        # Provides a relative path to your source file(s).
        src/main/cpp/native_test.cpp)
#添加依赖的NDK 库
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 )

#添加外部依赖的so
add_library(
        aesutil
        SHARED
        IMPORTED)
set_target_properties(
        aesutil
        PROPERTIES IMPORTED_LOCATION
        ${PROJECT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libaesutil.so
)
include_directories(src/main/cpp/include)

#将目标库与NDK 中的库链接
target_link_libraries( # Specifies the target library.
        native_test
        # Links the target library to the log library
        # included in the NDK.
        aesutil
        ${log-lib} )

 自己的nativelib module的build.gradle:

android {
    compileSdkVersion 30

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"

        //cmake ndk
        externalNativeBuild {
            cmake {
                cppFlags ""
                arguments "-DANDROID_STL=c++_shared"
            }
        }
        //选择生成的CPU 架构,  android defaultConfig下定义
        ndk{
            abiFilters "armeabi-v7a", "arm64-v8a"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    //cmake ndk
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
  
}

 整个项目Android Gradle Plugin 是4.2.2版本。

网络上搜索了不少帖子,无效。

最后在自己的nativelib module的build.gradle 的android{}加上

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }

重新 make project 解决。

  • 16
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值