简体   繁体   English

无法在android studio中包含共享库

[英]can't include shared library in android studio

I'm having a hard time with including my own sqlite library (libsqliteX.so) in android studio: 我很难在android studio中包含自己的sqlite库(libsqliteX.so):

I followed this guide and loaded this and compiled it with latest android NDK (r10e) (i just added "APP_ABI := xxx" to the Application.mk to build also x86 and armeabi-v7a versions of it) and got this: console output: s3.postimg.org/v83e8bwsz/ndk_build.jpg (cant post more than 2 links :D). 我跟着这个指南 ,并加载这个与最新的Android NDK(r10e)编译它(我只是说“APP_ABI:= XXX”的Application.mk还建立它的x86和armeabi-V7A版本),并得到这个:控制台输出:s3.postimg.org/v83e8bwsz/ndk_build.jpg(无法发布2个以上的链接:D)。

After that I have created a new app in android studio (v1.2.1.1) and create a new jnilibs-folder where I copied my .so files: s17.postimg.org/7vvvsao67/jni_Libs.jpg 之后,我在android studio(v1.2.1.1)中创建了一个新应用,并创建了一个新的jnilibs-folder,在其中复制了我的.so文件:s17.postimg.org/7vvvsao67/jni_Libs.jpg

I didn't change the build.gradle (gradle version 1.2.3) or anything, just compiled my app and the libraries are included in the apk (opened the .../app/build/outputs/apk/apk-debug.apk with winzip and there is a lib-folder with the libsqliteX.so files). 我没有更改build.gradle(1.2.3版本的版本)或其他任何东西,只是编译了我的应用程序,并且库包含在apk中(打开了... / app / build / outputs / apk / apk-debug。带有winzip的apk,还有一个带有libsqliteX.so文件的lib文件夹)。

But now I don't know how to use that library in my project. 但是现在我不知道如何在我的项目中使用该库。 I'm not able to add the line import org.sqlite.database...; 我无法添加import org.sqlite.database...; (cant resolve symbol 'sqlite'), I'm not able to add that libraries in Project Structure -> Dependencies (only the default depencies that are also in the build.gradle are there: (无法解析符号“ sqlite”),我无法在“项目结构”->“依赖关系”中添加该库(仅存在于build.gradle中的默认依赖关系:

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:support-v4:22.1.1'

and if I just load the library with System.loadLibrary("sqliteX"); 如果我只是用System.loadLibrary("sqliteX");加载库System.loadLibrary("sqliteX"); I got this error at runtime: 我在运行时收到此错误:

05-29 03:21:54.248    3450-3450/com.example.thele.geostuff D/dalvikvm﹕ Added shared lib /data/app-lib/com.example.thele.geostuff-1/libsqliteX.so 0x416f6428
05-29 03:21:54.288    3450-3450/com.example.thele.geostuff E/SQLiteConnection﹕ Unable to find class org/sqlite/database/sqlite/SQLiteCustomFunction
05-29 03:21:54.288    3450-3450/com.example.thele.geostuff W/dalvikvm﹕ JNI WARNING: JNI method called with exception pending
05-29 03:21:54.288    3450-3450/com.example.thele.geostuff W/dalvikvm﹕ in Ljava/lang/Runtime;.nativeLoad:(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/String; (GetFieldID)
05-29 03:21:54.288    3450-3450/com.example.thele.geostuff W/dalvikvm﹕ Pending exception is:
05-29 03:21:54.297    3450-3450/com.example.thele.geostuff I/dalvikvm﹕ java.lang.NoClassDefFoundError: org/sqlite/database/sqlite/SQLiteCustomFunction

(changing dalvik to art throws a similar error (cant find the class)) (将dalvik换成艺术品会引发类似错误(无法找到该类))

I applied different methods to make it work (invalidate caches/restart, created a .jar file out of the .so file) but it didn't help. 我采用了不同的方法来使其工作(使缓存无效/重新启动,从.so文件中创建一个.jar文件),但没有帮助。 What I'm doing wrong? 我做错了什么?


Edit: 编辑:

The complete build.gradle: 完整的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.thele.geostuff"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.android.support:support-v4:22.1.1'
}

To me the error 对我来说错误

java.lang.NoClassDefFoundError: org/sqlite/database/sqlite/SQLiteCustomFunction

Seems to be a Java layer error, not a C level error. 似乎是Java层错误,而不是C级错误。 Because the *.c files doesn't have package/folder structure (like "org/sqlite/database..."). 因为* .c文件没有包/文件夹结构(例如“ org / sqlite / database ...”)。

So my best guess is, some .class file are not in your apk. 因此,我最好的猜测是,某些.class文件不在您的apk中。 If I were you I'd use 7zip/winrar to unzip the apk and check if the org.sqlite.database.sqlite.SQLiteCustomFunction is there. 如果您是我,我将使用7zip / winrar解压缩apk,并检查org.sqlite.database.sqlite.SQLiteCustomFunction是否存在。

Actually, I believe the .so is successfully loaded. 实际上,我相信.so已成功加载。

Added shared lib /data/app-lib/com.example.thele.geostuff-1/libsqliteX.so 0x416f6428

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM