NDK: how include *.so files in AndroidStudio

前端 未结 4 603
耶瑟儿~
耶瑟儿~ 2020-11-29 10:50

I have libs jar and *.so. I created Eclipse project as in tutorial (for this libs). I am now doing project in Android Studio, but system can\'t find *.so files. I make how i

4条回答
  •  爱一瞬间的悲伤
    2020-11-29 11:22

    Current Solution

    Create the folder project/app/src/main/jniLibs, and then put your *.so files within their abi folders in that location. E.g.,

    project/
    ├──libs/
    |  └── *.jar       <-- if your library has jar files, they go here
    ├──src/
       └── main/
           ├── AndroidManifest.xml
           ├── java/
           └── jniLibs/ 
               ├── arm64-v8a/                       <-- ARM 64bit
               │   └── yourlib.so
               ├── armeabi-v7a/                     <-- ARM 32bit
               │   └── yourlib.so
               └── x86/                             <-- Intel 32bit
                   └── yourlib.so
    

    Deprecated solution

    Add both code snippets in your module gradle.build file as a dependency:

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


提交回复
热议问题