NDK:如何在 AndroidStudio 中包含 *.so 文件 [英] NDK: how include *.so files in AndroidStudio
问题描述
我有 libs jar 和 *.so.我在教程中创建了 Eclipse 项目(对于这个库).我现在在 Android Studio 中做项目,但系统找不到 *.so 文件.我如何在这个 - 在 android studio 的 apk 中包含 .so 库 .我的应用程序在 so libs 中找不到函数.如何找到它们?日志:
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 in this - Include .so library in apk in android studio . My app does not find function in so libs. How to find them? Log:
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
使用 JAR 库创建对象时发生错误.她反过来戳 *.so 文件,但要找到她需要的东西.谁应该受到指责,该怎么做?
An error occurs when creating an object using a JAR library. She in turn poked *.so files, but to find what she needs. Who is to blame and what to do?
推荐答案
三个选项:
一个
将您的 *.SO 库复制到您的 libs
文件夹中并将其放在 Build.gradle
上:
Copy yours *.SO libraries on your libs
folder and put that on Build.gradle
:
dependencies
{
compile fileTree(include: ['*.jar'], dir: 'libs')
}
两个
在 src/main/jniLibs
上创建一个新文件夹并将其写入您的 Build.gradle
:
Make a new folder on src/main/jniLibs
and write that on your Build.gradle
:
android {
//Another code
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jnilibs']
}
//Another code
}//sourceSets tag close
}//Android tag close
那里
在 src/main/jniLibs
上创建一个新文件夹并将其写入您的 Build.gradle
:
Make a new folder on src/main/jniLibs
and write that on your 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)
}
这篇关于NDK:如何在 AndroidStudio 中包含 *.so 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!