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 518 forks source link

Need build instructions for building plugin from source for contributing work #861

Open jamesncl opened 1 year ago

jamesncl commented 1 year ago

Please note this issue is about building the plugin itself, i.e. building the source code of this repository, this is not about building a flutter app which uses flutter-unity-view-widget as a 3rd party plugin

I'd like to try to fix #785 and other issues, but I can't seem to build the plugin source code. What I've done so far:

unityLibrary

Build file 'C:\Users\james\GithubRepos\flutter-unity-view-widget\android\build.gradle' line: 58

A problem occurred evaluating root project 'flutter_unity_widget'.

Project with path ':unityLibrary' could not be found in root project 'flutter_unity_widget'.

So I guess maybe I need to have an exported Unity project in the android subfolder, like android/unityLibrary - at first I tried copying the demo Unity app from the example folder into the root folder, as unity/DemoApp, and tried an export - but this fails because the export can't find the project's build.gradle file. That makes sense because it's a flutter plugin, not a flutter project, so I guessed that maybe I just copy an already-exported unityLibrary to android/unityLibrary, and add this to android/settings.gradle:

include ":unityLibrary"
project(":unityLibrary").projectDir = file("./unityLibrary")

Is that the right thing to do? It seemed to work, but then I got another error:

flutter_plugin_android_lifecycle

Build file 'C:\Users\james\GithubRepos\flutter-unity-view-widget\android\build.gradle' line: 67

A problem occurred evaluating root project 'flutter_unity_widget'.

Cannot convert a null value to an object of type Dependency. The following types/formats are supported:

  • Instances of Dependency.
  • String or CharSequence values, for example 'org.gradle:gradle-core:1.0'.
  • Maps, for example [group: 'org.gradle', name: 'gradle-core', version: '1.0'].
  • FileCollections, for example files('some.jar', 'someOther.jar').
  • Projects, for example project(':some:project:path').
  • ClassPathNotation, for example gradleApi().

Not sure what this error means (do any other contributors get this error?) but it points to this line in android/build.gradle:

compileOnly rootProject.findProject(":flutter_plugin_android_lifecycle")

Is this another project I need to clone? If so where do I put it? I tried just commenting it out for now. Then I get another error:

android references not found

C:\Users\james\GithubRepos\flutter-unity-view-widget\android\unityLibrary\src\main\java\com\unity3d\player\UnityPlayerActivity.java:3: error: package android.app does not exist import android.app.Activity; ^

At this point I'm totally stuck. Any help would be appreciated, especially from any maintainers / contributors who work on the android side of things - I just want to be able to build the project so I can contribute some changes. Thanks!

jamesncl commented 1 year ago

I just noticed there is also this in android/build.gradle:

    // FOR DEV ONLY
//    implementation(name: 'flutter', ext:'jar')

What is this for - do I need to comment it out? Same question for this: comment or uncomment?

        // FOR DEV ONLY
        flatDir {
            dirs "libs"
        }
timbotimbo commented 1 year ago

I haven't tried building the plugin seperately yet. (as I can't publish an update without juicycleff, who is mostly absent in this repo)

I generally make a change in the plugin (root folder), then I run Flutter clean and pub get in the example folder. The example includes the plugin from the parent folder, so the example now runs using the edited plugin.

I've use this so far to see if changes work, but none have ended up in an update yet.

Offtopic: I don't think the linked issue 785 needs a plugin update, see my comments on that issue.

jamesncl commented 1 year ago

Okay thank you so much for the help @timbotimbo that's a good workaround! I'll leave this issue open though because I do think it would help to be able to build the plugin folder, for example to get compiler warnings and AGP upgrade assistant etc. to work in Android Studio.

jamesncl commented 1 year ago

@timbotimbo I have decided to write my own plugin from scratch. I need to depend on this into the future and be able to update and maintain it, and much of the native code in this plugin is confusing, hard to follow and I'm guessing littered with hacks and fixes for lots of different versions of Unity, and I can't even build it, so thought it was worth the effort rebuilding from the ground up. It's not published to pub.dev yet, but you can find it on my github here: https://github.com/jamesncl/flutter_embed_unity, the main README is in the public facing package.

I've tried to make it as bare-bones as possible, well documented and hopefully the platform code is easier to follow. It's currently limited to only work with Unity 2022.3 LTS (hopefully this will make it more stable), but I've built it as a federated plugin, meaning that separate packages can be built in the future to support different versions of Unity separately.

It currently seems to be working but would welcome anyone to test the example project for yourself and report any bugs before I publish to pub.dev :)

timbotimbo commented 1 year ago

@jamesncl At first glance it looks like you've put quite some effort into documentation, which is a good sign.

I will try to test the example soon.

I started trying to maintain this repo for a similar reason. However it is kind of hard to do anything when the repo owner is absent.

Who knows, if your version ends up being stable and easier to maintain, I might jump ship.