google-ar / arcore-android-sdk

ARCore SDK for Android Studio
https://developers.google.com/ar
Other
4.95k stars 1.21k forks source link

Cannot Load GLTF and GLB assets at runtime #726

Closed michaelglu closed 5 years ago

michaelglu commented 5 years ago

SPECIFIC ISSUE ENCOUNTERED

I am trying to load a GLTF file at runtime using this tutorial, but keep getting this error: Unable to load Renderable registryId='https://github.com/KhronosGroup/glTF-Sample-Models/raw/master/2.0/Duck/glTF/Duck.gltf' java.util.concurrent.CompletionException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/io/Files; at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:276) at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:282) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1627) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/io/Files; at com.google.ar.sceneform.assets.RenderableSource.call(SourceFile:15) at com.google.ar.sceneform.assets.RenderableSource.call(SourceFile:73) at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask.inputStreamToByteBuffer(LoadRenderableFromSfbTask.java:178) at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask.lambda$downloadAndProcessRenderable$0$LoadRenderableFromSfbTask(LoadRenderableFromSfbTask.java:113) at com.google.ar.sceneform.rendering.LoadRenderableFromSfbTask$$Lambda$0.get(Unknown Source:4) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1625) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  at java.lang.Thread.run(Thread.java:764)  02-27 22:16:30.840 5321-5498/com.example.michael.aronedge E/ModelRenderable: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.common.io.Files" on path: DexPathList[[zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/base.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_resources_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/lib/arm64, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/base.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_dependencies_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_resources_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_0_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_1_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_2_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_3_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_4_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_5_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_6_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_7_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_8_apk.apk!/lib/arm64-v8a, /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_slice_9_apk.apk!/lib/arm64-v8a, /system/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) ... 9 more Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.example.michael.aronedge--7qkAPu1nG3fckb2uy2sQg==/split_lib_resources_apk.apk at dalvik.system.DexFile.openDexFileNative(Native Method) at dalvik.system.DexFile.openDexFile(DexFile.java:354) at dalvik.system.DexFile.<init>(DexFile.java:101) at dalvik.system.DexFile.<init>(DexFile.java:75) at dalvik.system.DexPathList.loadDexFile(DexPathList.java:394) at dalvik.system.DexPathList.makeDexElements(DexPathList.java:354) at dalvik.system.DexPathList.<init>(DexPathList.java:164) at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:74) at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65) at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64) at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73) 02-27 22:16:30.843 5321-5498/com.example.michael.aronedge E/ModelRenderable: at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88) at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74) at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40) at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727) at android.app.LoadedApk.getClassLoader(LoadedApk.java:810) at android.app.LoadedApk.getResources(LoadedApk.java:1032) at android.app.ContextImpl.createAppContext(ContextImpl.java:2345) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5798) at android.app.ActivityThread.access$1100(ActivityThread.java:200) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6718) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

I ended up copying and pasting the tutorial code with the minor change, but the error is not going away. The method where I'm trying to download the file is:

 private void placeObject(ArFragment fragment, Anchor anchor, Uri model){
        ModelRenderable.builder()
                .setSource(this, RenderableSource.builder().setSource(
                        this,
                        Uri.parse(GLTF_ASSET),
                        RenderableSource.SourceType.GLTF2)
                        .setScale(0.5f)  // Scale the original model to 50%.
                        .setRecenterMode(RenderableSource.RecenterMode.ROOT)
                        .build())
                .setRegistryId(GLTF_ASSET)
                .build()
                .thenAccept(renderable -> addNodeToScene(fragment,anchor,renderable))
                .exceptionally(
                        throwable -> {
                            Toast toast =
                                    Toast.makeText(this, "Unable to load renderable " +
                                            GLTF_ASSET, Toast.LENGTH_LONG);
                            toast.setGravity(Gravity.CENTER, 0, 0);
                            toast.show();
                            return null;
                        });

My App Gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.michael.aronedge"
        minSdkVersion 27
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation "com.google.ar.sceneform:core:1.7.0"
    implementation "com.google.ar.sceneform.ux:sceneform-ux:1.7.0"
    implementation 'com.google.ar.sceneform:assets:1.7.0'
    implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.ar.sceneform.plugin'

My Project Gradle File:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.ar.sceneform:plugin:1.7.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My Manifest does have added.

I couldn't find anyone running into this issue, and I'm not sure what is causing it.

VERSIONS USED

michaelglu commented 5 years ago

Had to downgrade to 1.5 and the issue was resolved:

implementation "com.google.ar.sceneform:core:1.5.0"
    implementation "com.google.ar.sceneform.ux:sceneform-ux:1.5.0"
    implementation 'com.google.ar.sceneform:assets:1.5.0'

Please update the tutorial page to not require version 1.7, that doesn't work

fxsalazar commented 5 years ago

Did you try with 1.6?

michaelglu commented 5 years ago

1.6 works as well

BasilMVarghese commented 5 years ago

There is an issue with 1.9 as well. I had to use 1.8.

chnouman commented 4 years ago

I'm still getting this error even at 1.12.