Why am i getting this error when trying to create an ar app?
Unable to load Renderable registryId='android.resource://com.nevco.ar/raw/cat'
java.util.concurrent.CompletionException: java.lang.AssertionError: No RCB file at uri: android.resource://com.nevco.ar/raw/cat
I am folliwng this tutorial to create a simple ar app, but everytime i launch my app i keep getting this error. I am not sure what to do to fix this. Some help would be grealty appreciated. I attached the link to the tutorial. https://www.androidauthority.com/google-arcore-972579/
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private static final double MIN_OPENGL_VERSION = 3.0;
//Create a member variable for ModelRenderable//
private ModelRenderable dinoRenderable;
//Create a member variable for ArFragment//
private ArFragment arCoreFragment;
@RequiresApi(api = VERSION_CODES.N)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!checkDevice((this))) {
return;
}
setContentView(R.layout.activity_main);
arCoreFragment = (ArFragment)
//Find the fragment, using fragment manager//
getSupportFragmentManager().findFragmentById(R.id.main_fragment);
if (Build.VERSION.SDK_INT >= VERSION_CODES.N) {
//Build the ModelRenderable//
ModelRenderable.builder()
.setSource(this, R.raw.cat)
.build()
.thenAccept(renderable -> dinoRenderable = renderable)
.exceptionally(
//If an error occurs...//
throwable -> {
//...then print the following message to Logcat//
Log.e(TAG, "Unable to load renderable");
return null;
});
}
//Listen for onTap events//
arCoreFragment.setOnTapArPlaneListener(
(HitResult hitResult, Plane plane, MotionEvent motionEvent) -> {
if (dinoRenderable == null) {
return;
}
Anchor anchor = hitResult.createAnchor();
//Build a node of type AnchorNode//
AnchorNode anchorNode = new AnchorNode(anchor);
//Connect the AnchorNode to the Scene//
anchorNode.setParent(arCoreFragment.getArSceneView().getScene());
//Build a node of type TransformableNode//
TransformableNode transformableNode = new TransformableNode(arCoreFragment.getTransformationSystem());
//Connect the TransformableNode to the AnchorNode//
transformableNode.setParent(anchorNode);
//Attach the Renderable//
transformableNode.setRenderable(dinoRenderable);
//Set the node//
transformableNode.select();
});
}
public static boolean checkDevice(final Activity activity) {
//If the device is running Android Marshmallow or earlier...//
if (Build.VERSION.SDK_INT < VERSION_CODES.N) {
//...then print the following message to Logcat//
Log.e(TAG, "Sceneform requires Android N or higher");
activity.finish();
return false;
}
String openGlVersionString =
((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE))
.getDeviceConfigurationInfo()
//Check the version of OpenGL ES//
.getGlEsVersion();
//If the device is running anything less than OpenGL ES 3.0...//
if (Double.parseDouble(openGlVersionString) < MIN_OPENGL_VERSION) {
//...then print the following message to Logcat//
Log.e(TAG, "Requires OpenGL ES 3.0 or higher");
activity.finish();
return false;
}
return true;
}
}
You have to first create a node and add renderable of the model in it then attach it to the arFragment. You just used the renderable directly without creating a node. There you are getting the error. Check the below code addNodeToScene() method.
Try the following code,
package com.example.arcorefirst;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.widget.Toast;
import com.google.ar.core.Anchor;
import com.google.ar.core.HitResult;
import com.google.ar.core.Plane;
import com.google.ar.sceneform.AnchorNode;
import com.google.ar.sceneform.rendering.ModelRenderable;
import com.google.ar.sceneform.rendering.Renderable;
import com.google.ar.sceneform.ux.ArFragment;
import com.google.ar.sceneform.ux.TransformableNode;
public class MainActivity extends AppCompatActivity {
private static final String TAG = MainActivity.class.getSimpleName();
private static final double MIN_OPENGL_VERSION = 3.0;
ArFragment arFragment;
ModelRenderable lampPostRenderable;
private Uri selectedObject;
@Override
@SuppressWarnings({"AndroidApiChecker", "FutureReturnValueIgnored"})
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
arFragment.setOnTapArPlaneListener(
(HitResult hitresult, Plane plane, MotionEvent motionevent) -> {
if (plane.getType() != Plane.Type.HORIZONTAL_UPWARD_FACING)
return;
Anchor anchor = hitresult.createAnchor();
placeObject(arFragment, anchor, R.raw.cube);
}
);
}
private void placeObject(ArFragment arFragment, Anchor anchor, int uri) {
ModelRenderable.builder()
.setSource(arFragment.getContext(), uri)
.build()
.thenAccept(modelRenderable -> addNodeToScene(arFragment, anchor, modelRenderable))
.exceptionally(throwable -> {
Toast.makeText(arFragment.getContext(), "Error:" + throwable.getMessage(), Toast.LENGTH_LONG).show();
return null;
}
);
}
private void addNodeToScene(ArFragment arFragment, Anchor anchor, Renderable renderable) {
AnchorNode anchorNode = new AnchorNode(anchor);
TransformableNode node = new TransformableNode(arFragment.getTransformationSystem());
node.setRenderable(renderable);
node.setParent(anchorNode);
arFragment.getArSceneView().getScene().addChild(anchorNode);
node.select();
}
}
For more checkout my repo:
codemaker2015/ar-object-augmentation-android-studio
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With