コード例 #1
0
        public static void SetKeystoreToProject(EclipseProject project)
        {
            string keystore = PlayerSettings.Android.keystoreName;

            if (string.IsNullOrEmpty(keystore))
            {
                return;
            }
            FileInfo fi = new FileInfo(keystore);

            if (!fi.Exists)
            {
                throw new Exception("keysotre '" + fi.FullName + "' not exsits!");
            }
            DirectoryInfo di = new DirectoryInfo(project.Path + "/nativebuilder/keystore");

            if (!di.Exists)
            {
                di.Create();
            }
            fi.CopyTo(di.FullName + "/" + fi.Name);
            var keystore_path = "./nativebuilder/keystore/" + fi.Name;
            var keystore_pass = PlayerSettings.Android.keystorePass;
            var keyalis_name  = PlayerSettings.Android.keyaliasName;
            var keyalis_pass  = PlayerSettings.Android.keyaliasPass;

            project.SetKeystore(keystore_path, keystore_pass, keyalis_name, keyalis_pass);
        }
コード例 #2
0
        public static string BuildAPK(string projectPath, ProcessHandller process = null)
        {
            if (process == null)
            {
                process = (percent, title, verbos) => {};
            }
            UnityEngine.Debug.Log(" -> BuildAPK...");

            //----------------------------------------------------------
            //Detect Paths
            //----------------------------------------------------------
            process(0.1f, "Detect paths", "detect Android project path...");
            var project = new EclipseProject(projectPath);            //new EclipseProject(BaseProjectPath + "/" + gameProjectName);

            process(0.1f, "Detect path", "detect tools path...");
            var local       = Configuration.Local;
            var android_sdk = local["android.sdk"];
            var ant_sdk     = local["ant.sdk"];

            process(0.1f, "Detect path", "detect target apk path...");
            var conf        = Configuration.Gloable;
            var target_path = conf["android.apk"];

            // log
            UnityEngine.Debug.Log("android sdk: " + android_sdk);
            UnityEngine.Debug.Log("ant: " + ant_sdk);
            UnityEngine.Debug.Log("apk target: " + target_path);
            //----------------------------------------------------------
            //excute command
            //----------------------------------------------------------
            process(0.2f, "Build Apk", "excute android update...");
            project.Antlize(android_sdk);

            process(0.3f, "Build Apk", "excute android clean...");
            Ant.ant_clean(project.Path, ant_sdk);

            process(0.4f, "Build Apk", "detect Ant mod...");
            var antMod = DecideAntMod(project);

            if (antMod == AntMod.Debug)
            {
                process(0.4f, "Build Apk", "excute ant debug...");
                Ant.ant_debug(project.Path, ant_sdk);
            }
            else if (antMod == AntMod.Release)
            {
                //process(0.4f, "Build Apk", "set keystore to Anroid project...");
                //SetKeystoreToProject(project);

                process(0.45f, "Build Apk", "execute ant release...");
                Ant.ant_release(project.Path, ant_sdk);
            }

            process(0.95f, "Build Apk", "copy apk...");
            var f = Android.FindAntBuiltAPK(project.Path, antMod);

            f.CopyTo(target_path, true);
            return(target_path);
        }
コード例 #3
0
        public static void SetKeystoreToProject(EclipseProject project, string key_store_path)
        {
            var keystore_path = key_store_path;
            var keystore_pass = "******";
            var keyalis_name  = "androiddebugkey";
            var keyalis_pass  = "******";

            project.SetKeystore(keystore_path, keystore_pass, keyalis_name, keyalis_pass);
        }
コード例 #4
0
        public static AntMod DecideAntMod(EclipseProject project)
        {
            //string keystore = PlayerSettings.Android.keyaliasName;
            //return string.IsNullOrEmpty(keystore) ? AntMod.Debug : AntMod.Release;

            if (project.KeystoreExists)
            {
                return(AntMod.Release);
            }
            return(AntMod.Debug);
        }
コード例 #5
0
        //build Eclipse Project
        public override void OnBuild()
        {
            string solutionPath = global["android.project"];

            // Build Android Project
            if (ShouldDoTask(TaskList.BuildAndroidProject))
            {
                Process(5, "Build Android Project", "");


                //mod file path
                var task_buildAndroidProject = new ReportableTask();
                task_buildAndroidProject.name            = "Build Android Studio Project";
                task_buildAndroidProject.processHandller = OnExportReport;
                task_buildAndroidProject.action          = (process) => {
                    //check parent dir
                    process(0.1f, "Export Android Studio Project", "ensure dirs...");
                    {
                        var di = new DirectoryInfo(solutionPath).Parent;
                        if (!di.Exists)
                        {
                            di.Create();
                        }
                    }

                    //if target Path exits, delete it!
                    if (Directory.Exists(solutionPath))
                    {
                        DirectoryInfo dir = new DirectoryInfo(solutionPath);
                        dir.Delete(true);
                    }

                    if (!this.UseBackup)
                    {
                        // build eclipse project
                        process(0.15f, "Export Android Project", "call unity to export android project...");
                        UnityEngine.Debug.Log("Unity building eclipse project...");
                        NativeBuilderUtility.Build(solutionPath, UnityEditor.BuildTarget.Android, UnityEditor.BuildOptions.AcceptExternalModificationsToPlayer);

                        // change project name

                        /*
                         *                      DirectoryInfo projectDir = new DirectoryInfo(EclipsePath);
                         *                      DirectoryInfo[] childrenDir = projectDir.GetDirectories();
                         *                      if(childrenDir.Length != 1)
                         *                      {
                         *                              throw new Exception("multi child directories be found under the project!");
                         *                      }
                         *                      string oldGameName = childrenDir[0].Name;
                         */
                        // rename project dir
                        string oldGameName = PlayerSettings.productName;
                        string newGamename = "Game";
                        string source      = Path.Combine(solutionPath, oldGameName);
                        string dest        = Path.Combine(solutionPath, newGamename);
                        Directory.Move(source, dest);

                        // rename obb
                        string ObbPath = solutionPath + "/" + PlayerSettings.productName + ".main.obb";
                        if (File.Exists(ObbPath))
                        {
                            string targetObbPath = solutionPath + "/" + "main." + PlayerSettings.Android.bundleVersionCode + "." + PlayerSettings.applicationIdentifier + ".obb";
                            File.Move(ObbPath, targetObbPath);
                        }

                        // write info
                        EclipseProject project = new EclipseProject(solutionPath + "/Game");
                        project.BuildTime = this.startTime.ToString();


                        // backup pure eclips project
                        PShellUtil.CopyTo(solutionPath, Configuration.Gloable.Eclipse_Project_Backup_Home + "/autosave", PShellUtil.FileExsitsOption.Override, PShellUtil.DirectoryExsitsOption.Override);
                    }
                    else if (this.UseBackup)
                    {
                        PShellUtil.CopyTo(Path.Combine(Configuration.Gloable.Eclipse_Project_Backup_Home, this.BackupName), solutionPath, PShellUtil.FileExsitsOption.Override, PShellUtil.DirectoryExsitsOption.Override);
                    }
                };
                task_buildAndroidProject.Run();

                UnityEngine.Debug.Log("Build AndroidStudio Project success, Release At [" + solutionPath + "].");
            }

            /*
             *          // Apply NativeBuilder
             *          if(ShouldDoTask(TaskList.ApplyNativeBuilder))
             *          {
             *                  Process(0.8f, "Apply NativeBuilder Conf", "apply eupe...");
             *                  ELProject project = new ELProject (solutionPath + "/Game");
             *                  EUPE.ModEclipseProject(project, mod);
             *          }
             *
             *          // Build Apk
             *          if(ShouldDoTask(TaskList.BuildApk))
             *          {
             *                  Process(15, "Build APK", "");
             *                  this.apkPath = NativeBuilderUtility.BuildAPK(solutionPath + "/Game", OnApkBuildReport);
             *                  string target_dir = solutionPath + "/../TargetAndroid";
             *                  string appName = PlayerSettings.productName +"_"+PlayerSettings.bundleVersion+"_"+System.DateTime.Now.ToString("MMdd_HHmm")+".apk";
             *                  string target_path = target_dir+"/"+ appName;
             *                  if (Directory.Exists(target_dir))
             *                  {
             *                          Directory.Delete(target_dir,true);
             *                  }
             *                  Directory.CreateDirectory(target_dir);
             *                  File.Move(this.apkPath,target_path);
             *                  this.apkPath = target_path;
             *                  //main.42.tw.mobage.g22000016.obb
             *                  string thisObbPath = solutionPath+"/"+PlayerSettings.productName+".main.obb";
             *                  if(File.Exists(thisObbPath))
             *                  {
             *
             *                          string targetObbPath = target_dir+"/"+"main."+PlayerSettings.Android.bundleVersionCode+"."+PlayerSettings.applicationIdentifier+".obb";
             *                          File.Move(thisObbPath,targetObbPath);
             *                  }
             *
             *                  UnityEngine.Debug.Log("Build Apk success, Release At [" + apkPath + "].");
             *          }
             *
             *          // Run Apk
             *          if(ShouldDoTask(TaskList.RunApk))
             *          {
             *                  NativeBuilderUtility.RunAPK(this.apkPath, PlayerSettings.applicationIdentifier);
             *          }
             */
        }
コード例 #6
0
        public void OnGUI()
        {
            // build android project
            build_android_project = EditorGUILayout.Toggle("Build Android Project", build_android_project);

            // option
            if (build_android_project)
            {
                //build_option = (IOSBuildOption)EditorGUILayout.EnumPopup("Option", build_option);
                int selected = Array.IndexOf(option_list, selected_option);
                selected        = EditorGUILayout.Popup("Use Backuped ?", selected, option_list);
                selected_option = option_list[selected];
            }

            // backup info
            // null means rebuild, if not null, print backup info
            if (this.BackupName != null)
            {
                // if backup_project is not current selected project, reload it.
                if (backup_project == null || backup_project.Path != Configuration.Gloable.Eclipse_Project_Backup_Home + "/" + this.BackupName + "/Game")
                {
                    backup_project = new EclipseProject(Configuration.Gloable.Eclipse_Project_Backup_Home + "/" + this.BackupName + "/Game");
                }
                EditorGUILayout.LabelField("Backup Built At: " + this.backup_project.BuildTime);
            }


            if (!build_android_project)
            {
                apply_native_builder = false;
            }

            /*
             *          apply_native_builder = EditorGUILayout.Toggle("Apply NativeBuilder", apply_native_builder);
             *          {
             *                  if(apply_native_builder)
             *                  {
             *                          if(mod_list.Length > 0)
             *                          {
             *                                  int selectedIndex = Array.IndexOf(mod_list, selected_mod);
             *                                  selectedIndex = EditorGUILayout.Popup("Eupe package", selectedIndex, mod_list);
             *                                  this.selected_mod = mod_list[selectedIndex];
             *                          }
             *                          else
             *                          {
             *                                  EditorGUILayout.LabelField("None of .eupe package found, Can't Build.");
             *                          }
             *                  }
             *          }
             *          if(!apply_native_builder)
             *          {
             *                  build_apk = false;
             *          }else{
             *                  build_android_project = true;
             *          }
             *
             *          build_apk = EditorGUILayout.Toggle("Build Apk", build_apk);
             *          if(!build_apk)
             *          {
             *                  run_apk = false;
             *          }else
             *          {
             *                  build_android_project = true;
             *                  apply_native_builder = true;
             *          }
             *
             *          run_apk = EditorGUILayout.Toggle("Run Apk", run_apk);
             *          if(!run_apk)
             *          {
             *          }
             *          else
             *          {
             *                  build_android_project = true;
             *                  apply_native_builder = true;
             *                  build_apk = true;
             *          }
             */

            if (!string.IsNullOrEmpty(this.selected_option))
            {
                if (GUILayout.Button("Build"))
                {
                    var task = new BuildTask_Android(GetBuildLevel(), this.BackupName, this.selected_mod);
                    task.Build();
                }
            }
        }
コード例 #7
0
        public void OnGUI()
        {
            // build android project
            // build_android_project = EditorGUILayout.Toggle("Build Android Project", build_android_project);

            // option
            if (build_android_project)
            {
                //build_option = (IOSBuildOption)EditorGUILayout.EnumPopup("Option", build_option);
                int selected = Array.IndexOf(option_list, selected_option);
                selected        = EditorGUILayout.Popup("Use Backuped ?", selected, option_list);
                selected_option = option_list[selected];
            }

            // backup info
            // null means rebuild, if not null, print backup info
            if (this.BackupName != null)
            {
                // if backup_project is not current selected project, reload it.
                if (backup_project == null || backup_project.Path != Configuration.Gloable.Eclipse_Project_Backup_Home + "/" + this.BackupName + "/Game")
                {
                    backup_project = new EclipseProject(Configuration.Gloable.Eclipse_Project_Backup_Home + "/" + this.BackupName + "/Game");
                }
                EditorGUILayout.LabelField("Backup Built At: " + this.backup_project.BuildTime);
            }


            if (!build_android_project)
            {
                apply_native_builder = false;
            }

            /*
             *          apply_native_builder = EditorGUILayout.Toggle("Apply NativeBuilder", apply_native_builder);
             *          {
             *                  if(apply_native_builder)
             *                  {
             *                          if(mod_list.Length > 0)
             *                          {
             *                                  int selectedIndex = Array.IndexOf(mod_list, selected_mod);
             *                                  selectedIndex = EditorGUILayout.Popup("Eupe package", selectedIndex, mod_list);
             *                                  this.selected_mod = mod_list[selectedIndex];
             *                          }
             *                          else
             *                          {
             *                                  EditorGUILayout.LabelField("None of .eupe package found, Can't Build.");
             *                          }
             *                  }
             *          }
             *          if(!apply_native_builder)
             *          {
             *                  build_apk = false;
             *          }else{
             *                  build_android_project = true;
             *          }
             *
             *          build_apk = EditorGUILayout.Toggle("Build Apk", build_apk);
             *          if(!build_apk)
             *          {
             *                  run_apk = false;
             *          }else
             *          {
             *                  build_android_project = true;
             *                  apply_native_builder = true;
             *          }
             *
             *          run_apk = EditorGUILayout.Toggle("Run Apk", run_apk);
             *          if(!run_apk)
             *          {
             *          }
             *          else
             *          {
             *                  build_android_project = true;
             *                  apply_native_builder = true;
             *                  build_apk = true;
             *          }
             */

            // player name
            {
                var productName = PlayerSettings.productName;
                productName = EditorGUILayout.TextField("Product Name", productName);
                PlayerSettings.productName = productName;
            }

            // package name
            {
                var a = PlayerSettings.applicationIdentifier;
                var b = EditorGUILayout.TextField("Package", a);
                //PlayerSettings.applicationIdentifier = b;
                PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, b);
            }

            {
                var list = EditorBuildSettings.scenes;
                foreach (var s in list)
                {
                    var enable = GUILayout.Toggle(s.enabled, s.path);
                    s.enabled = enable;
                }
                EditorBuildSettings.scenes = list;
            }


            if (!string.IsNullOrEmpty(this.selected_option))
            {
                if (GUILayout.Button("Build"))
                {
                    var task = new BuildTask_Android(GetBuildLevel(), this.BackupName, this.selected_mod);
                    task.Build();
                }
            }
            if (GUILayout.Button("Open ProductDirectory"))
            {
                OpenProductDir();
            }
        }