flutter-unity-view-widget icon indicating copy to clipboard operation
flutter-unity-view-widget copied to clipboard

Is it possible to pre-compile the unitylibrary for android/ios to later run with Codemagic

Open emileswain opened this issue 11 months ago • 6 comments

This article shows how codemagic can be used to compile Unity as a library projects in the cloud.

I'd like to save my build minutes so i'm wondering if there is a way to pre-build the unityLibrary packages that Unity generates into something smaller?

As it stands, the android/unitylibrary and ios/unitylibrary folders are both GB's in size, making it impractical to check them in. And whilsts the Unity project is only 200MB itself, I feel that getting code magic to compile Unity is going to be a big hassel, (also I believe you need a pro license?).

I'm wondering if there is a way to only provide specific assets that the flutter build process needs? i.e. not all 4GB of unitylibrary folder assets for ios and android?

emileswain avatar Mar 12 '24 15:03 emileswain

Unity used to do this.

Up to 2019.3.x it compiled everything in the build/export phase and Flutter only needed to include a small compiled project.
See the android/unityLibrary folder in this repo

Any newer version exports a project that still needs to compile and which makes the Flutter build experience worse.

I've complained on the unity forums, but this is simply their 'improved' android export.

I don't think there is an easy way. The only possibility might be to extract it from the flutter build folder after a build (I see a unitylibrary folder in there). But getting that working as a valid gradle project might be a nightmare.

timbotimbo avatar Mar 12 '24 17:03 timbotimbo

Thanks for the heads up. Yeah, i was wondering if it was going to be worth investigating how gradle libraries etc work to see if a pre-compile would work, sounds like it would be horendous. If i find anything out i'll update this thread.

emileswain avatar Mar 12 '24 17:03 emileswain

I found something that works on Android once you have both exported unity and made a build in Flutter.

This output is from 2022.3.21, it might be slightly different for other Unity versions.

1

Open the android/unityLibrary folder. Delete build and symbols.

- build/
libs/
src/
- symbols/
build.gradle
proguard-unity.txt

2

Open unityLibrary/src/main, delete Il2CppOutputProject.

assets/
- Il2CppOutputProject/
java/
jniLibs/
jniStaticLibs/
res/
resources/
AndroidManifest.xml

3

Now open unityLibrary/build.gradle

Delete everything below the first android section

android {
    
    compileSdkVersion ..
    buildToolsVersion ..

    ..

    packagingOptions {
        doNotStrip '*/armeabi-v7a/*.so'
        doNotStrip '*/arm64-v8a/*.so'
    }
}


# Delete everything below this

- def getSdkDir() {
- ...
- }

- def BuildIl2Cpp(...) {
- ...
- }

- android {
-    task BuildIl2CppTask {
-    }
-   ..
- }

With these changes my android unityLibrary folder is around 145MB (basic unity project) and it still works after a flutter clean.

timbotimbo avatar Mar 14 '24 14:03 timbotimbo

This is great thanks! I was heading in the right direction at least. So will try this out when I go back to the build setup. Its crazy how the build process duplicates those so files into multiple locations. its literally 800MB of duplicated files and then 4GB of build files. Unity really does take liberties with your disc space.

emileswain avatar Mar 14 '24 14:03 emileswain

Hi @emileswain @timbotimbo, by any chance, did you figure out a way to make it work on iOS?

foreg avatar Aug 07 '24 14:08 foreg

I didn’t look any further into it because my project was a POC and hasn’t got to codemagic yet. May do later this year.

I think the last message from timbitimbo in discourse had an approach on how to do it. But I didn’t validate it myself.

On Wed, 7 Aug 2024 at 15:53, foreg @.***> wrote:

Hi @emileswain https://github.com/emileswain @timbotimbo https://github.com/timbotimbo, by any chance, did you figure out a way to make it work on iOS?

— Reply to this email directly, view it on GitHub https://github.com/juicycleff/flutter-unity-view-widget/issues/936#issuecomment-2273668482, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGWUOVTRPD7ZRLBYWB2PKDZQIYGTAVCNFSM6AAAAABESQUYKWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZTGY3DQNBYGI . You are receiving this because you were mentioned.Message ID: @.***>

emileswain avatar Aug 07 '24 15:08 emileswain