Unity (Vuforia) project integrated in Android proj

2020-02-26 12:59发布

My situation:

I created an Android app and an AR Unity app that makes use of Vuforia 7.0.47. The Android app has lots of features, one of the features is the augmented reality made with Unity and Vuforia.

In order to easily include and later on replace the Unity project in the Android project, I exported the Unity app to an Android Studio project and made it a library. After that I added the .aar file inside my Android project.

All of this seems to be working as my Android project is able to detect the UnityPlayerActivity and is able to start an Intent.

I now use the following code (a normal Intent) to start the Unity app inside my Android application:

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

The problem I have:

Whenever The UnityPlayerActivity starts, you see the Unity splash screen followed by a black screen instead of the camera opening for the AR.

However, when I build the Unity project to my phone everything works fine aswel as when exporting it to an Android studio project and running it from there.

The problem only seems to occur when including it as a library in my existing Android project.

Tutorials and links I used/tried

In order to create a library from the exported project I followed the following tutorial: https://medium.com/@davidbeloosesky/embedded-unity-within-android-app-7061f4f473a

The Logcat

This is the Logcat I get when starting the Intent

enter image description here

2条回答
萌系小妹纸
2楼-- · 2020-02-26 13:46

As mentioned you have to add VuforiaWrapper.aar

But sometimes you will have to add the dependency as

implementation project(':VuforiaWrapper')
implementation fileTree(dir: 'libs', include: ['*.jar'])
查看更多
倾城 Initia
3楼-- · 2020-02-26 13:48

You need to take VuforiaWrapper.aar file from

ExportedAndroidStudioProject/libs/VuforiaWrapper.aar

and add it to your app in the same directory where you added UnityGame.aar file and add it in gradle as a dependency

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

Hope this helps you. Good luck

查看更多
登录 后发表回答