0

那里。如何将.so格式的第三方文件复制到apk内的lib文件夹中?我有。有一个第三方库需要一个依赖 .so 文件,但是如何将它推入 lib 目录?我的 build.gradle

    defaultConfig {
        applicationId "com.test"
        minSdkVersion 22
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        externalNativeBuild {
            cmake {
                cppFlags "-std=c++17 -v -fPIC"
            }
        }
    }

    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ["src/main/buildLibs"]
            assets.srcDirs = ["src/main/assets"]
        }
    }


    flavorDimensions.add("abi")
    productFlavors {
        arm64_v8a {
            isDefault.set(true)
            buildConfigField "String", "CURRENT_ABI", '"arm64-v8a"'
            dimension "abi"
            ndk {
               abiFilters "arm64-v8a"
                ldLibs "log"
            }
        }
        armeabi_v7a {
            dimension "abi"
            ndk {
                abiFilters "armeabi-v7a"
                ldLibs "log"
            }
        }
    }

我的 .so 文件位于:src/main/cpp/test/arm_v8a, src/main/cpp/test/arm_v8a. 文件:test1.so, test2.so, test3.so, test4.so 在 cmakelists.txt 我指出文件:test1.sotest2.so

add_library(test1 SHARED IMPORTED)
set_target_properties(
    test1
    PROPERTIES IMPORTED_LOCATION
    ${CMAKE_SOURCE_DIR}/test/${ANDROID_ABI}/test1.so)

add_library(test2 SHARED IMPORTED)
set_target_properties(
        test2
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/test/${ANDROID_ABI}/test2.so)

target_link_libraries(test-jni PRIVATE test1)
target_link_libraries(test-jni PRIVATE test2)

但是test1.so并且test2.so依赖于我只看到的lib目录中的apktest3.so和内部,我该如何做到这一点,你也被击中了吗?谢谢test4.sotest1.sotest2.sotest3.sotest4.so

4

0 回答 0