我正在使用Sceneform 1.16和andriod Studio4.1,我试图渲染,但它不起作用。
问题:
activity.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
tools:context=".MainActivity">
<fragment android:name="com.google.ar.sceneform.ux.ArFragment" <======Error ArFragment must be a fragment >
android:id="@+id/ux_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
公共类MainActivity扩展AppCompatActivity {
私有ArFragment arFragment;私有ModelRenderable modelRenderable;@重写受保护的modelRenderable onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);arFragment = (ArFragment)
错误:
Inconvertible types; cannot cast 'androidx.fragment.app.Fragment' to 'com.google.ar.sceneform.ux.ArFragment'
我们遵循了以下步骤:https://github.com/google-ar/sceneform-android-sdk
-开始使用Sceneform 1.16.0
你能告诉我是怎么回事吗。
生成分级文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "30.0.1"
defaultConfig {
applicationId "com.examples.myapplication"
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
api project(":sceneformux")
}
发布于 2021-05-28 20:57:17
您应该编辑settings.gradle文件。增加以下几行:
include ':sceneform'
project(':sceneform').projectDir = new File('sceneformsrc/sceneform')
include ':sceneformux'
project(':sceneformux').projectDir = new File('sceneformux/ux')
发布于 2022-04-21 09:40:26
您有扩展ArFragment的片段类吗?我就像
<fragment android:name="com.example.zzz.FaceARFragment"
android:id="@+id/face_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
它是一个FaceARFragment扩展ArFragment类,仅用于配置。在活动中:
FaceARFragment arFragment = (FaceARFragment) getSupportFragmentManager().findFragmentById(R.id.face_fragment);
对我起作用了。您也可以尝试使用Sceneform 1.17,我尝试使用1.16,但是1.17对我来说更好,因为我使用的是.glb模型。
https://stackoverflow.com/questions/63991143
复制相似问题