Home > Software design >  Android studio com.google.ar.sceneform.ux.ArFragment is incompatible with androidx.fragment.app.Frag
Android studio com.google.ar.sceneform.ux.ArFragment is incompatible with androidx.fragment.app.Frag

Time:02-14

Does android studio don't support sceneform library anymore? because whenever I instantiate ArFragment with (ArFragment) getSupportFragmentManager().findFragmentById(R.id.fragment) I get an error that says Inconvertible types; cannot cast 'androidx.fragment.app.Fragment' to 'com.google.ar.sceneform.ux.ArFragment

I already put <meta-data android:name="com.google.ar.core" android:value="required" /> in manifest and all the stuff needed

This is my xml code

<?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>

This is my Java code

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);
    }
}

This is my gradle dependencies look like

    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'

CodePudding user response:

Google stopped the development in 2020. Please use the current maintained version

  • Related