启用以缩小发布版本。
启用以在发布配置中缩小您的 Java 代码。使用 Proguard 配置文件来控制此过程。注意:缩小有时会删除需要的代码并生成无法正常工作的二进制文件。
using UnityEditor; using UnityEditor.Build; using UnityEngine;
public class MinifyReleaseExample : MonoBehaviour { [MenuItem("Build/Android Minify Release Example")] public static void MinifyRelease() { PlayerSettings.SetScriptingBackend(NamedBuildTarget.Android, ScriptingImplementation.IL2CPP); PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARM64;
//Enable minify release PlayerSettings.Android.minifyRelease = true;
BuildPlayerOptions options = new BuildPlayerOptions(); options.scenes = new[] { "Assets/Scenes/SampleScene.unity" }; options.locationPathName = "Builds/AndroidBuild.apk"; options.target = BuildTarget.Android; options.targetGroup = BuildTargetGroup.Android;
BuildPipeline.BuildPlayer(options); } }