Пример #1
0
 private void Clean()
 {
     if (Directory.Exists(this._installPath))
     {
         try
         {
             Directory.Delete(this._installPath);
         }
         catch (IOException)
         {
             CancelPostProcess.AbortBuild("Unable to create new apk!", $"Unable to write target apk because {this._installPath} is a non-empty directory", null);
         }
     }
     else
     {
         if (File.Exists(this._installPath))
         {
             File.Delete(this._installPath);
         }
         if (File.Exists(this._installPath))
         {
             CancelPostProcess.AbortBuild("Unable to delete old apk!", $"Target apk could not be overwritten: {this._installPath}", null);
         }
     }
     if (!Directory.Exists(this._installDirectory))
     {
         Directory.CreateDirectory(this._installDirectory);
     }
 }
        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)
 {
     if (this.OnProgress != null)
     {
         this.OnProgress(this, "Starting Android build");
     }
     this.EnsureUnityLibrariesAreAvailable(context);
     if (!context.Get <bool>("ExportAndroidProject") && !this.ArePasswordsProvided())
     {
         CancelPostProcess.AbortBuild("Can not sign application", "Unable to sign application; please provide passwords!", null);
     }
 }
        internal static void Launch(BuildTarget target, string installPath)
        {
            if (target != BuildTarget.Android)
            {
                CancelPostProcess.AbortBuild("Build failure", "Internal error: Target platform mismatch", null);
            }
            PostProcessRunner runner = new PostProcessRunner();

            _context.Set <string>("InstallPath", installPath);
            runner.AddNextTask(new PublishPackage());
            runner.RunAllTasks(_context);
        }
Пример #5
0
        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}");
                }
            }
        }
Пример #6
0
 private void ThrowIfInvalid(string packageName)
 {
     if (!this.IsValidAndroidBundleIdentifier(packageName))
     {
         string message = "Please set the Bundle Identifier in the Player Settings.";
         message = (message + " The value must follow the convention 'com.YourCompanyName.YourProductName'") + " and can contain alphanumeric characters and underscore." + "\nEach segment must not start with a numeric character or underscore.";
         Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings");
         CancelPostProcess.AbortBuild("Bundle Identifier has not been set up correctly", message, null);
     }
     if (!this.IsValidJavaPackageName(packageName))
     {
         Debug.LogWarning((("As of Unity 4.2 the restrictions on the Bundle Identifier has been updated " + " to include those for java package names. Specifically the" + " restrictions have been updated regarding reserved java keywords.") + "\n" + "\nhttp://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html") + "\nhttp://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.9" + "\n");
     }
 }
        public void Execute(PostProcessorContext context)
        {
            if (this.OnProgress != null)
            {
                this.OnProgress(this, "Building");
            }
            string str    = context.Get <string>("StagingArea");
            int    system = context.Get <int>("ProjectType");

            if (system != 1)
            {
                throw new UnityException("Illegal project type: " + system);
            }
            AndroidProjectExport.Create(system).Export(context, null);
            bool   flag           = PlayerSettings.Android.keyaliasName.Length != 0;
            bool   flag2          = context.Get <bool>("DevelopmentPlayer");
            string sourceFileName = "";
            string task           = "";

            string[] components = new string[] { "Temp", "gradleOut" };
            string   workingdir = Paths.Combine(components);

            if (flag2 || Unsupported.IsDeveloperBuild())
            {
                task = "assembleDebug";
                string[] textArray2 = new string[] { workingdir, "build", "outputs", "apk", "gradleOut-debug.apk" };
                sourceFileName = Paths.Combine(textArray2);
            }
            else
            {
                if (!flag)
                {
                    CancelPostProcess.AbortBuild("Build Failure", "Release builds have to be signed when using Gradle", null);
                    return;
                }
                task = "assembleRelease";
                string[] textArray3 = new string[] { workingdir, "build", "outputs", "apk", "gradleOut-release.apk" };
                sourceFileName = Paths.Combine(textArray3);
            }
            GradleWrapper.Run(workingdir, task, delegate(string task) {
                if (((this.OnProgress != null) && (task != "")) && (task[0] == ':'))
                {
                    this.OnProgress(this, "Task " + task.Substring(1));
                }
            });
            string[] textArray4 = new string[] { str, "Package.apk" };
            File.Move(sourceFileName, Paths.Combine(textArray4));
        }
Пример #8
0
        private void Move(PostProcessorContext context)
        {
            string str  = context.Get <string>("StagingArea");
            bool   flag = context.Get <bool>("UseObb");

            FileUtil.MoveFileOrDirectory(Path.Combine(str, "Package.apk"), this._installPath);
            if (!File.Exists(this._installPath))
            {
                CancelPostProcess.AbortBuild("Unable to create new apk!", $"Unable to move file '{Path.Combine(str, "Package.apk")}' -> '{this._installPath}", null);
            }
            if (flag && File.Exists(Path.Combine(str, "main.obb")))
            {
                string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(this._installPath);
                string path = Path.Combine(this._installDirectory, $"{fileNameWithoutExtension}.main.obb");
                FileUtil.DeleteFileOrDirectory(path);
                FileUtil.MoveFileOrDirectory(Path.Combine(str, "main.obb"), path);
            }
        }
 internal static string PrepareForBuild(BuildOptions options, BuildTarget target)
 {
     if (target != BuildTarget.Android)
     {
         CancelPostProcess.AbortBuild("Build failure", "Internal error: Target platform mismatch", null);
     }
     if ((options & BuildOptions.BuildAdditionalStreamedScenes) == BuildOptions.CompressTextures)
     {
         _context = new PostProcessorContext();
         SetupContextForPreBuild(_context, options, target);
         PostProcessRunner runner = new PostProcessRunner();
         runner.AddNextTask(new CheckPrerequisites());
         runner.AddNextTask(new CheckAndroidSdk());
         runner.AddNextTask(new CheckDevice());
         runner.RunAllTasks(_context);
     }
     return("");
 }
Пример #10
0
        private void StartApplication(PostProcessorContext context)
        {
            string path = context.Get <string>("ManifestName");

            if (this._developmentPlayer)
            {
                if (this.OnProgress != null)
                {
                    this.OnProgress(this, "Setting up profiler tunnel");
                }
                this._device.Forward($"tcp:{ProfilerDriver.directConnectionPort}", "localabstract:Unity-" + this._packageName, null);
            }
            string activityWithLaunchIntent = new AndroidManifest(path).GetActivityWithLaunchIntent();

            if (activityWithLaunchIntent.Length == 0)
            {
                CancelPostProcess.AbortBuild("Unable to start activity!", "No activity in the manifest with action MAIN and category LAUNCHER. Try launching the application manually on the device.", null);
            }
            if (this.OnProgress != null)
            {
                this.OnProgress(this, "Attempting to start Unity Player on device " + this._device.Describe());
            }
            this._device.Launch(this._packageName, activityWithLaunchIntent, null);
        }
Пример #11
0
        public void Execute(PostProcessorContext context)
        {
            if (this.OnProgress != null)
            {
                this.OnProgress(this, "Checking Android SDK and components");
            }
            this._sdkTools = AndroidSDKTools.GetInstance();
            if (this._sdkTools == null)
            {
                CancelPostProcess.AbortBuild("Build failure!", "Unable to locate Android SDK", null);
            }
            context.Set <AndroidSDKTools>("SDKTools", this._sdkTools);
            this.EnsureSDKComponentVersion(0x18, new SDKToolsDetector(this));
            this.EnsureSDKComponentVersion(0x17, new SDKBuildToolsDetector(this));
            this.EnsureSDKComponentVersion(0x17, new SDKPlatformToolsDetector(this));
            int num = this.EnsureSDKPlatformAPI("Android 6.0", 0x17);

            context.Set <int>("PlatformApiLevel", num);
            int num2 = Math.Max((int)PlayerSettings.Android.minSdkVersion, num);

            context.Set <int>("TargetSDKVersion", num2);
            this._sdkTools.UpdateToolsDirectories();
            this._sdkTools.DumpDiagnostics();
            AndroidJavaTools.DumpDiagnostics();
            string str = "android.jar";
            string androidPlatformPath = this._sdkTools.GetAndroidPlatformPath(num);

            if (androidPlatformPath.Length == 0)
            {
                EditorPrefs.SetString("AndroidSdkRoot", "");
                string message = "Android SDK does not include any platforms! Did you run Android SDK setup to install the platform(s)?\nMinimum platform required for build is Android 5.0 (API level 21)\n";
                CancelPostProcess.AbortBuild("No platforms found", message, null);
            }
            str = Path.Combine(androidPlatformPath, str);
            context.Set <string>("AndroidJarPath", str);
        }
Пример #12
0
        private AndroidDevice FindDevice(PostProcessorContext context)
        {
            BuildTarget         platform     = context.Get <BuildTarget>("BuildTarget");
            AndroidTargetDevice targetDevice = PlayerSettings.Android.targetDevice;
            List <string>       list         = null;

            do
            {
                list = ADB.Devices(null);
            }while ((list.Count == 0) && EditorUtility.DisplayDialog("No Android device found!", " * Make sure USB debugging has been enabled\n * Check your device, in most cases there should be a small icon in the status bar telling you if the USB connection is up.\n * If you are sure that device is attached then it might be USB driver problem, for details please check Android SDK Setup section in Unity manual.", "Retry", "Cancel"));
            if (list.Count < 1)
            {
                string message = $"No Android devices found.{(Application.platform != RuntimePlatform.WindowsEditor) ? "" : " If you are sure that device is attached then it might be USB driver problem, for details please check Android SDK Setup section in Unity manual."}
";
                CancelPostProcess.AbortBuild("Couldn't find Android device", message, null);
            }
            AndroidDevice device2 = new AndroidDevice(list[0]);
            int           num     = Convert.ToInt32(device2.Properties["ro.build.version.sdk"]);

            if (num < 9)
            {
                string str2 = (("Device: " + device2.Describe() + "\n") + "The connected device is not running Android OS 2.3 or later.") + " Unity Android does not support earlier versions of the Android OS;" + " please upgrade your device to a later OS version.";
                Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings");
                CancelPostProcess.AbortBuild("Device software is not supported", str2, null);
            }
            int num2 = 0;

            try
            {
                num2 = Convert.ToInt32(device2.Properties["ro.opengles.version"]);
            }
            catch (FormatException)
            {
                num2 = -1;
            }
            int num3 = 0xf0000;

            GraphicsDeviceType[] graphicsAPIs = PlayerSettings.GetGraphicsAPIs(platform);
            if (graphicsAPIs.Contains <GraphicsDeviceType>(GraphicsDeviceType.OpenGLES3))
            {
                num3 = 0x30000;
            }
            if (graphicsAPIs.Contains <GraphicsDeviceType>(GraphicsDeviceType.OpenGLES2))
            {
                num3 = 0x20000;
            }
            bool flag = device2.Features.Contains("android.hardware.opengles.aep");

            if ((num3 == 0x30000) && (PlayerSettings.openGLRequireES31 || PlayerSettings.openGLRequireES31AEP))
            {
                num3 = 0x30001;
            }
            bool flag2 = true;
            bool flag3 = (graphicsAPIs.Length == 1) && (graphicsAPIs[0] == GraphicsDeviceType.Vulkan);

            if ("Amazon" != device2.Properties["ro.product.brand"])
            {
                string str3 = null;
                if (flag3 && !flag2)
                {
                    str3 = "The connected device does not support Vulkan.";
                    str3 = str3 + " Please select OpenGLES under Player Settings instead.";
                }
                if (((num2 >= 0) && (num2 < num3)) || (PlayerSettings.openGLRequireES31AEP && !flag))
                {
                    str3 = "The connected device is not compatible with the selected OpenGLES version.";
                    str3 = str3 + " Please select a lower OpenGLES version under Player Settings instead.";
                }
                if (str3 != null)
                {
                    Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings");
                    CancelPostProcess.AbortBuild("Device hardware is not supported", str3, null);
                }
            }
            if ((targetDevice == AndroidTargetDevice.x86) && device2.Properties["ro.product.cpu.abi"].Equals("armeabi-v7a"))
            {
                string str4 = "You are trying to install x86 APK to ARM device. ";
                str4 = str4 + "Please select FAT or ARM as device filter under Player Settings, or connect a x86 device.";
                Selection.activeObject = Unsupported.GetSerializedAssetInterfaceSingleton("PlayerSettings");
                CancelPostProcess.AbortBuild("Device hardware is not supported", str4, null);
            }
            string str5   = device2.Properties["ro.product.manufacturer"];
            string str6   = device2.Properties["ro.product.model"];
            string action = device2.Properties["ro.product.cpu.abi"];
            bool   flag4  = device2.Properties["ro.secure"].Equals("1");
            string str8   = $"{char.ToUpper(str5[0])}{str5.Substring(1)} {str6}";
            string label  = $"Android API-{num}";

            UsabilityAnalytics.Event("Android Device", str8, label, !flag4 ? 0 : 1);
            string str10 = $"gles {num2 >> 0x10}.{num2 & 0xffff}{!flag ? "" : " AEP"}";

            if (num2 < 0)
            {
                str10 = "gles 2.0";
            }
            UsabilityAnalytics.Event("Android Architecture", action, str10, 1);
            string str11 = device2.Properties["ro.board.platform"];
            ulong  i     = device2.MemInfo["MemTotal"];

            i = UpperboundPowerOf2(i) / ((ulong)0x100000L);
            UsabilityAnalytics.Event("Android Chipset", str11, $"{i}MB", 1);
            return(device2);
        }
        internal static void PostProcess(BuildTarget target, string stagingAreaData, string stagingArea, string playerPackage, string installPath, string companyName, string productName, BuildOptions options, RuntimeClassRegistry usedClassRegistry)
        {
            if (target != BuildTarget.Android)
            {
                CancelPostProcess.AbortBuild("Build failure", "Internal error: Target platform mismatch", null);
            }
            _context.Set <BuildTarget>("BuildTarget", target);
            _context.Set <string>("StagingAreaData", stagingAreaData);
            _context.Set <string>("StagingArea", stagingArea);
            _context.Set <string>("InstallPath", installPath);
            _context.Set <RuntimeClassRegistry>("UsedClassRegistry", usedClassRegistry);
            bool flag = (options & BuildOptions.AutoRunPlayer) != BuildOptions.CompressTextures;

            _context.Set <bool>("AutoRunPlayer", flag);
            bool flag2 = (options & BuildOptions.AcceptExternalModificationsToPlayer) != BuildOptions.CompressTextures;

            _context.Set <bool>("ExportAndroidProject", flag2);
            _context.Set <string>("AndroidPluginsPath", "Assets/Plugins/Android");
            switch (EditorUserBuildSettings.androidBuildSystem)
            {
            case AndroidBuildSystem.Internal:
                _context.Set <int>("ProjectType", 0);
                break;

            case AndroidBuildSystem.Gradle:
                _context.Set <int>("ProjectType", 1);
                break;

            case AndroidBuildSystem.ADT:
                _context.Set <int>("ProjectType", 2);
                break;

            default:
                _context.Set <int>("ProjectType", !flag2 ? 0 : 2);
                break;
            }
            bool flag3 = _context.Get <int>("ProjectType") == 1;
            PostProcessRunner runner = new PostProcessRunner();

            runner.AddNextTask(new Initializer());
            runner.AddNextTask(new PrepareUnityResources());
            runner.AddNextTask(new SplitLargeFiles());
            runner.AddNextTask(new NonstreamingObbAssets());
            runner.AddNextTask(new PrepareUnityPackage());
            runner.AddNextTask(new PrepareUserResources());
            runner.AddNextTask(new PrepareAPKResources());
            runner.AddNextTask(new NativePlugins());
            if (!flag3)
            {
                runner.AddNextTask(new ProcessAAR());
            }
            runner.AddNextTask(new AddAndroidLibraries());
            runner.AddNextTask(new GenerateManifest());
            runner.AddNextTask(new BuildResources());
            if (!flag3 && !flag2)
            {
                runner.AddNextTask(new CheckLibrariesConflict());
                runner.AddNextTask(new RunDex());
            }
            runner.AddNextTask(new RunIl2Cpp());
            runner.AddNextTask(new StreamingAssets());
            runner.AddNextTask(new FastZip());
            runner.AddNextTask(new AAPTPackage());
            if (flag2)
            {
                runner.AddNextTask(new ExportProject());
            }
            else
            {
                if (flag3)
                {
                    runner.AddNextTask(new BuildGradleProject());
                }
                else
                {
                    runner.AddNextTask(new BuildAPK());
                }
                runner.AddNextTask(new MoveFinalPackage());
            }
            runner.RunAllTasks(_context);
        }