google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 604 forks source link

ViewRenderable unable to add layout files #1037

Open kulnaman opened 4 years ago

kulnaman commented 4 years ago

@tpsiaki When I am trying to add viewRenderable through :

ViewRenderable.builder()
                .setSource(getContext(),R.layout.ar_image).build()
                .thenAccept(
                        viewRenderable -> {
                            renderable = viewRenderable;

                        })

I am getting error

E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.IllegalArgumentException: Unknown resource resourceType 'layout' in resId 'com.dds.webrtc:layout/ar_image'. Resource will not be loaded
        at com.google.ar.sceneform.utilities.LoadHelper.fromResource(LoadHelper.java:100)
        at com.google.ar.sceneform.rendering.Renderable$Builder.setSource(Renderable.java:375)
        at com.dds.java.voip.FragmentVideo.initAR(FragmentVideo.java:106)
        at com.dds.java.voip.FragmentVideo.init(FragmentVideo.java:208)
        at com.dds.java.voip.FragmentVideo.onCreateView(FragmentVideo.java:99)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2663)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManagerImpl.java:2613)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:246)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:542)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1514)
        at android.app.Activity.performStart(Activity.java:7838)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3359)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2081)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7643)
        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)

While looking through the LoadHelper class,

if (resourceType.equals(RAW_RESOURCE_TYPE) || resourceType.equals(DRAWABLE_RESOURCE_TYPE)) {
            return () -> context.getResources().openRawResource(resId);
        }

there is only support for raw or drawable resources only and So, instead of loading a layout resource, I tried to load a simple png image but then i am getting the error

2020-03-31 15:57:56.290 21256-21256/com.dds.webrtc W/System.err: java.util.concurrent.CompletionException: java.lang.AssertionError: ViewRenderable must have a source.
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:296)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:312)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at java.util.concurrent.CompletableFuture.uniAccept(CompletableFuture.java:657)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at java.util.concurrent.CompletableFuture.uniAcceptStage(CompletableFuture.java:679)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at java.util.concurrent.CompletableFuture.thenAccept(CompletableFuture.java:2025)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.dds.java.voip.FragmentVideo.initAR(FragmentVideo.java:107)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.dds.java.voip.FragmentVideo.init(FragmentVideo.java:208)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.dds.java.voip.FragmentVideo.onCreateView(FragmentVideo.java:99)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2663)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManagerImpl.java:2613)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:246)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:542)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1514)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.Activity.performStart(Activity.java:7838)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3359)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2081)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:107)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.os.Looper.loop(Looper.java:214)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7643)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err: Caused by: java.lang.AssertionError: ViewRenderable must have a source.
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.google.ar.sceneform.rendering.ViewRenderable$Builder.checkPreconditions(ViewRenderable.java:511)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.google.ar.sceneform.rendering.Renderable$Builder.build(Renderable.java:422)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.google.ar.sceneform.rendering.ViewRenderable$Builder.build(ViewRenderable.java:464)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:     at com.dds.java.voip.FragmentVideo.initAR(FragmentVideo.java:106)
2020-03-31 15:57:56.291 21256-21256/com.dds.webrtc W/System.err:    ... 30 more

is this issue similar to https://github.com/google-ar/sceneform-android-sdk/issues/1025 or something new.

kulnaman commented 4 years ago

@tpsiaki are you removing support for simple layout files as the loadHelper in sceneform utilities has support only for raw or drawable files