问题描述
我正在尝试开发一个简单的 android 应用程序,在该应用程序中我尝试使用 sqlcipher,它使用 .所以图书馆内部.我已阅读有关如何在 android 应用程序中使用 sqlcipher 的文档.我已经按照步骤进行了编译,没有任何错误.但是,在运行时它会抛出 UnsatisfiedLinkError
.
I am trying my hands on developing a simple android application in which I am trying to use sqlcipher, which uses .so libraries internally. I have read the documentation on how to use sqlcipher with android app. I have followed the steps and it compiles without any error. But, at runtime it throws UnsatisfiedLinkError
.
谷歌搜索,我发现,gradle 不支持.so 库,但我发现了一个 hack here,我正在尝试使用它.但它在第 40 行的要点上抛出编译时错误,即
Googling around for it, I found that, gradle doesn't support .so libraries yet, but I found a hack here which I am trying to use. But it throws compile time error at line #40 on the gist which is,
tasks.withType(com.android.build.gradle.PackageApplicationTask) { pkgTask ->
pkgTask.jniDir new File(buildDir, 'native-libs')
}
说
在项目MyProject"上找不到属性com"
这里我发布了我的 build.gradle 文件中的代码.
Here I am posting code from my build.gradle file.
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/commons-codec.jar')
compile files('libs/guava-r09.jar')
compile files('libs/sqlcipher.jar')
}
targetCompatibility = 1.6
sourceCompatibility = 1.6
android {
target = 'android-14'
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 16
}
}
task copyNativeLibs(type: Copy) {
from(new File(project(':MyProject').buildDir, 'native-libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.PackageApplicationTask) { pkgTask ->
pkgTask.jniDir new File(buildDir, 'native-libs')
}
有人可以帮助我解决我做错了什么,或者我应该怎么做才能将这些 .so 库包含在我的 apk 中?
Can, anybody please help me on what I have done wrong or what should I do to include those .so libraries in my apk?
由于我是 android 开发和 gradle 的新手,如果我误解了什么,请向我道歉.
As I am new to android development and gradle, please apologize me if I have misunderstood something.
推荐答案
我遇到了同样的问题.查看 https://gist.github.com/khernyo/4226923#comment-812526 中的评论
I had the same problem. Check out the comment in https://gist.github.com/khernyo/4226923#comment-812526
它说:
对于 gradle android 插件 v0.3 使用com.android.build.gradle.tasks.PackageApplication"
那应该可以解决您的问题.
That should fix your problem.
这篇关于在 android studio 的 apk 中包含 .so 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!