Exemplo n.º 1
0
        private void UploadAPK(bool retryUpload)
        {
            if (this.OnProgress != null)
            {
                this.OnProgress(this, "Copying APK package to device " + this._device.Describe());
            }
            string str = this._device.Install(this._installPath, null);

            if (!retryUpload && (str.Contains("[INSTALL_FAILED_UPDATE_INCOMPATIBLE]") || str.Contains("[INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]")))
            {
                Debug.LogWarning("Application update incompatible (signed with different keys?); removing previous installation (PlayerPrefs will be lost)...\n");
                if (this.OnProgress != null)
                {
                    this.OnProgress(this, "Removing " + this._packageName + " from device " + this._device.Describe());
                }
                this._device.Uninstall(this._packageName, null);
                this.UploadAPK(true);
            }
            else
            {
                if (((str.Contains("protocol failure") || str.Contains("No space left on device")) || (str.Contains("[INSTALL_FAILED_INSUFFICIENT_STORAGE]") || str.Contains("[INSTALL_FAILED_UPDATE_INCOMPATIBLE]"))) || ((str.Contains("[INSTALL_FAILED_MEDIA_UNAVAILABLE]") || str.Contains("[INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]")) || str.Contains("Failure [")))
                {
                    Debug.LogError("Installation failed with the following output:\n" + str);
                    CancelPostProcess.AbortBuildPointToConsole("Unable to install APK!", "Installation failed.");
                }
                bool flag = this._developmentPlayer || Unsupported.IsDeveloperBuild();
                if (this.OnProgress != null)
                {
                    this.OnProgress(this, "Setting device property CheckJNI to " + flag);
                }
                this._device.SetProperty("debug.checkjni", !flag ? "0" : "1", null);
            }
        }
Exemplo n.º 2
0
        private void UploadOBB()
        {
            string str  = $"{Path.GetFileNameWithoutExtension(this._installPath)}.main.obb";
            string path = Path.Combine(Path.GetDirectoryName(this._installPath), str);

            if (File.Exists(path))
            {
                if (this.OnProgress != null)
                {
                    this.OnProgress(this, "Copying APK Expansion file to device " + this._device.Describe());
                }
                int       bundleVersionCode = PlayerSettings.Android.bundleVersionCode;
                string[]  strArray          = new string[] { "/mnt/shell/emulated", "/mnt/shell/emulated/0/Android", this._device.ExternalStorageRoot + "/Android" };
                bool      flag      = false;
                Exception exception = null;
                string    str3      = $"main.{bundleVersionCode.ToString()}.{this._packageName}.obb";
                foreach (string str4 in strArray)
                {
                    try
                    {
                        string str5 = $"{str4}/{"obb"}/{this._packageName}/{str3}";
                        this._device.Push(path, str5, null);
                        flag = true;
                        break;
                    }
                    catch (Exception exception2)
                    {
                        exception = exception2;
                    }
                }
                string dst = $"{this._device.ExternalStorageRoot}/{str3}";
                if (!flag)
                {
                    try
                    {
                        this._device.Push(path, dst, null);
                        string str7        = $"{this._device.ExternalStorageRoot}/{"Android"}/{"obb"}/{this._packageName}";
                        string destination = $"{str7}/{str3}";
                        this._device.MakePath(str7, null);
                        this._device.Move(dst, destination, null);
                        flag = true;
                    }
                    catch (Exception exception3)
                    {
                        exception = exception3;
                    }
                }
                if (!flag)
                {
                    this.TryCleanupTemporaryOBB(dst);
                    Debug.LogException(exception);
                    CancelPostProcess.AbortBuildPointToConsole("Unable to deploy OBB to device", "Failed pushing OBB file to the device.");
                }
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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.");
            }
        }
Exemplo n.º 5
0
        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);
                }
            }
        }
Exemplo n.º 6
0
        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.");
            }
        }
Exemplo n.º 7
0
        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();
            }
        }
Exemplo n.º 8
0
        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.");
            }
        }