Android studio com.google.ar.sceneform.ux.ArFragment 与 androidx.fragment.app.Fragment 不兼容

标签 android android-studio augmented-reality sceneform

android studio 不再支持 sceneform 库了吗?因为每当我实例化 ArFragment(ArFragment) getSupportFragmentManager().findFragmentById(R.id.fragment)我收到一条错误消息 Inconvertible types; cannot cast 'androidx.fragment.app.Fragment' to 'com.google.ar.sceneform.ux.ArFragment

我已经输入了 <meta-data android:name="com.google.ar.core" android:value="required" />在 list 和所有需要的东西

这是我的 xml 代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <fragment
        android:id="@+id/fragment"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:name="com.google.ar.sceneform.ux.ArFragment" />

</LinearLayout>

这是我的 Java 代码

package com.example.test;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.google.ar.sceneform.ux.ArFragment;

public class MainActivity extends AppCompatActivity {
    ArFragment arFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.fragment);
    }
}

这是我的 gradle 依赖项的样子

    implementation 'androidx.appcompat:appcompat:1.4.1'
    implementation 'com.google.android.material:material:1.5.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.17.1'

最佳答案

Google 于 2020 年停止开发。请使用当前的 maintained version

关于Android studio com.google.ar.sceneform.ux.ArFragment 与 androidx.fragment.app.Fragment 不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71099418/

相关文章:

flutter - '类型 'Color' 不是 'MaterialColor' 的子类型,每次我在 Android Studio 的模拟器(Android 和 iOS)上构建我的 Flutter 应用程序时都会出现错误

swift - ARKit/RealityKit – People Occlusion 配置不工作

augmented-reality - 标记识别后的AR.JS重定向

java - 数组内存泄漏

android - 无法在 Android Studio 中生成已签名的 APK, 'java.io.IOException'

android - 从坐标获取国家?

android - 为什么在布局背景中设置可绘制形状会被警告?

swift - ARKit People Occlusion 样本是如何完成的?

java - android.content.res.Resources$NotFoundException : String resource ID #0x0

android - java.io.IOException : Received authentication challenge is null 异常