googlecodelabs / sceneform-intro

Other
25 stars 18 forks source link

Cannot get the sample running with 1.17 Sceneform #24

Open MrCsabaToth opened 4 years ago

MrCsabaToth commented 4 years ago

I experimented with this example back in the days of 1.12 Sceneform. I wanted to take it for a spin for some new projects and it miserably fails to run. I'm at 1.17 Sceneform version and 4.0 Gradle (everything is updated to latest), 4.0 Android Studio, 1.17 Sceneform plugin. I tried both with target SDK 28 and 29.

The Animation part doesn't even complie, but that was easy to comment out and I didn't need it. After that however I get:

E/Perf: Fail to get file list com.example.sceneform
E/Perf: getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
W/ample.scenefor: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/ample.scenefor: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.sceneform, PID: 30804
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sceneform/com.example.sceneform.MainActivity}: android.view.InflateException: Binary XML file line #23 in com.example.sceneform:layout/activity_main: Binary XML file line #22 in com.example.sceneform:layout/sceneform_ux_fragment_layout: Binary XML file line #22 in com.example.sceneform:layout/sceneform_ux_fragment_layout: Error inflating class com.google.ar.sceneform.ArSceneView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3374)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3513)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2109)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: android.view.InflateException: Binary XML file line #23 in com.example.sceneform:layout/activity_main: Binary XML file line #22 in com.example.sceneform:layout/sceneform_ux_fragment_layout: Binary XML file line #22 in com.example.sceneform:layout/sceneform_ux_fragment_layout: Error inflating class com.google.ar.sceneform.ArSceneView
     Caused by: android.view.InflateException: Binary XML file line #22 in com.example.sceneform:layout/sceneform_ux_fragment_layout: Binary XML file line #22 in com.example.sceneform:layout/sceneform_ux_fragment_layout: Error inflating class com.google.ar.sceneform.ArSceneView
     Caused by: android.view.InflateException: Binary XML file line #22 in com.example.sceneform:layout/sceneform_ux_fragment_layout: Error inflating class com.google.ar.sceneform.ArSceneView
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:854)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1006)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at com.google.ar.sceneform.ux.BaseArFragment.onCreateView(BaseArFragment.java:162)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
        at androidx.fragment.app.FragmentManagerImpl.ensureInflatedFragmentView(FragmentManagerImpl.java:1138)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:851)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1133)
        at androidx.fragment.app.FragmentManagerImpl.addFragment(FragmentManagerImpl.java:1393)
        at androidx.fragment.app.FragmentManagerImpl.onCreateView(FragmentManagerImpl.java:3205)
        at androidx.fragment.app.FragmentController.onCreateView(FragmentController.java:134)
        at androidx.fragment.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
        at androidx.fragment.app.FragmentActivity.onCreateView(FragmentActivity.java:336)
        at android.view.LayoutInflater.tryCreateView(LayoutInflater.java:1069)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:997)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:961)
E/AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:1123)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:1263)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:1119)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1084)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:682)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:534)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:481)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:555)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.example.sceneform.MainActivity.onCreate(MainActivity.java:59)
        at android.app.Activity.performCreate(Activity.java:7815)
        at android.app.Activity.performCreate(Activity.java:7804)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1318)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3349)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3513)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2109)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/filament/gltfio/Gltfio;
        at com.google.ar.sceneform.rendering.EngineInstance.gltfioInit(EngineInstance.java:96)
        at com.google.ar.sceneform.rendering.EngineInstance.createEngine(EngineInstance.java:110)
        at com.google.ar.sceneform.rendering.EngineInstance.getEngine(EngineInstance.java:42)
        at com.google.ar.sceneform.rendering.Renderer.initialize(Renderer.java:542)
        at com.google.ar.sceneform.rendering.Renderer.<init>(Renderer.java:109)
        at com.google.ar.sceneform.SceneView.initialize(SourceFile:37)
        at com.google.ar.sceneform.SceneView.<init>(SourceFile:13)
        at com.google.ar.sceneform.ArSceneView.<init>(SourceFile:10)
            ... 48 more
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.filament.gltfio.Gltfio" on path: DexPathList[[zip file "/data/app/com.example.sceneform-wiYXdRfeb7wSS91CFPS9tw==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.sceneform-wiYXdRfeb7wSS91CFPS9tw==/lib/arm64, /data/app/com.example.sceneform-wiYXdRfeb7wSS91CFPS9tw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
            ... 56 more
I/Process: Sending signal. PID: 30804 SIG: 9
Disconnected from the target VM, address: 'localhost:8628', transport: 'socket'

Now, an interesting twist: Android Studio warns me to convert the <fragment> in content_main.xml to a <androidx.fragment.app.FragmentContainerView> (now I'm figureing out that implementation "androidx.preference:preference:1.1.1 suggests that). Now if I do that the filament file not found + Binary XML file line #22 uninterpretable / unactionable series of exceptions go away, but then I faced with a big fat NPE:

E/Perf: Fail to get file list com.example.sceneform
    getFolderSize() : Exception_1 = java.lang.NullPointerException: Attempt to get length of null array
W/ample.scenefor: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed)
W/ample.scenefor: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.sceneform, PID: 5729
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sceneform/com.example.sceneform.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.ar.sceneform.Scene com.google.ar.sceneform.ArSceneView.getScene()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3374)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3513)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2109)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.ar.sceneform.Scene com.google.ar.sceneform.ArSceneView.getScene()' on a null object reference
        at com.example.sceneform.MainActivity.onCreate(MainActivity.java:76)
        at android.app.Activity.performCreate(Activity.java:7815)
        at android.app.Activity.performCreate(Activity.java:7804)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1318)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3349)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3513) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2109) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7682) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 
I/Process: Sending signal. PID: 5729 SIG: 9

How can I got out of this?

MrCsabaToth commented 4 years ago

This is kinda serious for me.

MrCsabaToth commented 4 years ago

The problem was that with Sceneform SDK 1.16 and up there's a breaking change: now I need to manually add the sceneformsrc and sceneformux directories from the SDK into my project. After the com.google.ar.sceneform.ux:sceneform-ux:1.* has to be removed from the gradle.build file (because it's now part as a source of the app and both would result in class duplication). This only applies if someone upgrades the dependencies and the Android Studio plugin to 1.16 / 1.17 respectively. You don't want to stay behind. As an extra, if your code uses newer androidx libraries, you need to modify the SDK's source to accommodate that and being able to be compiled.

MrCsabaToth commented 4 years ago

Blog post: https://csaba.page/blog/sceneform-breaking-change.html

GokulDas027 commented 4 years ago

@MrCsabaToth Is ViewRenderable working on version 1.17 and do you have any idea why the Sceneform Repo is archived.

MrCsabaToth commented 4 years ago

@MrCsabaToth Is ViewRenderable working on version 1.17 and do you have any idea why the Sceneform Repo is archived.

Not sure but it is very concerning for the future

ferPrieto commented 4 years ago

I've faced the same problem as @MrCsabaToth and I've got to the point where I've had to choose:

Hope that helps. You can find my code in one of my repositories on Github

MrCsabaToth commented 4 years ago

I've faced the same problem as @MrCsabaToth and I've got to the point where I've had to choose:

  • Using 'com.google.ar:core:1.18.0' with the java resources that Google published long ago (in my case, I've separated that in a isolated module)
  • Using sceneForm with ArFragment and not using the last version (but instead, using 'com.google.ar.sceneform:plugin:1.9.0')

Hope that helps. You can find my code in one of my repositories on Github

So you say to either drop Sceneform and work directly with ARCore (with some extra code you mention) or roll back to an earlier version of Sceneform? In the former case I'd lose majority of what Sceneform covers. The ARCore Java layer you mention - how much does that cover of the Sceneform layer? Doesn't seem much. (Comparing the https://github.com/ferPrieto/ARCoreAnchors/tree/master/ar-core/src/main/java/fernando/prieto/ar_core/ with https://github.com/CsabaConsulting/ARPhysics/tree/master/sceneformux and https://github.com/CsabaConsulting/ARPhysics/tree/master/sceneformsrc) In the latter case why so far back as 1.9? Things still worked fine with 1.12-1.14.

MrCsabaToth commented 3 years ago

These days if I'd start a SceneForm project I'd rely on Thomas Gorisse's repository https://github.com/ThomasGorisse/sceneform-android-sdk instead of copying the two directories on my own and upgrading them to AndroidX on my own. Romain Guy pointed to that repository https://twitter.com/romainguy/status/1371864003882807300 See also https://csaba.page/blog/sceneform-good-news.html