2

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

Dennis
  • 818
  • 2
  • 10
  • 23
  • I ended up adding all necessary files Unity needs to the Android project itself. Apparently using it as a library doesn't work that well. Whenever something changes to your Unity code, you just export the project to an Android project again and replace the assets folder in your Android project with the one from the generated Android project. – Dennis Jun 26 '18 at 14:40

2 Answers2

3

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

  • This really helped. I imported VuforiaWrapper as module, and added to `settings.graddle` like `include ':app', 'VuforiaWrapper'` – nipunasudha Nov 05 '18 at 18:26
  • yea even that works, I implemented in that way awsell, either of them do the work – MarioAndroid Nov 27 '18 at 14:53
  • 1
    This doesn't seem working for me, I have everything. What is meant by *vuforiaWrapper*, is it a random name for the exported vuforia.arr, if it's the one then, it's not working for me – Idris Stack Aug 06 '20 at 11:22
  • Am getting this error : ```AndroidJavaException: java.lang.ClassNotFoundException: com.vuforia.VuforiaUnityPlayer.VuforiaInitializer java.lang.ClassNotFoundException: com.vuforia.VuforiaUnityPlayer.VuforiaInitializer``` – Idris Stack Aug 06 '20 at 11:23
0

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'])
Ritz
  • 26
  • 2