Object 应用程序启动时出现框错误 - 未找到 void io.objectbox.BoxStore.nativeDelete(长)的实现

Object Box error on app start - No implementation found for void io.objectbox.BoxStore.nativeDelete(long)

和标题差不多。

当我启动我的 Android 应用程序时,出现以下错误

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

我会稍微添加我的完整 build.gradle 和应用程序代码,因为我很着急,但我认为我应该 post,以防万一有一个已知且明显的解决方案.

我已经尝试了 1.1.0 和 1.2.0

更新:

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

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

更新 2:(堆栈跟踪)

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 的是 'core' 项目,而不是 Android 项目。此外,据我所知我的机器是 Linux 64 位 我决定注释掉所有检测内容和 windows 内容,只使用 linux extension/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')
    }
}

DB Class 使用 ObjectBox

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();
}

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

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

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

其他说明:

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