应用程序启动时出现对象框错误 - 找不到void io.objectbox.BoxStore.nativeDelete(long)的实现

时间:2017-11-10 09:50:48

标签: android objectbox

就像标题所说的那样。

当我启动Android应用时,我收到以下错误

No implementation found for void io.objectbox.BoxStore.nativeDelete(long)

我会稍微添加我的完整build.gradle和app代码,因为我很匆忙,但我认为我应该发布,以防有​​一个已知且明显的解决方案。

我已经尝试了1.1.0和1.2.0

更新:

一些进一步的信息。我正试图在我的LibGDX项目中使用ObjectBox。 LibGDX是一个跨平台的游戏库,你用Java编写代码,它会吐出Android,iOS和桌面版本。

我决定尝试使用Java版本,而不是使用ObjectBox的Android实现,因此理论上它可以在所有三个平台上使用。我不确定,但也许这就是问题所在。在Android平台上使用Java版本。

更新2 :( Stacktrace)

11-10 09:48:05.159 16269-16278/com.myapp E/System: java.lang.UnsatisfiedLinkError: No implementation found for void io.objectbox.BoxStore.nativeDelete(long) (tried Java_io_objectbox_BoxStore_nativeDelete and Java_io_objectbox_BoxStore_nativeDelete__J)
                                                                              at io.objectbox.BoxStore.nativeDelete(Native Method)
                                                                              at io.objectbox.BoxStore.close(BoxStore.java:355)
                                                                              at io.objectbox.BoxStore.finalize(BoxStore.java:245)
                                                                              at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:222)
                                                                              at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:209)
                                                                              at java.lang.Thread.run(Thread.java:762)
11-10 09:48:05.261 16269-16269/com.myapp E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                  Process: com.myapp, PID: 16269
                                                                                  java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.myapp-1/lib/arm64, /data/app/com.myapp-1/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]] couldn't find "libobjectbox.so"
                                                                                      at java.lang.Runtime.loadLibrary0(Runtime.java:972)
                                                                                      at java.lang.System.loadLibrary(System.java:1567)
                                                                                      at io.objectbox.internal.NativeLibraryLoader.<clinit>(NativeLibraryLoader.java:44)
                                                                                      at io.objectbox.internal.NativeLibraryLoader.ensureLoaded(NativeLibraryLoader.java:82)
                                                                                      at io.objectbox.BoxStore.<init>(BoxStore.java:170)
                                                                                      at io.objectbox.BoxStoreBuilder.build(BoxStoreBuilder.java:243)
                                                                                      at com.myapp.db.DB.createMyObjectBox(DB.java:28)
                                                                                      at com.myapp.db.DB.updateAchievements(DB.java:35)
                                                                                      at com.myapp.screens.MainMenuScreen.achievementsFinishedLoading(MainMenuScreen.java:1241)
                                                                                      at com.myapp.android.AndroidPlayServices$GetAchievementsAsyncTask.onPostExecute(AndroidPlayServices.java:418)
                                                                                      at com.myapp.android.AndroidPlayServices$GetAchievementsAsyncTask.onPostExecute(AndroidPlayServices.java:364)
                                                                                      at android.os.AsyncTask.finish(AsyncTask.java:660)
                                                                                      at android.os.AsyncTask.-wrap1(AsyncTask.java)
                                                                                      at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:677)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:154)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
1

build.gradle(很多可能会被忽略,但它是我使用ObjectBox的'核心'项目,而不是Android。此外,据我所知我的机器是Linux 64bit我决定退出所有的检测内容和windows的东西,只需使用linux扩展/ lib)

buildscript {
    ext.objectboxVersion = '1.1.0'
//    ext {
//        osName = System.getProperty("os.name").toLowerCase()
//        isLinux = osName.contains("linux")
//        isWindows = osName.contains("windows")
//        is64 = System.getProperty("sun.arch.data.model") == "64"
//        isLinux64 = isLinux && is64
//        isWindows64 = isWindows && is64
//    }
    repositories {
        mavenCentral()
        jcenter()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://maven.java.net/content/groups/public/" }
        maven { url "http://objectbox.net/beta-repo/" }
        maven { url "https://plugins.gradle.org/m2/" }
        google()
    }
//        https://maven.fabric.io/public/io/fabric/tools/gradle/maven-metadata.xml look here for up to date fabric version

    dependencies {
        classpath 'com.github.triplet.gradle:play-publisher:1.1.5'
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'io.fabric.tools:gradle:1.24.4'
        classpath "io.objectbox:objectbox-gradle-plugin:$objectboxVersion"
        classpath "net.ltgt.gradle:gradle-apt-plugin:0.12"
    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "Masters Gallery by Reiner Knizia"
        gdxVersion = '1.9.6'
        roboVMVersion = '1.12.0'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.6.0'
        aiVersion = '1.6.0'
    }

    repositories {
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
        maven { url "http://objectbox.net/beta-repo/" }
        google()
    }
}

project(":desktop") {
    apply plugin: "java"

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
    }
}

project(":android") {
    apply plugin: "android"
    apply plugin: 'com.android.application'
    apply plugin: 'io.fabric'
    apply plugin: 'com.github.triplet.play'
//    apply plugin: 'io.objectbox' // after applying Android plugin

    repositories {
        jcenter()
//        maven { url 'https://maven.fabric.io/public' }
        flatDir { dirs 'libs' }
    }
    // .aar repositories
    repositories {
        flatDir { dirs 'libs' }
    }

    configurations { natives }

    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
        compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
            transitive = true
        }
        compile 'com.android.support:support-annotations:27.0.0'
        compile 'com.google.android.gms:play-services-auth:11.6.0'
        compile 'com.google.android.gms:play-services-games:11.6.0'
        compile 'com.android.support:multidex:1.0.2'
        compile 'com.sun.mail:android-mail:1.6.0'
        compile 'com.sun.mail:android-activation:1.6.0'
    }
}

project(":core") {
    apply plugin: "java"
    apply plugin: 'net.ltgt.apt-idea'
    apply plugin: 'io.objectbox'

    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "io.objectbox:objectbox-java:$objectboxVersion"

        // everything compiles without this, but it might still be needed
//        if (isLinux64) {
//            compile "io.objectbox:objectbox-linux:$objectboxVersion"
//        } else if (isWindows64) {
//            compile "io.objectbox:objectbox-windows:$objectboxVersion"
//        } else println("Native dependency could not be set up for unsupported OS: " + osName)

        compile fileTree(dir: 'libs', include: '*.jar')
        compile fileTree(dir: 'libs', include: '*.aar')
    }
}

使用ObjectBox的DB类

private void createMyObjectBox() throws IOException {
    File tempFile = File.createTempFile("objectstorefile", "");
    tempFile.delete();
    boxStoreDir = tempFile;
    Gdx.app.error("DB","tempfile="+tempFile);
    Gdx.app.error("DB","boxstoredir="+boxStoreDir);
    store = MyObjectBox.builder().directory(boxStoreDir).build();
}

1 个答案:

答案 0 :(得分:2)

如果我没弄错,你只能在Java项目中定义ObjectBox依赖项。似乎缺少的是Android特定工件:

compile "io.objectbox:objectbox-android:$objectboxVersion"

这包括共享库(本机.so文件)。

其他说明:

  • 确保您通过所有库获得一致的ABI支持。看起来你的LibGDX附带了armeabi,它非常陈旧,因此不包含在ObjectBox中。 ObjectBox Android附带armeabi-v7a,arm64-v8a和x86支持。我建议从LibGDX设置中删除所有其他设置。否则,应用程序可能会在某些设备上崩溃,因为它无法混合32位和64位库。
  • 您可以通过向Linux机器的桌面项目添加编译"io.objectbox:objectbox-linux:$objectboxVersion"来尝试为桌面设置ObjectBox
  • 您使用的ObjectBox版本已过时。请查看changelog以获取最新版本。