.so文件中定义的文件不会成为最终APK的一部分

时间:2018-10-29 11:53:13

标签: android gradle android-gradle dependency-management

我已通过转到File->New->Import Module添加了库。模块提供了多个.so文件,并且它们不属于最终apk文件,并且应用程序崩溃并显示以下错误消息。

java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file
     

“ / data / app / com。== / base.apk”],nativeLibraryDirectories = [/ data / app / com。== / lib / arm,   /data/app/com.==/base.apk!/lib/armeabi-v7a、/system/lib,   / system / vendor / lib]]]找不到“ libAAA.so”

.so文件在库模块中的以下结构中定义。

src ->main ->jniLibs ->arm64-v8a/armeabi/x86/ -> libAA.so/libBB.so

库Build.gradle

dependencies {
    compile 'com.android.support:support-v4:27.1.1'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile fileTree(dir: "$buildDir/native", include: 'native.jar')
}

task nativeLibsToJar(type: Zip, description: 'create a jar archive of the native libs (*.so files)') {
    destinationDir file("$buildDir/native")
    baseName 'native'
    extension 'jar'
    from fileTree(dir: 'libs', include: '**/*.so')
    into 'lib/'
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn(nativeLibsToJar)
}

设置

include ':app', ':myLibrary'

应用程序级别:build.gradle

android {
    compileSdkVersion 27
    defaultConfig {

    ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86"
        }
    }

    productFlavors {
    }

    aaptOptions {
        cruncherEnabled = false
    }

  dexOptions {
        javaMaxHeapSize "4g" //specify the heap size for the dex process
        preDexLibraries false
    }

    lintOptions {
        abortOnError false
    }

}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':myLibrary')
}

repositories {

    flatDir {
        dirs 'libs'
    }
}

我还安装了Native Libs Monitor,它没有显示库模块内部定义的.so个文件。

1 个答案:

答案 0 :(得分:1)

这是文件夹结构:

src ->main ->jniLibs ->arm64-v8a/armeabi/x86/ -> libAA.so/libBB.so

这是NDK部分:

    ndk {
            abiFilters "armeabi", "armeabi-v7a", "x86"
        }

-v8a和-v7a不同。