在build.gradle文件android studio中指定.so文件

时间:2017-07-05 14:47:51

标签: android android-studio java-native-interface build.gradle .so

这是我的目录结构

src -main

    -java

    -jniLibs

            -armeabi

                     -lib1.so
                     -lib2.so

需要了解应该在构建gradle文件中编写哪些代码,以便将这些文件包含在构建中。 现在,我收到了找不到.so文件的错误。

  java.lang.UnsatisfiedLinkError: nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libFPEComponent.so"

关注solution by H.Brooks

我必须在这里添加

enter image description here

My Git repository:

我的bUild.gradle文件

 apply plugin: 'com.android.application'

android {
    productFlavors {
        arm {
            ndk {
                abiFilters "armeabi-v7a", "armeabi"
            }
        }

    }

    sourceSets
            {
                main
                        {

                            jniLibs.srcDirs = ['src/main/jnilibs']

                        }

//Another code

            }

    compileSdkVersion 26
    buildToolsVersion '26.0.0'
    defaultConfig {
        applicationId "com.goambee.biometricziqitza"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

    }
    splits {

        // Configures multiple APKs based on ABI.
        abi {

            // Enables building multiple APKs per ABI.
            enable true

            // By default all ABIs are included, so use reset() and include to specify that we only
            // want APKs for x86, armeabi-v7a, and mips.

            // Resets the list of ABIs that Gradle should create APKs for to none.
            reset()

            // Specifies a list of ABIs that Gradle should create APKs for.
            include "armeabi-v7a"

            // Specifies that we do not want to also generate a universal APK that includes all ABIs.
            universalApk false
        }
    }
}

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')
//    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')


    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
}

//task native-libstiveLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
//    destinationDir file("$buildDir/native-libs")
//    baseName 'native-libs'
//    from fileTree(dir: 'src/main/jnilibs', include: '**/*.so')
//    into 'lib/'
//}
//
//tasks.withType(JavaCompile)
//        {
//            compileTask -> compileTask.dependsOn(nativeLibsToJar)
//        }

这里我已经包含了源集块,我也测试了没有该块。 所以仍然无法访问.so文件。

1 个答案:

答案 0 :(得分:0)

如果您想使用它,可以在课堂上调用它:

std::variant

static { System.loadLibrary("libSONAME"); } 中添加以下内容:

gradle

修改

在Android Studio中添加.so库

  1. 在“src / main /”
  2. 中创建文件夹“jniLibs”
  3. 将所有.so库放在“src / main / jniLibs”文件夹
  4. 文件夹结构如下,
    | --app:
    | - | --src:
    | - | - | - 主
    | - | - | - | --jniLibs
    | - | - | - | - | --armeabi
    | - | - | - | - | - | - 。so文件
    | - | - | - | - | --x86
    | - | - | - | - | - | - 。so Files
  5. 没有额外的代码只需同步您的项目并运行您的项目 应用
  6. <强>参考

    https://github.com/commonsguy/sqlcipher-gradle/tree/master/src/main

    如果你只有.so?

    ,不确定你确切拥有哪些文件

    请看下面的图片:

    structure

    这是我项目中的“项目/库”,这是加载/添加.so文件的加载方式:

    loading library

    我像这样编译项目:

    jniLibs.srcDirs = ['libs']