在build.gradle文件android studio中指定.so文件 [英] specify .so files in build.gradle file android studio

查看:945
本文介绍了在build.gradle文件android studio中指定.so文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的目录结构

  src -main 

-java

-jniLibs

-armeabi

-lib1.so
-lib2.so

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

  java.lang.UnsatisfiedLinkError:nativeLibraryDirectories = [/ vendor / lib,/ system / lib]]]找不到 libFPEComponent.so 

跟随





这是我项目中的项目/库,这就是.so文件的加载/添加:





我这样编译项目:

  compile project(':videokit')


This is my Directory Structure

src -main

    -java

    -jniLibs

            -armeabi

                     -lib1.so
                     -lib2.so

Need to understand what piece of code should be written in build gradle file for these files to be included in the build. Right now, i am getting the error of not finding the .so file.

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

Following solution by H.Brooks

I have got to add here

My Git repository:

My bUild.gradle file

 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)
//        }

Here i have included source set block, i also had tested without that block. So still build isn't able to access .so files.

解决方案

If you want to use it you can call it in your class like this:

static {
    System.loadLibrary("libSONAME");
}

Add the following in your gradle:

jniLibs.srcDirs = ['libs']


Edit:

Adding .so Library in Android Studio

  1. Create Folder "jniLibs" inside "src/main/"
  2. Put all your .so libraries inside "src/main/jniLibs" folder
  3. Folder structure looks like,
    |--app:
    |--|--src:
    |--|--|--main
    |--|--|--|--jniLibs
    |--|--|--|--|--armeabi
    |--|--|--|--|--|--.so Files
    |--|--|--|--|--x86
    |--|--|--|--|--|--.so Files
  4. No extra code requires just sync your project and run your application.

Reference

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


Not sure what files you exactly have, if you only have .so?


Have a look at the image below:

This is a 'project/library' within my project and this is how the load the .so files get loaded/added:

I compile the project like this:

compile project(':videokit')

这篇关于在build.gradle文件android studio中指定.so文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆