![](/img/trans.png)
[英]Can Android NDK include a windows dll to a an Android shared library?
[英]can't include shared library in android studio
我很難在android studio中包含自己的sqlite庫(libsqliteX.so):
我跟着這個指南 ,並加載這個與最新的Android NDK(r10e)編譯它(我只是說“APP_ABI:= XXX”的Application.mk還建立它的x86和armeabi-V7A版本),並得到這個:控制台輸出:s3.postimg.org/v83e8bwsz/ndk_build.jpg(無法發布2個以上的鏈接:D)。
之后,我在android studio(v1.2.1.1)中創建了一個新應用,並創建了一個新的jnilibs-folder,在其中復制了我的.so文件:s17.postimg.org/7vvvsao67/jni_Libs.jpg
我沒有更改build.gradle(1.2.3版本的版本)或其他任何東西,只是編譯了我的應用程序,並且庫包含在apk中(打開了... / app / build / outputs / apk / apk-debug。帶有winzip的apk,還有一個帶有libsqliteX.so文件的lib文件夾)。
但是現在我不知道如何在我的項目中使用該庫。 我無法添加import org.sqlite.database...;
(無法解析符號“ 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'
如果我只是用System.loadLibrary("sqliteX");
加載庫System.loadLibrary("sqliteX");
我在運行時收到此錯誤:
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
(將dalvik換成藝術品會引發類似錯誤(無法找到該類))
我采用了不同的方法來使其工作(使緩存無效/重新啟動,從.so文件中創建一個.jar文件),但沒有幫助。 我做錯了什么?
編輯:
完整的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'
}
對我來說錯誤
java.lang.NoClassDefFoundError: org/sqlite/database/sqlite/SQLiteCustomFunction
似乎是Java層錯誤,而不是C級錯誤。 因為* .c文件沒有包/文件夾結構(例如“ org / sqlite / database ...”)。
因此,我最好的猜測是,某些.class文件不在您的apk中。 如果您是我,我將使用7zip / winrar解壓縮apk,並檢查org.sqlite.database.sqlite.SQLiteCustomFunction是否存在。
實際上,我相信.so已成功加載。
Added shared lib /data/app-lib/com.example.thele.geostuff-1/libsqliteX.so 0x416f6428
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.