0

谁能帮我修复我的 Android 项目中的错误。我在我的项目中与 Dropbox 同步,但是当我尝试启动应用程序时出现错误:Caused by: java.lang.UnsatisfiedLinkError: Library DropboxSync not found

09-02 12:56:55.367    1313-1313/? E/AndroidRuntime: Uncaught handler: thread main exiting due to uncaught exception
09-02 12:56:55.377    1313-1313/? E/AndroidRuntime: java.lang.ExceptionInInitializerError
        at com.dropbox.sync.android.CoreAccountManager.initNativeLib(CoreAccountManager.java:111)
        at com.dropbox.sync.android.CoreAccountManager.<init>(CoreAccountManager.java:91)
        at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:132)
        at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:100)
        at com.shvedchenko.skleroshop.MainActivity.onCreate(MainActivity.java:44)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
        at android.app.ActivityThread.access$2200(ActivityThread.java:119)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4363)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: java.lang.ExceptionInInitializerError
        at com.dropbox.sync.android.NativeLib.<init>(NativeLib.java:33)
        at com.dropbox.sync.android.NativeLib.<clinit>(NativeLib.java:11)
        ... 18 more
        Caused by: java.lang.UnsatisfiedLinkError: Library DropboxSync not found
        at java.lang.Runtime.loadLibrary(Runtime.java:489)
        at java.lang.System.loadLibrary(System.java:557)
        at com.dropbox.sync.android.NativeHttp.<clinit>(NativeHttp.java:411)
        ... 20 more

第 44 行是 mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(), appKey, appSecret);

我不明白怎么了?

谢谢!

4

4 回答 4

1

这是我的解决方案:

dependencies {
    compile files('libs/dropbox-sync-sdk-android.jar')
}

android {
    tasks.withType(com.android.build.gradle.tasks.PackageApplication) {
        pkgTask -> pkgTask.jniFolders = new HashSet<File>();
            pkgTask.jniFolders.add(new File(projectDir, 'libs'));
    }
}

将 Dropbox sdk 中的“libs”文件夹与“build”和“src”文件夹放在同一级别。

于 2013-12-31T20:06:07.950 回答
0

看起来这是本机库和 gradle 的普遍问题。我发现这个答案很有帮助:Include .so library in apk in android studio

我的build.gradle文件的一部分现在看起来像这样,我的应用程序成功启动:

dependencies {
    compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
    compile fileTree(dir: 'libs', include: '*.jar')
}

task nativeLibsToJar(
        type: Zip,
        description: 'create a jar archive of the native libs') {
    destinationDir file("$buildDir/native-libs")
    baseName 'native-libs'
    extension 'jar'
    from fileTree(dir: 'libs', include: '**/*.so')
    into 'lib/'
}

tasks.withType(Compile) {
    compileTask -> compileTask.dependsOn(nativeLibsToJar)
}
于 2013-09-02T16:28:58.843 回答
0

您似乎错过了 Dropbox 的库(本机部分)

您可以在堆栈跟踪的底部看到它

    Caused by: java.lang.UnsatisfiedLinkError: Library DropboxSync not found
    at java.lang.Runtime.loadLibrary(Runtime.java:489)
    at java.lang.System.loadLibrary(System.java:557)
    at com.dropbox.sync.android.NativeHttp.<clinit>(NativeHttp.java:411)
    ... 20 more

检查库下载或文档在哪里获取丢失的库文件

[更新]:如何在 android studio 中使用本机库

将 *.so 文件放在libssrc 文件夹旁边的文件夹中

task copyNativeLibs(type: Copy) {
    from(new File('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.tasks.PackageApplication) { pkgTask ->
    pkgTask.jniDir new File(buildDir, 'native-libs')
}
于 2013-09-02T13:24:40.450 回答
0

无需复制数据的解决方案

可能我们大多数开发人员不喜欢将数据从一个位置复制到另一个位置......所以这里是解决方案,无需将 .so 文件复制到您的项目:

compile files('M:\\Dropbox\\SWDevelopment\\Libraries\\Android\\dropbox-android-sync-sdk-3.1.2\\libs\\dropbox-sync-sdk-android.jar')
compile fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
task nativeLibsToJar(type: Zip, description: 'create a jar archive of the native libs') {
    destinationDir file("$buildDir/native-libs")
    baseName 'native-libs'
    extension 'jar'
    from fileTree(dir: 'M:/Dropbox/SWDevelopment/Libraries/Android/dropbox-android-sync-sdk-3.1.2/libs', include: '**/*.so')
    into 'lib/'
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn(nativeLibsToJar)
}

只需将我的 Dropbox 同步 api 文件夹的 2 个出现调整为您自己的一个 ...

于 2015-02-08T14:27:02.800 回答