public static void CopyAndroidIL2CPPSymbols(string pathToBuiltProject, AndroidTargetDevice targetDevice) { string buildName = Path.GetFileNameWithoutExtension(pathToBuiltProject); FileInfo fileInfo = new FileInfo(pathToBuiltProject); string symbolsDir = fileInfo.Directory.Name; symbolsDir = symbolsDir + "/" + buildName + "_IL2CPPSymbols"; CreateDir(symbolsDir); switch (PlayerSettings.Android.targetDevice) { case AndroidTargetDevice.FAT: { CopyARMSymbols(symbolsDir); CopyX86Symbols(symbolsDir); break; } case AndroidTargetDevice.ARMv7: { CopyARMSymbols(symbolsDir); break; } case AndroidTargetDevice.x86: { CopyX86Symbols(symbolsDir); break; } default: break; } }
public void Execute(PostProcessorContext context) { if (this.OnProgress != null) { this.OnProgress(this, "Copying unity libraries"); } this._stagingArea = context.Get <string>("StagingArea"); this._playerPackage = context.Get <string>("PlayerPackage"); AndroidTargetDevice device = context.Get <AndroidTargetDevice>("TargetDevice"); switch (device) { case AndroidTargetDevice.FAT: case AndroidTargetDevice.ARMv7: this.PrepareNativeUnityLibs(context, "armeabi-v7a"); break; } if ((device == AndroidTargetDevice.FAT) || (device == AndroidTargetDevice.x86)) { this.PrepareNativeUnityLibs(context, "x86"); } string[] components = new string[] { this._playerPackage, "Apk", "assets" }; FileUtil.CopyDirectoryRecursive(Paths.Combine(components), Path.Combine(this._stagingArea, "assets"), true); string[] textArray2 = new string[] { this._playerPackage, "Apk", "res" }; FileUtil.CopyDirectoryRecursive(Paths.Combine(textArray2), Path.Combine(this._stagingArea, "res"), true); }
public static void BuildAndroid(AndroidTargetDevice target, BuildOptions options = BuildOptions.None) { Debug.LogFormat("Building for android, target: {0}, options: {1}", target, options); Directory.CreateDirectory(AndroidLocation); if (!UpdateKeystoreData()) { Debug.LogError("Couldn't complete build"); return; } // https://developer.android.com/google/play/publishing/multiple-apks.html // Using a version code scheme var version = new Version(PlayerSettings.bundleVersion); string bundleString = String.Format("{0}{1:00}{2:00}{3:00}", version.Major, version.Minor, version.Build, (int)target); int bundle = Convert.ToInt32(bundleString); PlayerSettings.Android.bundleVersionCode = bundle; PlayerSettings.Android.targetDevice = target; string file = string.Format("{0}_{1}.apk", GameName, target); string fullName = Path.Combine(AndroidLocation, file); BuildPipeline.BuildPlayer(GetScenes(), fullName, BuildTarget.Android, options); Debug.Log("Build completed"); }
/// <summary> /// Build project for Android with specified AndroidTargetDevice. /// This function change PlayerSettings and restore it after build. /// Different devices will get different bundle version code. /// See: <see cref="BuildHelperStrings.GenBundleNumber(UnityEditor.AndroidTargetDevice)"/> /// </summary> /// <param name="device">Android target device</param> /// <param name="buildVersion">Build version wich will be available by <i>Application.version</i></param> /// <param name="options">Build player options</param> /// <returns>Build path</returns> private static string BuildAndroidForDevice(AndroidTargetDevice device, string buildVersion, BuildPlayerOptions options) { BuildTime.SaveSettingsToRestore(); PlayerSettings.Android.targetDevice = device; PlayerSettings.Android.bundleVersionCode = BuildHelperStrings.GenBundleNumber(device); var buildPath = BuildHelperStrings.GetBuildPath(BuildTarget.Android, buildVersion, specifyName: device.ToString()); options.locationPathName = buildPath; BuildTime.Build(options); return(buildPath); }
public void Execute(PostProcessorContext context) { if (((ScriptingImplementation)context.Get <ScriptingImplementation>("ScriptingBackend")) == ScriptingImplementation.IL2CPP) { if (this.OnProgress != null) { this.OnProgress(this, "Generating native assemblies"); } BuildTarget target = context.Get <BuildTarget>("BuildTarget"); string str = context.Get <string>("StagingArea"); string[] components = new string[] { str, "assets", "bin", "Data" }; string stagingAreaData = Paths.Combine(components); string[] textArray2 = new string[] { BuildPipeline.GetBuildToolsDirectory(target), "AndroidNativeLink.xml" }; string[] textArray3 = new string[] { stagingAreaData, "platform_native_link.xml" }; FileUtil.CopyFileOrDirectory(Paths.Combine(textArray2), Paths.Combine(textArray3)); AndroidTargetDevice device = context.Get <AndroidTargetDevice>("TargetDevice"); AndroidTargetDeviceType deviceType = new AndroidTargetDeviceARMv7(); if (device == AndroidTargetDevice.x86) { deviceType = new AndroidTargetDevicex86(); } if (this.OnProgress != null) { this.OnProgress(this, "Compiling native assemblies for " + deviceType.Architecture); } string tempFolder = Path.Combine(str, "Il2Cpp"); bool isDevelopmentBuild = context.Get <bool>("DevelopmentPlayer"); RuntimeClassRegistry runtimeClassRegistry = context.Get <RuntimeClassRegistry>("UsedClassRegistry"); AndroidIl2CppPlatformProvider platformProvider = new AndroidIl2CppPlatformProvider(target, deviceType, isDevelopmentBuild); IL2CPPUtils.RunIl2Cpp(tempFolder, stagingAreaData, platformProvider, null, runtimeClassRegistry, isDevelopmentBuild); AndroidTargetDeviceType type2 = null; if (device == AndroidTargetDevice.FAT) { type2 = new AndroidTargetDevicex86(); if (this.OnProgress != null) { this.OnProgress(this, "Compiling native assemblies for " + type2.Architecture); } platformProvider = new AndroidIl2CppPlatformProvider(target, type2, isDevelopmentBuild); IL2CPPUtils.RunCompileAndLink(tempFolder, stagingAreaData, platformProvider, null, runtimeClassRegistry, false); } this.FinalizeAndCleanup(str, stagingAreaData, tempFolder); this.CopySymbolMap(str, stagingAreaData, deviceType); if (type2 != null) { this.CopySymbolMap(str, stagingAreaData, type2); } } }
private void EnsureUnityLibrariesAreAvailable(PostProcessorContext context) { AndroidTargetDevice device = context.Get <AndroidTargetDevice>("TargetDevice"); switch (device) { case AndroidTargetDevice.FAT: case AndroidTargetDevice.ARMv7: this.CheckUnityLibraryForArchitecture(context, "armeabi-v7a"); break; } if ((device == AndroidTargetDevice.FAT) || (device == AndroidTargetDevice.x86)) { this.CheckUnityLibraryForArchitecture(context, "x86"); } }
private static void SetupContextForPreBuild(PostProcessorContext context, BuildOptions options, BuildTarget target) { context.Set <BuildTarget>("BuildTarget", target); bool flag = (options & BuildOptions.Development) != BuildOptions.CompressTextures; context.Set <bool>("DevelopmentPlayer", flag); bool flag2 = (options & BuildOptions.AcceptExternalModificationsToPlayer) != BuildOptions.CompressTextures; context.Set <bool>("ExportAndroidProject", flag2); bool flag3 = (options & BuildOptions.AutoRunPlayer) != BuildOptions.CompressTextures; context.Set <bool>("AutoRunPlayer", flag3); AndroidTargetDevice targetDevice = PlayerSettings.Android.targetDevice; context.Set <AndroidTargetDevice>("TargetDevice", targetDevice); string playbackEngineDirectory = BuildPipeline.GetPlaybackEngineDirectory(target, options); context.Set <string>("PlayerPackage", playbackEngineDirectory); ScriptingImplementation scriptingBackend = PlayerSettings.GetScriptingBackend(BuildPipeline.GetBuildTargetGroup(target)); context.Set <ScriptingImplementation>("ScriptingBackend", scriptingBackend); }
private void PrepareNativePlugin(PostProcessorContext context, string assetPath, string pluginTargetCPU) { string[] textArray1; string str; AndroidTargetDevice device = context.Get <AndroidTargetDevice>("TargetDevice"); if ((device == AndroidTargetDevice.FAT) || device.ToString().Equals(pluginTargetCPU)) { str = ""; if (pluginTargetCPU != null) { if (pluginTargetCPU != "ARMv7") { if (pluginTargetCPU == "x86") { str = "x86"; goto Label_0088; } } else { str = "armeabi-v7a"; goto Label_0088; } } Debug.LogWarning($"Unknown cpu architecture for .so library ({assetPath})"); } return; Label_0088: textArray1 = new string[] { this._stagingArea, "libs", str }; string path = Paths.Combine(textArray1); Directory.CreateDirectory(path); FileUtil.UnityFileCopy(assetPath, Path.Combine(path, Path.GetFileName(assetPath))); }
/// <summary> /// Generate bundle number of build for Android.<br/> /// Format: <![CDATA[<revision><branchId><targetId>]]><br/> /// Where <i>revision</i> - parsed number from <see cref="GitRequest.Revision"/>; /// <i>branchId</i> - 0 if current branch is equal to <see cref="RELEASE_BRANCH"/>, otherwise 1; /// <i>targetId</i> - number equivalent of <i>targetDevice</i>.<br/> /// Example return: "23403" - revision is 234, release branch, Android target - ARMv7. /// </summary> /// <param name="targetDevice">Android target device</param> /// <returns>Generated bundle number</returns> public static int GenBundleNumber(AndroidTargetDevice targetDevice) { return(GenBundleNumber((int)targetDevice)); }
private AndroidDevice FindDevice(PostProcessorContext context) { BuildTarget platform = context.Get <BuildTarget>("BuildTarget"); AndroidTargetDevice targetDevice = PlayerSettings.Android.targetDevice; List <string> list = null; do { list = ADB.Devices(null); }while ((list.Count == 0) && EditorUtility.DisplayDialog("No Android device found!", " * Make sure USB debugging has been enabled\n * Check your device, in most cases there should be a small icon in the status bar telling you if the USB connection is up.\n * If you are sure that device is attached then it might be USB driver problem, for details please check Android SDK Setup section in Unity manual.", "Retry", "Cancel")); if (list.Count < 1) { string message = $"No Android devices found.{(Application.platform != RuntimePlatform.WindowsEditor) ? "" : " If you are sure that device is attached then it might be USB driver problem, for details please check Android SDK Setup section in Unity manual."} "; CancelPostProcess.AbortBuild("Couldn't find Android device", message, null); } AndroidDevice device2 = new AndroidDevice(list[0]); int num = Convert.ToInt32(device2.Properties["ro.build.version.sdk"]); if (num < 9) { string str2 = (("Device: " + device2.Describe() + "\n") + "The connected device is not running Android OS 2.3 or later.") + " Unity Android does not support earlier versions of the Android OS;" + " please upgrade your device to a later OS version."; Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings"); CancelPostProcess.AbortBuild("Device software is not supported", str2, null); } int num2 = 0; try { num2 = Convert.ToInt32(device2.Properties["ro.opengles.version"]); } catch (FormatException) { num2 = -1; } int num3 = 0xf0000; GraphicsDeviceType[] graphicsAPIs = PlayerSettings.GetGraphicsAPIs(platform); if (graphicsAPIs.Contains <GraphicsDeviceType>(GraphicsDeviceType.OpenGLES3)) { num3 = 0x30000; } if (graphicsAPIs.Contains <GraphicsDeviceType>(GraphicsDeviceType.OpenGLES2)) { num3 = 0x20000; } bool flag = device2.Features.Contains("android.hardware.opengles.aep"); if ((num3 == 0x30000) && (PlayerSettings.openGLRequireES31 || PlayerSettings.openGLRequireES31AEP)) { num3 = 0x30001; } bool flag2 = true; bool flag3 = (graphicsAPIs.Length == 1) && (graphicsAPIs[0] == GraphicsDeviceType.Vulkan); if ("Amazon" != device2.Properties["ro.product.brand"]) { string str3 = null; if (flag3 && !flag2) { str3 = "The connected device does not support Vulkan."; str3 = str3 + " Please select OpenGLES under Player Settings instead."; } if (((num2 >= 0) && (num2 < num3)) || (PlayerSettings.openGLRequireES31AEP && !flag)) { str3 = "The connected device is not compatible with the selected OpenGLES version."; str3 = str3 + " Please select a lower OpenGLES version under Player Settings instead."; } if (str3 != null) { Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings"); CancelPostProcess.AbortBuild("Device hardware is not supported", str3, null); } } if ((targetDevice == AndroidTargetDevice.x86) && device2.Properties["ro.product.cpu.abi"].Equals("armeabi-v7a")) { string str4 = "You are trying to install x86 APK to ARM device. "; str4 = str4 + "Please select FAT or ARM as device filter under Player Settings, or connect a x86 device."; Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings"); CancelPostProcess.AbortBuild("Device hardware is not supported", str4, null); } string str5 = device2.Properties["ro.product.manufacturer"]; string str6 = device2.Properties["ro.product.model"]; string action = device2.Properties["ro.product.cpu.abi"]; bool flag4 = device2.Properties["ro.secure"].Equals("1"); string str8 = $"{char.ToUpper(str5[0])}{str5.Substring(1)} {str6}"; string label = $"Android API-{num}"; UsabilityAnalytics.Event("Android Device", str8, label, !flag4 ? 0 : 1); string str10 = $"gles {num2 >> 0x10}.{num2 & 0xffff}{!flag ? "" : " AEP"}"; if (num2 < 0) { str10 = "gles 2.0"; } UsabilityAnalytics.Event("Android Architecture", action, str10, 1); string str11 = device2.Properties["ro.board.platform"]; ulong i = device2.MemInfo["MemTotal"]; i = UpperboundPowerOf2(i) / ((ulong)0x100000L); UsabilityAnalytics.Event("Android Chipset", str11, $"{i}MB", 1); return(device2); }
internal static void ApplySettings(AndroidTargetDevice targetDevice = AndroidTargetDevice.FAT) { PlayerSettings.Android.targetDevice = targetDevice; }