react-native-unity icon indicating copy to clipboard operation
react-native-unity copied to clipboard

Build failed for Android, Unity 2023.2.15f1, library version 1.0.10

Open braginpavel opened this issue 1 year ago • 24 comments

Hi,

Tried to build app for Android, Unity 2023.2.15f1, library version 1.0.10. Got error below:

> Task :azesmway_react-native-unity:compileDebugJavaWithJavac FAILED
/Users/paul/Documents/projects/project/node_modules/@azesmway/react-native-unity/android/src/main/java/com/azesmwayreactnativeunity/UPlayer.java:100: error: incompatible types: UnityPlayer cannot be converted to FrameLayout
            return unityPlayer;
                   ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':azesmway_react-native-unity:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/8.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1m 20s
329 actionable tasks: 4 executed, 325 up-to-date
Error: /Users/paul/Documents/projects/project/android/gradlew exited with non-zero code: 1
Error: /Users/paul/Documents/projects/project/android/gradlew exited with non-zero code: 1
    at ChildProcess.completionListener (/Users/paul/Documents/projects/project/node_modules/@expo/cli/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23)
    at Object.onceWrapper (node:events:629:26)
    at ChildProcess.emit (node:events:514:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)
    ...
    at Object.spawnAsync [as default] (/Users/paul/Documents/projects/project/node_modules/@expo/cli/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21)
    at spawnGradleAsync (/Users/paul/Documents/projects/project/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:72:46)
    at Object.assembleAsync (/Users/paul/Documents/projects/project/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:52:18)
    at runAndroidAsync (/Users/paul/Documents/projects/project/node_modules/@expo/cli/build/src/run/android/runAndroidAsync.js:36:24)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

braginpavel avatar Jun 24 '24 05:06 braginpavel

I am having the same problem with Unity 6

cf-moritzjaeger avatar Jul 16 '24 13:07 cf-moritzjaeger

Could you please try this? Here's the link: https://github.com/byplay-io/react-native-unity.git

rmethaniya avatar Jul 17 '24 17:07 rmethaniya

hi has anyone been able to fix the above issue?

orjiAce avatar Aug 07 '24 14:08 orjiAce

Could you please try this? Here's the link: https://github.com/byplay-io/react-native-unity.git

hi please can you explain more on how to apply this solution?

orjiAce avatar Aug 07 '24 16:08 orjiAce

Hi,

Tried to build app for Android, Unity 2023.2.15f1, library version 1.0.10. Got error below:

> Task :azesmway_react-native-unity:compileDebugJavaWithJavac FAILED
/Users/paul/Documents/projects/project/node_modules/@azesmway/react-native-unity/android/src/main/java/com/azesmwayreactnativeunity/UPlayer.java:100: error: incompatible types: UnityPlayer cannot be converted to FrameLayout
            return unityPlayer;
                   ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':azesmway_react-native-unity:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/8.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1m 20s
329 actionable tasks: 4 executed, 325 up-to-date
Error: /Users/paul/Documents/projects/project/android/gradlew exited with non-zero code: 1
Error: /Users/paul/Documents/projects/project/android/gradlew exited with non-zero code: 1
    at ChildProcess.completionListener (/Users/paul/Documents/projects/project/node_modules/@expo/cli/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23)
    at Object.onceWrapper (node:events:629:26)
    at ChildProcess.emit (node:events:514:28)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)
    ...
    at Object.spawnAsync [as default] (/Users/paul/Documents/projects/project/node_modules/@expo/cli/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21)
    at spawnGradleAsync (/Users/paul/Documents/projects/project/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:72:46)
    at Object.assembleAsync (/Users/paul/Documents/projects/project/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:52:18)
    at runAndroidAsync (/Users/paul/Documents/projects/project/node_modules/@expo/cli/build/src/run/android/runAndroidAsync.js:36:24)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

hi did you find a solution? I'm having this same issue

orjiAce avatar Aug 14 '24 14:08 orjiAce

I am having the same problem with Unity 6

hi did you find a solution?

orjiAce avatar Aug 24 '24 16:08 orjiAce

Sadly not yet. I progressed with my project in Unity 2022 for now.

cf-moritzjaeger avatar Aug 26 '24 16:08 cf-moritzjaeger

@azesmway hi guys please help with this, thanks

orjiAce avatar Aug 27 '24 21:08 orjiAce

Sadly not yet. I progressed with my project in Unity 2022 for now.

Did this solve the issue for you? We're seeing the same error using 2023.

alexboyer avatar Oct 04 '24 16:10 alexboyer

Sadly not yet. I progressed with my project in Unity 2022 for now.

So is it working for you on Unity 2022?

douglasndm avatar Oct 06 '24 09:10 douglasndm

Sadly not yet. I progressed with my project in Unity 2022 for now.

So is it working for you on Unity 2022?

Yes, because the problem is caused by a change made in Unity 2023 (and onwards)

cf-moritzjaeger avatar Oct 07 '24 09:10 cf-moritzjaeger

Same problem with Unity 6000.0.23f1 Are there any solutions?

ramanradzivonau avatar Oct 30 '24 14:10 ramanradzivonau

Same problem with Unity 6000.0.23f1 Are there any solutions?

I was only able to work with Unity 2022

douglasndm avatar Oct 30 '24 16:10 douglasndm

Anyone get solution for above? Unity 2022 working fine. With Unity 2023 and after version not working due to 'Android: UnityPlayer java class no longer extends FrameLayout' reason ref: https://docs.unity3d.com/cn/2023.2/Manual/UpgradeGuide20231.html

@azesmway I saw you made changes in UPlayer.java. To get new unity 2023 class UnityPlayerForActivityOrService. That is fine. But we are getting this error now...

D:\Dhruv\react\unity2023\react-native-unity-app-main\node_modules\@azesmway\react-native-unity\android\src\main\java\com\azesmwayreactnativeunity\UPlayer.java:100: error: incompatible types: UnityPlayer cannot be converted to FrameLayout
            return unityPlayer;

I think something code implementation need to change in method 'requestFocusPlayer' and 'requestFrame' of UPlayer.java. Please provide any solution if you have.

Anybody get solution of above please tell here. Thanks.

dhruvaura avatar Nov 29 '24 05:11 dhruvaura

Yes, UnityPlayer no longer extends FrameLayout in newer versions, causing this compile error because of incompatible types. https://github.com/azesmway/react-native-unity/blob/86f89a64c96af2a918020e9170cbd9d8d0b260ac/android/src/main/java/com/azesmwayreactnativeunity/UPlayer.java#L100 For a quick fix, just modify node_modules (temporary test solution) <project>/node_modules/@azesmway/react-native-unity/android/src/main/java/com/azesmwayreactnativeunity/UPlayer.java:100 to let it return null (return null;).

To fix this issue and make it work for both old and new UnityPlayer class, change com.azesmwayreactnativeunity.UPlayer.requestFrame:

  public FrameLayout requestFrame() {
      try {
          //Attempt to invoke getFrameLayout() for the newer UnityPlayer class
          Method getFrameLayout = unityPlayer.getClass().getMethod("getFrameLayout");
          return (FrameLayout) getFrameLayout.invoke(unityPlayer);
      } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
          // If it is old UnityPlayer, use isInstance() and cast() to bypass incompatible type checks when compiling using newer versions of UnityPlayer
          if (FrameLayout.class.isInstance(unityPlayer)) {
              return FrameLayout.class.cast(unityPlayer);
          } else {
              return null;
          }
      }
  }

dlyrsk avatar Nov 30 '24 08:11 dlyrsk

same issue @gyanani-ritika I have used above solution which provided by dlyrsk. It worked and solved issue above mentioned.

dhruvaura avatar Dec 25 '24 11:12 dhruvaura

@dhruvaura but it's not a good fix, whenever well run npm i it will again reset to the older/existing code

gyanani-ritika avatar Dec 25 '24 11:12 gyanani-ritika

@dhruvaura but it's not a good fix, whenever well run npm i it will again reset to the older/existing code

I think no need to run multiple time npm install after once you successfully integrate unity with react. Because after onwards you have to just replace exported android build and test.

dhruvaura avatar Dec 25 '24 11:12 dhruvaura

I'm surprised that you have reached that point. I can't build and getting this error

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/konsnos/Documents/GitHub/RNMoCap/node_modules/@azesmway/react-native-unity/android/build.gradle' line: 110

* What went wrong:
A problem occurred evaluating project ':azesmway_react-native-unity'.
> Project with path ':unityLibrary' could not be found in project ':azesmway_react-native-unity'.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 841ms
error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build failed with an exception. * Where:
Build file '/Users/konsnos/Documents/GitHub/RNMoCap/node_modules/@azesmway/react-native-unity/android/build.gradle' line: 110 * What went wrong:
A problem occurred evaluating project ':azesmway_react-native-unity'.
> Project with path ':unityLibrary' could not be found in project ':azesmway_react-native-unity'. * Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org. BUILD FAILED in 841ms.
info Run CLI with --verbose flag for more details.

The /build.gradle' line: 110 is pointing to implementation project(':unityLibrary'). I can't understand what I am missing and it can't find the project unityLibrary or how to debug this.

I'm also using Unity 6.

konsnos avatar Jan 02 '25 11:01 konsnos

@konsnos can you share your project structure? Just provide a screenshot of it maybe there is an issue with the structure.

gyanani-ritika avatar Jan 02 '25 11:01 gyanani-ritika

@gyanani-ritika Here it is Screenshot 2025-01-02 at 1 24 34 PM

konsnos avatar Jan 02 '25 11:01 konsnos

That was my bad. My set-up was wrong. I've finally reached the same issue as the rest of you! 🎉

The issue is related to Unity 2023 upgrades Android: UnityPlayer java class no longer extends FrameLayout. Has anyone tried @rmethaniya 's fork https://github.com/azesmway/react-native-unity/issues/123#issuecomment-2233777698 ?

konsnos avatar Jan 02 '25 16:01 konsnos

As I said in my previous comment, Unity 2023 broke the process. I've tried to think of a way to handle both 2022 and 2023 but haven't found one.

IMO go into ./node_modules/@azesmway/react-native-unity/android/src/main/java/com/azesmwayreactnativeunity/UPlayer.java and replace return unityPlayer; in line 100 with throw new NoSuchMethodException("getFrameLayout method not found. Are you using Unity 2022 or older?");

You should be able to build now.

Since Unity introduced that change maybe this repo can upgrade to Unity 2023/6 and drop backwards compatibility. If anyone wants to use an older Unity version they can also use an older version of this repo as well.

konsnos avatar Jan 03 '25 13:01 konsnos

@dlyrsk thanks for solution. @gyanani-ritika to persists the changes in any node_modules, you can go with patch-package.

Haseeba393 avatar Mar 26 '25 22:03 Haseeba393