f111fei / react-native-unity-demo

103 stars 80 forks source link

Library doesn't work with Unity version 2018.2.14f1 #21

Closed ShaubertIlya closed 5 years ago

ShaubertIlya commented 5 years ago

It says that com.unity3d.player does not exist

Task :react-native-unity-view:compileDebugJavaWithJavac FAILED Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityUtils.java:10: error: package com.unity3d.player does not exist import com.unity3d.player.UnityPlayer; ^ Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityUtils.java:21: error: cannot find symbol private static UnityPlayer unityPlayer; ^ symbol: class UnityPlayer location: class UnityUtils Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityUtils.java:26: error: cannot find symbol public static UnityPlayer getPlayer() { ^ symbol: class UnityPlayer location: class UnityUtils Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityView.java:11: error: package com.unity3d.player does not exist import com.unity3d.player.UnityPlayer; ^ Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityView.java:19: error: cannot find symbol private UnityPlayer view; ^ symbol: class UnityPlayer location: class UnityView Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityView.java:21: error: cannot find symbol protected UnityView(Context context, UnityPlayer view) { ^ symbol: class UnityPlayer location: class UnityView Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityViewManager.java:12: error: package com.unity3d.player does not exist import com.unity3d.player.UnityPlayer; ^ Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityUtils.java:49: error: cannot find symbol unityPlayer = new UnityPlayer(activity); ^ symbol: class UnityPlayer Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityUtils.java:73: error: cannot find symbol UnityPlayer.UnitySendMessage(gameObject, methodName, message); ^ symbol: variable UnityPlayer location: class UnityUtils Note: Q:\LocalRepo\react-native-unity-demo-master\node_modules\react-native-unity-view\android\src\main\java\com\reactnative\unity\view\UnityViewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 9 errors

sutefan1 commented 5 years ago

You need to link the unity-classes.jar. Therefore do the following steps:

Another way would be to add this change in the gradle file.

ShaubertIlya commented 5 years ago

@papsti7 I don't work in Android Studio. I've added this two strings

compile project(':UnityExport') compile fileTree(dir: '../../../android/UnityExport/libs', include: ['*.jar'])

into my android/app/build.gradle file, but it still doesn't work. I still get this issue about UnityPlayer. Can i do it just with react-native in Visual Code?

sutefan1 commented 5 years ago

@ShaubertIlya I didn't test the solution from the link, but I thought it solves the same issue.

Nevertheless, you need to link the export in react-native-unity-view project, which comes with npm, and not in the demo project directly.

In my case, it's the absolute path, like implementation files('/Users/stefan/Documents/Programming/react-native-unity/react-native-unity-demo/android/UnityExport/libs/unity-classes.jar')

Let me know if this works.

JanOwiesniak commented 5 years ago

This demo works with Unity 2018.2.14f1 on my iPhone 6s (iOS 12.0.1) and my Nokia 6.1 (Android 8.1.0). This helped me to bring it on Android. That to make it run on iOS.

ShaubertIlya commented 5 years ago

@ShaubertIlya I didn't test the solution from the link, but I thought it solves the same issue.

Nevertheless, you need to link the export in react-native-unity-view project, which comes with npm, and not in the demo project directly.

  • So navigate to node_modules/react-native-unity-view/android/
  • Open the build.gradle
  • Add implementation files('XXX/UnityExport/libs/unity-classes.jar'), where XXX is the path to the UnityExportfolder, to the dependencies

In my case, it's the absolute path, like implementation files('/Users/stefan/Documents/Programming/react-native-unity/react-native-unity-demo/android/UnityExport/libs/unity-classes.jar')

Let me know if this works.

I did this and it doesn't work for me

sutefan1 commented 5 years ago

@ShaubertIlya Make sure you clean the project before building again. Is it the same error or did something change? If it still doesn't wanna work, please install Android Studio and follow the steps from this comment.

f111fei commented 5 years ago

Update Build.cs. fix with the commit https://github.com/f111fei/react-native-unity-demo/commit/56a0e149a17b31c55ea7c0002ebb3ae15807ed71

https://github.com/f111fei/react-native-unity-demo/commit/56a0e149a17b31c55ea7c0002ebb3ae15807ed71#diff-22cc3ee3c446922e4674cdd477015084