juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.13k stars 514 forks source link

can't run the example #805

Closed nyck33 closed 1 year ago

nyck33 commented 1 year ago

Describe the bug

nyck33@nyck33-IdeaPad-Gaming-3-15ACH6:~/Documents/flutter/flutter-unity-view-widget/example$ flutter run
Launching lib/main.dart on A202ZT in debug mode...
Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01
Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/03 to old ns http://schemas.android.com/sdk/android/repo/addon2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/03 to old ns http://schemas.android.com/sdk/android/repo/repository2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/03 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01
Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
   > Could not resolve project :unityLibrary.
     Required by:
         project :app
      > No matching configuration of project :unityLibrary was found. The consumer was configured to find an API of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
          - None of the consumable configurations have attributes.

* 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 1s
Running Gradle task 'assembleDebug'...                           1,647ms
Exception: Gradle task assembleDebug failed with exit code 1

To Reproduce Steps to reproduce the behavior:

  1. git clone the repo
  2. open the example folder in Android studio
  3. open a terminal and type flutter run
nyck33@nyck33-IdeaPad-Gaming-3-15ACH6:~/Documents/flutter/flutter-unity-view-widget/example$ flutter doctor -v
[✓] Flutter (Channel stable, 3.7.12, on Ubuntu 22.04.2 LTS 5.19.0-41-generic, locale
    en_US.UTF-8)
    • Flutter version 3.7.12 on channel stable at
      /home/nyck33/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 4d9e56e694 (2 weeks ago), 2023-04-17 21:47:46 -0400
    • Engine revision 1a65d409c7
    • Dart version 2.19.6
    • DevTools version 2.20.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /home/nyck33/Android/Sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /opt/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at google-chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 10.0.0-4ubuntu1
    • cmake version 3.16.3
    • ninja version 1.10.0
    • pkg-config version 0.29.1

[✓] Android Studio (version 2022.2)
    • Android Studio at /opt/android-studio
    • Flutter plugin version 73.0.2
    • Dart plugin version 222.4560
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code
    • VS Code at /snap/code/current
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • A202ZT (mobile) • 320226898815 • android-arm64  • Android 12 (API 31)
    • Linux (desktop) • linux        • linux-x64      • Ubuntu 22.04.2 LTS
      5.19.0-41-generic
    • Chrome (web)    • chrome       • web-javascript • Google Chrome 113.0.5672.63

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
timbotimbo commented 1 year ago
  1. git clone the repo
  2. open the example folder in Android studio
  3. open a terminal and type flutter run

You are missing a vital step. 2.1. open example\unity\DemoApp in Unity3D 2.2. Click Flutter -> Export Android ( .. ) in Unity and wait for the process to complete.

The error is that there is no project in android\unityLibrary, which gets generated by Unity.

nyck33 commented 1 year ago

@timbotimbo thanks, I watched the video and read the Readme, almost had it running but it launched on the web browser so of course nothing worked.
This time I am getting some gradle and java compatibility error perhaps because I did this: In the Reedme it says, put the fuw-xxxx.unitypackage in the unity/appname folder which I did.

image

I guess I only need to do that if it's my own project and not the example project in this repo.

My exact gradle java error is:

nyck33@nyck33-IdeaPad-Gaming-3-15ACH6:~/Documents/flutter/flutter-unity-view-widget/example$ flutter run
Launching lib/main.dart on A202ZT in debug mode...

FAILURE: Build failed with an exception.

* What went wrong:
Could not open settings generic class cache for settings file '/home/nyck33/Documents/flutter/flutter-unity-view-widget/example/android/settings.gradle' (/home/nyck33/.gradle/caches/6.5/scripts/25aorcp10u58z2dyk7lm4qet/settings6418c6d726070f323dbddda2aadc82ef).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61

* 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 2s
Running Gradle task 'assembleDebug'...                              3.2s

┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────┐
│ [!] Your project's Gradle version is incompatible with the Java version that Flutter │
│ is using for Gradle.                                                                 │
│                                                                                      │
│ To fix this issue, first, check the Java version used by Flutter by running `flutter │
│ doctor --verbose`.                                                                   │
│                                                                                      │
│ Then, update the Gradle version specified in                                         │
│ /home/nyck33/Documents/flutter/flutter-unity-view-widget/example/android/gradle/wrap │
│ per/gradle-wrapper.properties to be compatible with that Java version. See the link  │
│ below for more information on compatible Java/Gradle versions:                       │
│ https://docs.gradle.org/current/userguide/compatibility.html#java                    │
│                                                                                      │
│                                                                                      │
└──────────────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1

Should I start over? I've started over like 5 times now.

nyck33 commented 1 year ago

I noticed some differences like I don't get a Unity-Exports folder at all. I do right click on the unity-classes.jar and get the following directory tree

image

nyck33 commented 1 year ago

I am also guessing that because I am using Android Studio Flamingo, which is using jdk 17 and not 11, that's the problem. I'll look into switching that as well.

timbotimbo commented 1 year ago

Please ignore the video, that should be removed from the readme, since its ancient.

I've managed to build my own project using Flamingo without issues, the switch to java 17 didn't seem to break it.

The example project has some old gradle versions so I'll need to check if something is incompatible there.

nyck33 commented 1 year ago

Got it, thanks, I'll try again. I'm on Ubuntu 22.04 (not WSL) but my Unity is on Windows so I boot out do the Unity stuff then come back to Ubuntu on dual boot and do my Flutter stuff just in case that is causing problems.

timbotimbo commented 1 year ago

I believe that an android export from Unity on mac and windows are incompatible when moved to the other platform. Although that could also be because of arm vs x64 processors.

So it wouldn't surprise me if moving a windows export to ubuntu might cause issues.

Sadly the Unity export on Ubuntu in general seems to be broken too, look for the 'linux' tag in these issues.

nyck33 commented 1 year ago

I see, so I have to stay in Windows it sounds like end to end. Not even WSL2 am I correct? Ie. I have to install Flutter on Windows and not WSL2.

What about this step, do I need to perform it for the example app in this repo?

Copy the fuw-XXXX.unitypackage file into the Unity project folder. The expected path is unity/project-name/fuw-XXXX.unitypackage

timbotimbo commented 1 year ago

You don't need the unitypackage if you are using the example Unity project. The unitypackage is basically the FlutterUnityIntegration folder in the example project.

nyck33 commented 1 year ago

Thanks! I'll give it another shot here.

nyck33 commented 1 year ago

A few more hideous errors but nailed it down to

* What went wrong:
Execution failed for task ':unityLibrary:BuildIl2CppTask'.
> NDK is not installed

so I tried this https://stackoverflow.com/questions/66603488/ndk-is-not-installed

so my local.properties is like

sdk.dir=C:\\Users\\nycki_gq3buqc\\AppData\\Local\\Android\\sdk
flutter.sdk=C:\\software\\flutter
flutter.buildMode=debug
ndk.dir=C:\Program Files\Android\Android Studio\plugins\android-ndk\lib

but that's not working either.

timbotimbo commented 1 year ago

Can you try adding the Unity NDK? (edit to match your exact unity version) For windows you'll need \\ instead of \

    // mac
    ndk.dir=/Applications/Unity/Hub/Editor/2020.3.19f1/PlaybackEngines/AndroidPlayer/NDK
    // windows
    ndk.dir=C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.13f1\\Editor\\Data\\PlaybackEngines\\AndroidPlayer\\NDK

This was added to the readme, but for some reason not under Android Setup but a separate NDK section.

nyck33 commented 1 year ago

Everything works now, thanks! Except Native Activity Demo

Another exception was thrown: Could not find a generator for route
RouteSettings("/activity", null) in the _WidgetsAppState.
D/VelocityTracker(32111): addMovement: actionMasked:1, mChangeDirection:0, set it true

Another exception was thrown: Could not find a generator for route
RouteSettings("/activity", null) in the _WidgetsAppState.
Byambasurenn commented 8 months ago

Hello, I ran into this exact error and tried what's written on this thread. It's still not working. Here is list of the things I tried: