首页 文章

集成在Android项目中的Unity(Vuforia)项目在启动时显示黑屏

提问于
浏览
2

My situation:

我创建了一个Android应用程序和一个使用Vuforia 7.0.47的AR Unity应用程序 . Android应用程序具有许多功能,其中一个功能是使用Unity和Vuforia制作的增强现实 .

为了在Android项目中轻松包含并稍后替换Unity项目,我将Unity应用程序导出到Android Studio项目并使其成为库 . 之后我在我的Android项目中添加了.aar文件 .

所有这一切似乎都有效,因为我的Android项目能够检测UnityPlayerActivity并能够启动Intent .

我现在使用以下代码(一个普通的Intent)在我的Android应用程序中启动Unity应用程序:

Intent intent = new Intent(this, UnityPlayerActivity.class);
startActivity(intent);

The problem I have:

每当UnityPlayerActivity启动时,您会看到Unity闪屏,然后是黑屏,而不是AR的摄像头 .

但是,当我将Unity项目构建到我的手机时,一切正常,就像将它导出到Android工作室项目并从那里运行一样 .

在我现有的Android项目中将其作为库包含时,似乎只会出现此问题 .

Tutorials and links I used/tried

为了从导出的项目创建库,我遵循以下教程:https://medium.com/@davidbeloosesky/embedded-unity-within-android-app-7061f4f473a

The Logcat

这是我在启动Intent时得到的Logcat

enter image description here

2 回答

  • 0

    您需要从中获取 VuforiaWrapper.aar 文件

    ExportedAndroidStudioProject /库/ VuforiaWrapper.aar

    并将其添加到您添加UnityGame.aar文件的同一目录中的应用程序,并将其作为依赖项添加到gradle中

    dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation(name: 'UnityGame', ext:'aar')
    implementation(name: 'VuforiaWrapper', ext:'aar')}
    

    希望这对你有所帮助 . 祝好运

  • 2

    如上所述,您必须添加VuforiaWrapper.aar

    但有时您必须添加依赖项

    implementation project(':VuforiaWrapper')
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    

相关问题