NDK:如何在AndroidStudio中包含*.so文件

gc9*_*986 2 android android-ndk android-studio

我有libs jar和*.so.我在教程中创建了Eclipse项目(对于这个库).我现在在Android Studio中做项目,但系统找不到*.so文件.我在这个 - 在android工作室的apk中包含.so库.我的应用程序在这样的库中找不到功能.怎么找到他们?日志:

10-16 12:16:55.965: W/dalvikvm(4386): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/atol/drivers/fptr/IFptrNative;
10-16 12:16:55.965: W/dalvikvm(4386): threadid=1: thread exiting with uncaught exception (group=0x41869438)
10-16 12:16:55.976: E/AndroidRuntime(4386): FATAL EXCEPTION: main
10-16 12:16:55.976: E/AndroidRuntime(4386): java.lang.ExceptionInInitializerError
Run Code Online (Sandbox Code Playgroud)

使用JAR库创建对象时发生错误.她反过来戳了*.so文件,但找到了她需要的东西.谁应该责备谁该做什么?

Viv*_*ara 7

目前的解决方案

\n\n

创建文件夹 project/app/src/main/jniLibs,然后将 *.so 文件放入该位置的 abi 文件夹中。例如,

\n\n
project/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80libs/\n|  \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 *.jar       <-- if your library has jar files, they go here\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80src/\n   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 main/\n       \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 AndroidManifest.xml\n       \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 java/\n       \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 jniLibs/ \n           \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 arm64-v8a/                       <-- ARM 64bit\n           \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 yourlib.so\n           \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 armeabi-v7a/                     <-- ARM 32bit\n           \xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 yourlib.so\n           \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 x86/                             <-- Intel 32bit\n               \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 yourlib.so\n
Run Code Online (Sandbox Code Playgroud)\n\n

已弃用的解决方案

\n\n

将两个代码片段添加到模块 gradle.build 文件中作为依赖项:

\n\n
compile fileTree(dir: "$buildDir/native-libs", include: \'native-libs.jar\')\nHow to create this custom jar:\n\ntask nativeLibsToJar(type: Jar, description: \'create a jar archive of the native libs\') {\n    destinationDir file("$buildDir/native-libs")\n    baseName \'native-libs\'\n    from fileTree(dir: \'libs\', include: \'**/*.so\')\n    into \'lib/\'\n}\n\ntasks.withType(JavaCompile) {\n    compileTask -> compileTask.dependsOn(nativeLibsToJar)\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n
\n


Asp*_*cas 6

三种选择:

将您的*.SO库复制到您的libs文件夹中并将其放在Build.gradle:

dependencies
        {
    compile fileTree(include: ['*.jar'], dir: 'libs')
}
Run Code Online (Sandbox Code Playgroud)

创建一个新文件夹src/main/jniLibs并将其写在您的Build.gradle:

android {
    //Another code 
    sourceSets {
        main {         
            jniLibs.srcDirs = ['src/main/jnilibs']          
        }
        //Another code 
    }//sourceSets tag close
}//Android tag close
Run Code Online (Sandbox Code Playgroud)

那里

创建一个新文件夹src/main/jniLibs并将其写在您的Build.gradle:

//Another code....

    dependencies
    {
          compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    }//end dependencies


    task nativeLibsToJar(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)
     }
Run Code Online (Sandbox Code Playgroud)