包括.so库中的APK Android中的工作室 [英] Include .so library in apk in android studio

查看:125
本文介绍了包括.so库中的APK Android中的工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个简单的Andr​​oid应用程序中,我试图使用 sqlcipher ,它使用.so库内部我的手。我已阅读文档的如何sqlcipher使用与Android应用。我遵循的步骤,它编译没有任何错误。但是,在运行时,它抛出的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.

谷歌搜索周围,我发现,摇篮不支持。所以图书馆尚未< /一>,但我发现一个黑客这里我想使用。但它抛出的是,

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

Could not find property 'com' on Project 'MyProject'

下面我张贴code从我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')
}

可以,有人请帮助我什么,我做错了,或我应该怎么做,包括图书馆。所以在我的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开发和摇篮,请原谅我,如果我有误解的东西。

As I am new to android development and gradle, please apologize me if I have misunderstood something.

推荐答案

我有同样的问题。看看在<一个评论href="https://gist.github.com/khernyo/4226923#comment-812526">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

它说:

有关摇篮Android插件V0.3使用com.android.build.gradle.tasks.PackageApplication

for gradle android plugin v0.3 use "com.android.build.gradle.tasks.PackageApplication"

这应该解决您的问题。

这篇关于包括.so库中的APK Android中的工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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