yasirkula / UnityIonicIntegration

A guide to integrating Unity 3D content into an Ionic app and sending messages between them (for Android & iOS)(tested with Vuforia plugin)
104 stars 32 forks source link

Android build file: package com.unity3d.player does not exist #41

Closed ivanmayes closed 5 years ago

ivanmayes commented 5 years ago

Hey all! When I try to build on a clean project after adding the ionic plugin from the tutorial, this is the error log I get. Not sure what I can do to solve it. Do I need to be on a older gradle version?

Ionic:

   ionic (Ionic CLI)  : 4.1.1 (/Users/ivan.mayes/.npm_modules/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.11

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.0.0
   Cordova Plugins       : no whitelisted plugins (0 plugins total)

System:

   Android SDK Tools : 26.1.1 (/Users/ivan.mayes/Library/Android/sdk)
   NodeJS            : v10.6.0 (/usr/local/bin/node)
   npm               : 6.1.0
   OS                : macOS High Sierra
   Xcode             : Xcode 9.4.1 Build version 9F2000
BUILD FAILED in 24s
38 actionable tasks: 38 executed
(node:20377) UnhandledPromiseRejectionWarning: Error: /Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/gradlew: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:13: error: package com.unity3d.player does not exist
import com.unity3d.player.UnityPlayer;
                         ^
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:14: error: package com.unity3d.player does not exist
import com.unity3d.player.UnityPlayerActivity;
                         ^
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:16: error: cannot find symbol
public class UnityPlayerExtendedActivity extends UnityPlayerActivity
                                                 ^
  symbol: class UnityPlayerActivity
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:24: error: cannot find symbol
                                UnityPlayer.UnitySendMessage("IonicComms", intent.getStringExtra( "func" ), intent.getStringExtra( "param" ) );
                                ^
  symbol:   variable UnityPlayer
  location: class IonicToUnityBroadcastReceiver
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:34: error: method does not override or implement a method from a supertype
        @Override protected void onCreate (Bundle savedInstanceState)
        ^
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:36: error: cannot find symbol
                Intent intent = getIntent();
                                ^
  symbol:   method getIntent()
  location: class UnityPlayerExtendedActivity
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:42: error: cannot find symbol
                registerReceiver(broadcastReceiver, new IntentFilter( CordovaUnityLauncher.IONIC2UNITY_SEND_MESSAGE_BROADCAST ) );
                ^
  symbol:   method registerReceiver(IonicToUnityBroadcastReceiver,IntentFilter)
  location: class UnityPlayerExtendedActivity
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:43: error: cannot find symbol
                super.onCreate(savedInstanceState);
                ^
  symbol:   variable super
  location: class UnityPlayerExtendedActivity
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:46: error: method does not override or implement a method from a supertype
        @Override protected void onDestroy ()
        ^
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:48: error: cannot find symbol
                unregisterReceiver( broadcastReceiver );
                ^
  symbol:   method unregisterReceiver(IonicToUnityBroadcastReceiver)
  location: class UnityPlayerExtendedActivity
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:49: error: cannot find symbol
                super.onDestroy();
                ^
  symbol:   variable super
  location: class UnityPlayerExtendedActivity
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:59: error: cannot find symbol
                        sendBroadcast( ionicMessage );
                        ^
  symbol:   method sendBroadcast(Intent)
  location: class UnityPlayerExtendedActivity
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:75: error: cannot find symbol
                setResult(Activity.RESULT_OK, resultIntent);
                ^
  symbol:   method setResult(int,Intent)
  location: class UnityPlayerExtendedActivity
/Users/ivan.mayes/Projects/_tests/ionic-unity-test/platforms/android/app/src/main/java/com/unitycaller/ionic/UnityPlayerExtendedActivity.java:77: error: cannot find symbol
                finish();
                ^
  symbol:   method finish()
  location: class UnityPlayerExtendedActivity
14 errors

FAILURE: Build failed with an exception.
yasirkula commented 5 years ago

Is there a unity-classes.jar or something similar in UnityProject in Android Studio?

ivanmayes commented 5 years ago

Yes, that was the issue. Both the android project and the UnityProject had a unity-classes.jar file.

I had to remove the unity-classes.jar from the android project in the lib folder, then go to my UnityProject to the lib folder, right-click the unity-classes.jar file and select 'Add as Library'. Then select android as the project to add the library to.

zoix commented 5 years ago

Hello there,

I still have this problem. Following the instructions of @ivanmayes did not solve the problem.

I deleted the file unity-classes.jar located in the android module, and added as a library the one located in the Unity project. It automatically added the following line in my bundle.gradle file:

implementation files('/Users/MyUser/Developer/Cordova/hello/platforms/android/Unity/libs/unity-classes.jar')

But still did not work. I tried changing the previous line by the following hoping a different result:

compile fileTree(dir: '/Users/MyUser/Developer/Cordova/hello/platforms/android/Unity/libs', include: ['*.jar'])

But the result was the same. I did the process "manually" from File, Project Structure. Neither did work. I also tried with both Cordova and Ionic, exactly the same error in both:

error: package com.unity3d.player does not exist error: cannot find symbol class UnityPlayer

I have no idea what to try next. So any clue will be really appreciated.

zoix commented 5 years ago

This is me again! It is working now.

In bundle.gradle file of app module, instad of:

compile project(':UnityProject')

I am using:

implementation project(':UnityProject')

Which is the same thing Cordova actually does:

implementation project(path: ':CordovaLib')

Then, the unity-classes.jar file was implemented in the same way: implementation files('../Unity/libs/unity-classes.jar')

So the result is something like this:

dependencies {
    // SUB-PROJECT DEPENDENCIES START
    implementation project(path: ':CordovaLib')
    // SUB-PROJECT DEPENDENCIES END
    implementation project(':UnityProject')
    implementation files('../Unity/libs/unity-classes.jar')
}

And for some reason and no idea why since the unity-classes.jar is already implemented in the main module, I needed to do the same implementation for bundle.gradle file of Unity module. So just at the end of the file, the following:

dependencies {
    implementation files('libs/unity-classes.jar')
}

All this is Using Cordova 8.1.2 (cordova-lib@8.1.1) and Unity 2019.1.

Thank you @yasirkula for such an awesome work. Now I need to implement the same on iOS.