Esempio n. 1
0
        private string GetAssetsDir()
        {
            AndroidBuildFormat buildFormat = Factory.AGSEditor.CurrentGame.Settings.AndroidBuildFormat;
            bool destinationIsMainAssets   = buildFormat != AndroidBuildFormat.Aab;

            return(destinationIsMainAssets ? GetAssetEmbeddedDir() : GetAssetNonEmbeddedDir());
        }
Esempio n. 2
0
        private void ClearInvalidAssetDirIfNeeded()
        {
            AndroidBuildFormat buildFormat = Factory.AGSEditor.CurrentGame.Settings.AndroidBuildFormat;
            bool   clearEmbeddedDir        = buildFormat == AndroidBuildFormat.Aab;
            string dirToClear = clearEmbeddedDir ? GetAssetEmbeddedDir() : GetAssetNonEmbeddedDir();

            if (Directory.Exists(dirToClear) && Directory.GetFiles(dirToClear).Length != 0)
            {
                Directory.Delete(dirToClear, true);
                Directory.CreateDirectory(dirToClear);
            }
        }
Esempio n. 3
0
        public override bool Build(CompileMessages errors, bool forceRebuild)
        {
            if (!base.Build(errors, forceRebuild))
            {
                return(false);
            }

            UseGradleDaemon = Factory.AGSEditor.Settings.AndroidBuildGradleDaemon;
            string andProjDir = GetAndroidProjectInCompiledDir();

            if (!IsProjectSane(errors))
            {
                return(false);
            }

            InstallSdkToolsIfNeeded();

            AndroidBuildFormat buildFormat = Factory.AGSEditor.CurrentGame.Settings.AndroidBuildFormat;
            string             appName     = GetFinalAppName();

            string assetsDir = GetAssetsDir();

            if (!Directory.Exists(assetsDir))
            {
                Directory.CreateDirectory(assetsDir);
            }
            ClearInvalidAssetDirIfNeeded();

            foreach (string fileName in Directory.GetFiles(Path.Combine(AGSEditor.OUTPUT_DIRECTORY, AGSEditor.DATA_OUTPUT_DIRECTORY)))
            {
                if ((File.GetAttributes(fileName) & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.Temporary)) != 0)
                {
                    continue;
                }
                if ((!fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals("winsetup.exe", StringComparison.OrdinalIgnoreCase)) &&
                    (!Path.GetFileName(fileName).Equals(AGSEditor.CONFIG_FILE_NAME, StringComparison.OrdinalIgnoreCase)))
                {
                    string dest_filename = Path.Combine(assetsDir, Path.GetFileName(fileName));
                    Utilities.HardlinkOrCopy(dest_filename, fileName, true);
                }
            }

            // Update config file with current game parameters
            Factory.AGSEditor.WriteConfigFile(assetsDir);
            WriteAndroidCfg(assetsDir);

            foreach (KeyValuePair <string, string> pair in GetRequiredLibraryPaths())
            {
                string fileName  = pair.Key;
                string originDir = pair.Value;

                string dest = GetCompiledPath(ANDROID_DIR, Path.GetDirectoryName(fileName));

                if (!Directory.Exists(dest))
                {
                    // doesn't exist, let's create it
                    Directory.CreateDirectory(dest);
                }

                string destFile       = GetCompiledPath(ANDROID_DIR, fileName);
                string originFile     = Path.Combine(originDir, fileName);
                string destFileName   = Utilities.ResolveSourcePath(destFile);
                string sourceFileName = Utilities.ResolveSourcePath(originFile);

                if (fileName.EndsWith(".so"))
                {
                    Utilities.HardlinkOrCopy(destFile, originFile, true);
                }
                else
                {
                    File.Copy(sourceFileName, destFileName, true);
                }
            }

            string destDir = GetCompiledPath(ANDROID_DIR, "mygame");

            WriteProjectProperties(destDir);
            WriteLocalStaticProperties(destDir);
            WriteProjectXml(destDir);
            IconAssetType iconType = GetGameIconType();

            if (iconType != IconAssetType.NoIconFiles)
            {
                SetGameIcons(iconType, destDir);
            }

            GradleTasks gradleTask = GradleTasks.bundleRelease;

            if (buildFormat == AndroidBuildFormat.ApkEmbedded)
            {
                gradleTask = GradleTasks.assembleRelease;
            }

            if (!AndroidUtilities.RunGradlewTask(gradleTask, andProjDir, use_daemon: UseGradleDaemon))
            {
                errors.Add(new CompileError("There was an error running gradle to build the Android App."));
                return(false);
            }

            string appFinalFile     = GetFinalAppName();
            string appSrcDir        = GetOutputDir();
            string generatedAppFile = Path.Combine(appSrcDir, appFinalFile);

            if (File.Exists(generatedAppFile))
            {
                try
                {
                    Utilities.HardlinkOrCopy(GetCompiledPath(ANDROID_DIR, appFinalFile), generatedAppFile, true);
                }
                catch { }

                return(true);
            }

            errors.Add(new CompileError("Failed to generate Android App."));

            return(false);
        }