-
Notifications
You must be signed in to change notification settings - Fork 548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Android] Tips to reduce android build times. #643
Comments
Wow @timbotimbo , I followed your steps and I reduce the time from ~15min to 3min...thanks! |
Thanks @timbotimbo this should probably be added to the README for advanced users, but with an extra big warning to remove the changes for a release build. Just to add a bit more info from the Unity docs: Il2CppCodeGeneration
Il2CppCompilerConfiguration
|
Should I add this to our unitypackage? So that we improve android build? |
@Ahmadre The other 2 might be better off in the readme, because its better to disable them again for release builds. |
I tested everything with Unity 2021.* and 2022.* and there're some API-changes, actual solution looks like: #if UNITY_2020_3_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, Il2CppCompilerConfiguration.Debug);
EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize;
#elif UNITY_2022_1_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, Il2CppCompilerConfiguration.Debug);
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
#endif |
I will update this in |
Shouldn't that be EDIT: MIght also make more sense to switch the if statement around. #if UNITY_2022_1_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, Il2CppCompilerConfiguration.Debug);
PlayerSettings.SetIl2CppCodeGeneration(UnityEditor.Build.NamedBuildTarget.Android, UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize);
#elif UNITY_2020_3_OR_NEWER
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, Il2CppCompilerConfiguration.Debug);
EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize;
#endif |
Oh thank you! Sure It's UNITY_2022_1_OR_NEWER :) |
Because these changes actually reduce the performance of Unity, I would suggest having an extra menu option to build with these options. Otherwise, we are degrading the performance of people's apps as default and in an unexpected way. It would also be really easy to forget if you have manually changed these settings yourself. So in this menu: Instead of 'Export Android', there would be 'Export Android (release)' and 'Export Android (debug)' options - release just does the normal (slow, optimised) build and debug does the faster, unoptimised build. |
Yes! That's a better idea :) Will do that as soon as I've got time! |
With recent Unity versions (2020, 2021 and 2022) Flutter Android builds will take a lot longer, because it also has to compile the IL2CPP code from Unity.
From the Readme:
Here is some testing to check how to speed things up.
Unity settings
IL2CPP Code Generation
EditorUserBuildSettings.il2CppCodeGeneration = UnityEditor.Build.Il2CppCodeGeneration.OptimizeSize;
C++ compiler configuration
PlayerSettings.SetIl2CppCompilerConfiguration(BuildTargetGroup.Android, Il2CppCompilerConfiguration.Debug);
Disable script debugging
Don't bother setting this in the Unity settings, it will be overridden by the build script.
Assets/FlutterUnityIntegration/Editor/build.cs
In the function DoBuildAndroid() remove the line enabling script debugging.
playerOptions.options = BuildOptions.AllowDebugging;
This is the same as removing
commandLineArgs.add("--enable-debugger")
from the build.gradle file after an export.Measuring results
When you run a Flutter build, there are multiple IL2CPP stages that report their duration, with 2 sections taking far longer than all others.
We can compare these build durations when using different settings in Unity.
Log of the slow armv7 and arm64 sections
Results
The exact durations here aren't important, as this will be different of every computer and project setup.
This is after
flutter clean
and a fresh Unity export. Any subsequent runs will be faster because of caching.Flutter build apk
, with an export from Unity 2021.3.5f1 inandroid/unityLibrary
on Windows 10.Conclusion
My advice is to add this to the build script in
DoBuildAndroid()
for any test or debug builds, remove it for final release builds.If it doesn't affect your workflow, disable script debugging.
// playerOptions.options = BuildOptions.AllowDebugging;
And if you are developing on an arm64 device anyway, temporarily remove the armv7 build target from the Unity player settings.
The text was updated successfully, but these errors were encountered: