private void CheckUnityLibraryForArchitecture(PostProcessorContext context, string arch) { string[] components = new string[] { TasksCommon.GetVariationsDirectory(context), "Libs", arch, "libunity.so" }; string path = Paths.Combine(components); if (!File.Exists(path)) { CancelPostProcess.AbortBuild("Unable to package apk", "Unity library missing for the selected architecture '" + arch + " (" + path + ") !", null); } }
public void Execute(PostProcessorContext context) { string str = context.Get <string>("StagingArea"); if (this.OnProgress != null) { this.OnProgress(this, "Preparing and unpacking AAR plugins"); } string str2 = Path.Combine(str, "aar"); string path = Path.Combine(str, "android-libraries"); Directory.CreateDirectory(path); string[] strArray = AndroidFileLocator.Find(Path.Combine(str2, "*.aar")); foreach (string str4 in strArray) { string fileName = Path.GetFileName(str4); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(str4); string str7 = Path.Combine(path, fileNameWithoutExtension); if (Directory.Exists(str7)) { CancelPostProcess.AbortBuild("Build failure", "Plugin conflict detected for file " + fileName, null); } Directory.CreateDirectory(str7); TasksCommon.Exec(AndroidJavaTools.jarPath, "xf \"" + str4 + "\"", str7, "Error unpacking file " + fileName, 0); string str8 = Path.Combine(str7, "libs"); Directory.CreateDirectory(str8); FileUtil.MoveFileOrDirectory(Path.Combine(str7, "classes.jar"), Path.Combine(str8, "classes.jar")); string str9 = Path.Combine(str7, "jni"); if (Directory.Exists(str9)) { string str10 = Path.Combine(str7, "libs"); foreach (string str11 in Directory.GetDirectories(str9, "*")) { string to = Path.Combine(str10, FileUtil.RemovePathPrefix(str11, str9)); FileUtil.MoveFileOrDirectory(str11, to); } } string str13 = Path.Combine(str7, "src"); if (!Directory.Exists(str13)) { Directory.CreateDirectory(str13); } if (!File.Exists(Path.Combine(str7, AndroidLibraries.ProjectPropertiesFileName))) { int num3 = context.Get <int>("TargetSDKVersion"); File.WriteAllText(Path.Combine(str7, AndroidLibraries.ProjectPropertiesFileName), $"android.library=true target=android-{num3}"); } } }
private void AlignPackage(PostProcessorContext context) { AndroidSDKTools tools = context.Get <AndroidSDKTools>("SDKTools"); string errorMsg = "Failed to align APK package."; string str2 = Path.Combine(Environment.CurrentDirectory, this._stagingArea); string args = string.Format("4 \"{0}/Package_unaligned.apk\" \"{0}/Package.apk\"", str2); string message = TasksCommon.Exec(tools.ZIPALIGN, args, this._stagingArea, errorMsg, 0); if ((message.Contains("zipalign") || message.Contains("Warning")) || !File.Exists(Path.Combine(str2, "Package.apk"))) { Debug.LogError(message); CancelPostProcess.AbortBuildPointToConsole("APK Aligning Failed!", errorMsg); } }
private void BuildApk(PostProcessorContext context) { bool flag = context.Get <bool>("DevelopmentPlayer"); AndroidLibraries libraries = context.Get <AndroidLibraries>("AndroidLibraries"); bool flag2 = PlayerSettings.Android.keyaliasName.Length != 0; string str = Path.Combine(Environment.CurrentDirectory, this._stagingArea); string[] first = new string[] { "apk", $"{str}/Package_unaligned.apk", "-z", $"{str}/assets.ap_", "-z", $"{str}/bin/resources.ap_", "-nf", $"{str}/libs", "-f", $"{str}/bin/classes.dex", "-v" }; foreach (string str2 in libraries.GetLibraryDirectories()) { string[] second = new string[] { "-nf", str2 }; first = first.Concat <string>(second).ToArray <string>(); } foreach (string str3 in libraries.GetAssetsDirectories()) { string[] textArray3 = new string[] { "-A", str3 }; first = first.Concat <string>(textArray3).ToArray <string>(); } if (flag2) { string str4 = !Path.IsPathRooted(PlayerSettings.Android.keystoreName) ? Path.Combine(Directory.GetCurrentDirectory(), PlayerSettings.Android.keystoreName) : PlayerSettings.Android.keystoreName; string[] textArray4 = new string[] { "-k", str4, "-kp", PlayerSettings.Android.keystorePass, "-kk", PlayerSettings.Android.keyaliasName, "-kkp", PlayerSettings.Android.keyaliasPass }; first = first.Concat <string>(textArray4).ToArray <string>(); } if (flag || Unsupported.IsDeveloperBuild()) { string[] textArray5 = new string[] { "-d" }; first = first.Concat <string>(textArray5).ToArray <string>(); } if (File.Exists(Path.Combine(this._stagingArea, "raw.ap_"))) { string[] textArray6 = new string[] { "-z", $"{str}/raw.ap_" }; first = first.Concat <string>(textArray6).ToArray <string>(); } string message = TasksCommon.SDKTool(context, first, this._stagingArea, "Failed to build apk."); string fileName = Path.Combine(this._stagingArea, "Package_unaligned.apk"); FileInfo info = new FileInfo(fileName); if (!File.Exists(fileName) || (info.Length == 0L)) { Debug.LogError(message); CancelPostProcess.AbortBuildPointToConsole("APK Builder Failed!", "Failed to build APK package."); } }
private void CompileResources(PostProcessorContext context) { AndroidLibraries libraries = context.Get <AndroidLibraries>("AndroidLibraries"); string str = context.Get <string>("AndroidJarPath"); AndroidSDKTools tools = context.Get <AndroidSDKTools>("SDKTools"); string str2 = "gen"; string fullName = Directory.CreateDirectory(Path.Combine(this._stagingArea, str2)).FullName; string args = $"package --auto-add-overlay -v -f -m -J " { str2 } " -M " { "AndroidManifest.xml" } " -S " { "res" } " -I " { str } " -F {" bin / resources.ap_ "}"; if (libraries.Count > 0) { args = args + $" --extra-packages {string.Join(":", libraries.GetPackageNames())}"; foreach (string str5 in libraries.GetResourceDirectories()) { args = args + $" -S " { str5 } ""; } } string errorMsg = "Failed to re-package resources."; string str7 = TasksCommon.Exec(tools.AAPT, args, this._stagingArea, errorMsg, 3); if (!str7.Contains("Done!") || !File.Exists(Path.Combine(this._stagingArea, "bin/resources.ap_"))) { Debug.LogError("Failed to re-package resources with the following parameters:\n" + args + "\n" + str7); CancelPostProcess.AbortBuildPointToConsole("Resource re-package failed!", errorMsg); } if (libraries.Count > 0) { List <string> list = new List <string>(); foreach (string str8 in Directory.GetFiles(fullName, "*.java", SearchOption.AllDirectories)) { list.Add(str8.Substring(fullName.Length + 1)); } string str9 = Directory.CreateDirectory(Path.Combine(this._stagingArea, "bin/classes")).FullName; string str10 = $"-bootclasspath " { str } " -d " { str9 } " -source 1.6 -target 1.6 -encoding UTF-8 " { string.Join("\" \"", list.ToArray()) } ""; string str11 = "Failed to recompile android resource files."; string str12 = TasksCommon.Exec(AndroidJavaTools.javacPath, str10, fullName, str11, 0); if (str12.Trim().Length > 0) { Debug.LogError("Failed to compile resources with the following parameters:\n" + str10 + "\n" + str12); CancelPostProcess.AbortBuildPointToConsole("Resource compilation failed!", str11); } } }
private void AAPTPack(PostProcessorContext context, string apkName, string directory, bool compress) { AndroidSDKTools tools = context.Get <AndroidSDKTools>("SDKTools"); string str = ""; if (!compress) { str = " -0 \"\""; } string str2 = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"; string args = $"package -v -f -F {apkName} -A {directory}{str} --ignore-assets " { str2 } ""; string str4 = TasksCommon.Exec(tools.AAPT, args, this._stagingArea, "Android Asset Packaging Tool failed.", 3); if (!str4.Contains("Found 0 custom asset files") && (!str4.Contains("Done!") || !File.Exists(Path.Combine(this._stagingArea, apkName)))) { Debug.LogError($"Android Asset Packaging Tool failed: {tools.AAPT} {args} {str4}"); CancelPostProcess.AbortBuildPointToConsole("AAPT Failed!", "Android Asset Packaging Tool failed."); } }
public void Execute(PostProcessorContext context) { this._stagingArea = context.Get <string>("StagingArea"); this._androidLibraries = context.Get <AndroidLibraries>("AndroidLibraries"); bool flag = context.Get <bool>("HasJarPlugins"); bool flag2 = context.Get <bool>("ExportAndroidProject"); if (this.OnProgress != null) { this.OnProgress(this, "Converting Java classes to dex-format"); } if (!flag2 && (flag || (this._androidLibraries.Count > 0))) { this.BuildDex(context); } else { string[] components = new string[] { TasksCommon.GetClassDirectory(context), "classes.dex" }; string[] textArray2 = new string[] { this._stagingArea, "bin", "classes.dex" }; FileUtil.CopyFileOrDirectory(Paths.Combine(components), Paths.Combine(textArray2)); } }
private void PrepareNativeUnityLibs(PostProcessorContext context, string abi) { string pluginSourceFolder = context.Get <string>("AndroidPluginsPath"); string[] components = new string[] { this._stagingArea, "libs", abi }; string to = Paths.Combine(components); string[] textArray2 = new string[] { TasksCommon.GetVariationsDirectory(context), "Libs" }; string str3 = Paths.Combine(textArray2); string[] textArray3 = new string[] { this._stagingArea, "libs" }; Directory.CreateDirectory(Paths.Combine(textArray3)); string[] textArray4 = new string[] { str3, abi }; FileUtil.CopyFileOrDirectory(Paths.Combine(textArray4), to); string[] textArray5 = new string[] { pluginSourceFolder, "libs", abi }; string str4 = Paths.Combine(textArray5); string[] textArray6 = new string[] { to, "gdbserver" }; if (!File.Exists(Paths.Combine(textArray6)) && !PostprocessBuildPlayer.InstallPluginsByExtension(pluginSourceFolder, "gdbserver", string.Empty, to, false)) { PostprocessBuildPlayer.InstallPluginsByExtension(str4, "gdbserver", string.Empty, to, false); } }
private void BuildObb(PostProcessorContext context) { bool flag = File.Exists(Path.Combine(this._stagingArea, "obb.ap_")); bool flag2 = File.Exists(Path.Combine(this._stagingArea, "rawobb.ap_")); if (flag || flag2) { string str = Path.Combine(Environment.CurrentDirectory, this._stagingArea); string[] first = new string[] { "apk", $"{str}/main.obb", "-u" }; if (flag) { string[] second = new string[] { "-z", $"{str}/obb.ap_" }; first = first.Concat <string>(second).ToArray <string>(); } if (flag2) { string[] textArray3 = new string[] { "-z", $"{str}/rawobb.ap_" }; first = first.Concat <string>(textArray3).ToArray <string>(); } string message = TasksCommon.SDKTool(context, first, this._stagingArea, "Failed to build OBB."); string fileName = Path.Combine(this._stagingArea, "main.obb"); FileInfo info = new FileInfo(fileName); if (!File.Exists(fileName) || (info.Length == 0L)) { Debug.LogError(message); CancelPostProcess.AbortBuildPointToConsole("OBB Builder Failed!", "Failed to build OBB package."); } if (info.Length >= 0x80000000L) { Debug.LogError(message); CancelPostProcess.AbortBuildPointToConsole("OBB Builder Failed!", "OBB file too big for Android Market (max 2GB)."); } AndroidXmlDocument document = context.Get <AndroidXmlDocument>("SettingsXml"); document.PatchStringRes("bool", TasksCommon.GetMD5HashOfEOCD(fileName), true.ToString()); document.Save(); } }
private void BuildDex(PostProcessorContext context) { string[] components = new string[] { TasksCommon.GetClassDirectory(context), "classes.jar" }; string[] textArray2 = new string[] { this._stagingArea, "bin", "classes.jar" }; FileUtil.CopyFileOrDirectory(Paths.Combine(components), Paths.Combine(textArray2)); string[] array = new string[] { "dx", "--dex", "--verbose", "--output=bin/classes.dex", "bin/classes.jar" }; if (Directory.Exists(Path.Combine(this._stagingArea, "bin/classes"))) { ArrayUtility.Add <string>(ref array, "bin/classes"); } if (Directory.Exists(Path.Combine(this._stagingArea, "plugins"))) { ArrayUtility.Add <string>(ref array, "plugins"); } foreach (string str in this._androidLibraries.GetLibraryDirectories()) { ArrayUtility.Add <string>(ref array, str); } foreach (string str2 in this._androidLibraries.GetCompiledJarFiles()) { ArrayUtility.Add <string>(ref array, str2); } TasksCommon.SDKTool(context, array, this._stagingArea, "Unable to convert classes into dex format."); }
private void CreatePackagesWithFastzip(PostProcessorContext context) { string str5; string str6; string str7; FileInfo info; string workingdir = context.Get <string>("StagingArea"); bool flag = context.Get <bool>("UseObb"); AndroidLibraries libraries = context.Get <AndroidLibraries>("AndroidLibraries"); AndroidXmlDocument document = context.Get <AndroidXmlDocument>("SettingsXml"); string command = context.Get <string>("FastzipExe"); string str3 = "Package.apk"; string errorMsg = "Fastzip failed."; string str8 = " -j --seq -5"; if (flag) { if (this.OnProgress != null) { this.OnProgress(this, "Using fastzip to build expansion package (OBB)"); } str6 = ("main.obb" + str8 + " obbassets=assets") + " rawobb=assets"; str5 = TasksCommon.Exec(command, str6, workingdir, errorMsg, 0); str7 = Path.Combine(workingdir, "main.obb"); info = new FileInfo(str7); if (!File.Exists(str7) || (info.Length == 0L)) { Debug.LogError(str5); CancelPostProcess.AbortBuildPointToConsole("OBB Builder Failed!", "Failed to build OBB package."); } if (info.Length >= 0x80000000L) { Debug.LogError(str5); CancelPostProcess.AbortBuildPointToConsole("OBB Builder Failed!", "OBB file too big for Android Market (max 2GB)."); } document.PatchStringRes("bool", TasksCommon.GetMD5HashOfEOCD(str7), true.ToString()); document.Save(); } if (this.OnProgress != null) { this.OnProgress(this, "Using fastzip to build target package (APK)"); } string str9 = " libs=lib"; foreach (string str10 in libraries.GetLibraryDirectories()) { str9 = str9 + $" {str10}=libs"; } string str11 = " --apk"; if (PlayerSettings.Android.keyaliasName.Length != 0) { string str12 = !Path.IsPathRooted(PlayerSettings.Android.keystoreName) ? Path.Combine(Directory.GetCurrentDirectory(), PlayerSettings.Android.keystoreName) : PlayerSettings.Android.keystoreName; str11 = $" -A --sign={str12},{PlayerSettings.Android.keyaliasPass},{PlayerSettings.Android.keyaliasName}"; } string[] textArray1 = new string[] { str3, str8, str11, str9, " bin/classes.dex assets -0 -Z bin/resources.ap_ raw=assets" }; str6 = string.Concat(textArray1); str5 = TasksCommon.Exec(command, str6, workingdir, errorMsg, 0); str7 = Path.Combine(workingdir, str3); info = new FileInfo(str7); if (!File.Exists(str7) || (info.Length == 0L)) { Debug.LogError(str5); CancelPostProcess.AbortBuildPointToConsole("Fastzip Failed!", "Failed to build APK package."); } }