我正在尝试使用AR Core和Sceneform Sdk创建一个简单的AR应用程序。我正在使用Android Studio模拟器来测试我的应用程序。我还遵循了Sceneform sdk的HelloAr示例代码。但是在logcat上显示这样的错误。
2019-05-04 14:27:15.942 5172-5172/com.example.arcoredemo E/native: status.cc:156 generic::internal: Physical cameras don't match device profile. 0 expected back facing:CameraDirection::kRearFacing actual back facing:CameraDirection::kFrontFacing
2019-05-04 14:27:15.943 5172-5172/com.example.arcoredemo E/native: session_create_implementation_shared.cc:1544 Failed to initilize the data source - -2
2019-05-04 14:27:15.946 5172-5172/com.example.arcoredemo E/native: session_create_implementation_shared.cc:1545 CreateLiveSessionWithMostDependencies returning ArStatusErrorSpace::AR_ERROR_FATAL: .
2019-05-04 14:27:15.963 5172-5172/com.example.arcoredemo I/native: feature_combo_node.cc:176 Cleared scoped_image buffers in feature_combo.
2019-05-04 14:27:15.966 5172-5172/com.example.arcoredemo I/native: android_camera.cc:730 Reset cleanly got to CLOSED state for camera 0
2019-05-04 14:27:15.972 5172-5172/com.example.arcoredemo I/native: session_create_implementation.cc:148 ArSession_createWithSettingsImplementation_private returning ArStatusErrorSpace::AR_ERROR_FATAL: .
2019-05-04 14:27:15.972 5172-5195/com.example.arcoredemo V/third_party/redwood/base/jni_common/jni_helper.cc: ~JniHelper: about to detach thread (Called from line 281).
2019-05-04 14:27:15.973 5172-5195/com.example.arcoredemo V/third_party/redwood/base/jni_common/jni_helper.cc: ~JniHelper: detached thread (Called from line 281).
2019-05-04 14:27:15.981 5172-5172/com.example.arcoredemo E/StandardArFragment: Error: Failed to create AR session
com.google.ar.core.exceptions.UnavailableException
at com.google.ar.sceneform.ux.BaseArFragment.initializeSession(BaseArFragment.java:356)
at com.google.ar.sceneform.ux.BaseArFragment.onResume(BaseArFragment.java:311)
at android.support.v4.app.Fragment.performResume(Fragment.java:2498)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:3241)
at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223)
at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:538)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:527)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:172)
at android.app.Activity.performResume(Activity.java:7317)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3776)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3816)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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)
Caused by: com.google.ar.core.exceptions.FatalException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at com.google.ar.core.Session.throwExceptionFromArStatus(Session.java:134)
at com.google.ar.core.Session.nativeCreateSessionAndWrapperWithFeatures(Native Method)
at com.google.ar.core.Session.<init>(Session.java:19)
at com.google.ar.sceneform.ux.BaseArFragment.createSessionWithFeatures(BaseArFragment.java:381)
at com.google.ar.sceneform.ux.BaseArFragment.createSession(BaseArFragment.java:370)
at com.google.ar.sceneform.ux.BaseArFragment.initializeSession(BaseArFragment.java:344)
at com.google.ar.sceneform.ux.BaseArFragment.onResume(BaseArFragment.java:311)
at android.support.v4.app.Fragment.performResume(Fragment.java:2498)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1501)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3269)
at android.support.v4.app.FragmentManagerImpl.dispatchResume(FragmentManager.java:3241)
at android.support.v4.app.FragmentController.dispatchResume(FragmentController.java:223)
at android.support.v4.app.FragmentActivity.onResumeFragments(FragmentActivity.java:538)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:527)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:172)
at android.app.Activity.performResume(Activity.java:7317)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3776)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3816)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
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)
您好我正在初始化和创建ar会话的Ar活动。
private static final String TAG = HelloArActivity.class.getSimpleName();
private static final double MIN_OPENGL_VERSION = 3.0;
private ArFragment arFragment;
@Override
@SuppressWarnings({"AndroidApiChecker", "FutureReturnValueIgnored"})
// CompletableFuture requires api level 24
// FutureReturnValueIgnored is not valid
protected void onCreate(Bundle savedInstanceState) {
if (!checkIsSupportedDeviceOrFinish(this)) {
return;
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_ar);
arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
// When you build a Renderable, Sceneform loads its resources in the background while returning
// a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get().
arFragment.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
Anchor anchor = hitResult.createAnchor();
MaterialFactory.makeOpaqueWithColor(this,new Color(android.graphics.Color.RED))
.thenAccept(material -> {
ModelRenderable renderable = ShapeFactory.makeSphere(1.0f,new Vector3(0f,1f,1f),material);
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setRenderable(renderable);
arFragment.getArSceneView().getScene().addChild(anchorNode);
});
});
}
/**
* Returns false and displays an error message if Sceneform can not run, true if Sceneform can run
* on this device.
*
* <p>Sceneform requires Android N on the device as well as OpenGL 3.0 capabilities.
*
* <p>Finishes the activity if Sceneform can not run
*/
public static boolean checkIsSupportedDeviceOrFinish(final Activity activity) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
Log.e(TAG, "Sceneform requires Android N or later");
Toast.makeText(activity, "Sceneform requires Android N or later", Toast.LENGTH_LONG).show();
activity.finish();
return false;
}
String openGlVersionString =
((ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE))
.getDeviceConfigurationInfo()
.getGlEsVersion();
if (Double.parseDouble(openGlVersionString) < MIN_OPENGL_VERSION) {
Log.e(TAG, "Sceneform requires OpenGL ES 3.0 later");
Toast.makeText(activity, "Sceneform requires OpenGL ES 3.0 or later", Toast.LENGTH_LONG)
.show();
activity.finish();
return false;
}
return true;
}
}