【发布时间】:2021-01-07 11:33:57
【问题描述】:
我正在使用 Sceneform 1.16 和 andriod studio 4.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.java.
公共类 MainActivity 扩展 AppCompatActivity {
private ArFragment arFragment; private ModelRenderable modelRenderable; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
错误:
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 入门
你能告诉我是什么问题吗?
构建 gradle 文件
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")
}
【问题讨论】:
-
您可以添加您的应用 build.grade 吗?
-
谢谢。添加了构建 gradle 文件
-
如果将父级从 FrameLayout 更改为其他内容,错误仍然发生?我有一个使用 sceneform 1.17.0 的应用程序,我的片段位于 androidx.constraintlayout.widget.ConstraintLayout 中。我的其余代码和你的一样。