Ejemplo n.º 1
0
        public override void ExportWithCurrentSettings()
        {
            string str = Path.Combine(base.m_TargetPath, base.m_ProductName);

            AndroidProjectExport.CopyFile(base.m_UnityJavaLibrary, Path.Combine(Path.Combine(str, "libs"), "unity-classes.jar"));
            AndroidProjectExport.CopyFile(Path.Combine(base.m_UnityAndroidBuildTools, "UnityProGuardTemplate.txt"), Path.Combine(str, "proguard-unity.txt"));
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "res"), Path.Combine(str, "res"));
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "plugins"), Path.Combine(str, "libs"));
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "libs"), Path.Combine(str, "libs"));
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "aar"), Path.Combine(str, "libs"));
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "assets"), Path.Combine(str, "assets"));
            GenerateProjectProperties(str, base.m_PlatformApiLevel, base.m_AndroidLibraries);
            AndroidProjectExport.GenerateAndroidManifest(str, base.m_StagingArea, base.m_PackageName, true);
            AndroidProjectExport.CopyAndPatchJavaSources(Path.Combine(str, "src"), base.m_UnityJavaSources, base.m_PackageName);
            foreach (string str2 in base.m_AndroidLibraries)
            {
                AndroidProjectExport.CopyDir(str2, Path.Combine(base.m_TargetPath, Path.GetFileName(str2)));
            }
            if (base.m_UseObb)
            {
                AndroidProjectExport.CopyFile(Path.Combine(base.m_StagingArea, "main.obb"), Path.Combine(base.m_TargetPath, $"{base.m_ProductName}.main.obb"));
            }
            else
            {
                AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "raw"), Path.Combine(str, "assets"));
            }
        }
        public override void ExportWithCurrentSettings()
        {
            string str;
            bool   flag = false;

            if (base.m_TargetPath == null)
            {
                str  = Path.Combine("Temp", "gradleOut");
                flag = true;
                Directory.CreateDirectory(str);
                string[] strArray = AndroidFileLocator.Find(Path.Combine(str, "*"));
                foreach (string str2 in strArray)
                {
                    string fileName = Path.GetFileName(str2);
                    if ((fileName != "build") && (fileName != ".gradle"))
                    {
                        try
                        {
                            FileUtil.DeleteFileOrDirectory(str2);
                        }
                        catch (IOException)
                        {
                        }
                    }
                }
            }
            else
            {
                str = Path.Combine(base.m_TargetPath, base.m_ProductName);
            }
            int targetSDKVersion = base.m_TargetSDKVersion;
            Dictionary <string, string> templateValues = new Dictionary <string, string> {
                {
                    "BUILDTOOLS",
                    base.m_GoogleBuildTools.ToString()
                },
                {
                    "APIVERSION",
                    targetSDKVersion.ToString()
                },
                {
                    "TARGETSDKVERSION",
                    targetSDKVersion.ToString()
                }
            };

            string[] components = new string[] { str, "src", "main" };
            string   str4       = Paths.Combine(components);
            string   target     = Path.Combine(str, "libs");

            Directory.CreateDirectory(str);
            string sDKRootDir = AndroidSDKTools.GetInstance().SDKRootDir;
            string path       = Path.Combine(str, "local.properties");

            if (!File.Exists(path) || flag)
            {
                File.WriteAllText(path, $"sdk.dir={sDKRootDir.Replace(@"\", @"\\")}
");
            }
            AndroidProjectExport.CopyFile(base.m_UnityJavaLibrary, Path.Combine(Path.Combine(str, "libs"), "unity-classes.jar"));
            AndroidProjectExport.CopyFile(Path.Combine(base.m_UnityAndroidBuildTools, "UnityProGuardTemplate.txt"), Path.Combine(str, "proguard-unity.txt"));
            try
            {
                string[] textArray2 = new string[] { str4, "assets", "bin", "Data" };
                Directory.Delete(Paths.Combine(textArray2), true);
            }
            catch (IOException)
            {
            }
            try
            {
                Directory.Delete(Path.Combine(str4, "res"), true);
            }
            catch (IOException)
            {
            }
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "res"), Path.Combine(str4, "res"));
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "plugins"), target);
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "libs"), Path.Combine(str4, "jniLibs"));
            AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "assets"), Path.Combine(str4, "assets"));
            string[] strArray3 = AndroidFileLocator.Find(Path.Combine(Path.Combine(base.m_StagingArea, "aar"), "*.aar"));
            string   str9      = "";

            foreach (string str10 in strArray3)
            {
                string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(str10);
                string str12 = Path.GetFileName(str10);
                str9 = str9 + $"	compile(name: '{fileNameWithoutExtension}', ext:'aar')
";
                AndroidProjectExport.CopyFile(str10, Path.Combine(target, str12));
            }
            templateValues["DEPS"] = str9;
            if (flag)
            {
                AndroidProjectExport.CopyFile(Path.Combine(base.m_StagingArea, "AndroidManifest.xml"), Path.Combine(str4, "AndroidManifest.xml"));
            }
            else
            {
                AndroidProjectExport.GenerateAndroidManifest(str4, base.m_StagingArea, base.m_PackageName, false);
                AndroidProjectExport.CopyAndPatchJavaSources(Path.Combine(str4, "java"), base.m_UnityJavaSources, base.m_PackageName);
            }
            string str13 = Path.Combine(str, "build.gradle");

            if (File.Exists(str13) && !File.ReadAllText(str13).StartsWith("// GENERATED BY UNITY"))
            {
                str13 = Path.Combine(str, "build.gradle.NEW");
            }
            this.WriteGradleBuildFiles(str, str13, templateValues);
            if (base.m_UseObb)
            {
                AndroidProjectExport.CopyFile(Path.Combine(base.m_StagingArea, "main.obb"), Path.Combine(str, $"{base.m_ProductName}.main.obb"));
            }
            else
            {
                AndroidProjectExport.CopyDir(Path.Combine(base.m_StagingArea, "raw"), Path.Combine(str4, "assets"));
            }
        }