juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

emileswain opened this issue · 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?

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.

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.

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.

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.