Example #1
0
 public XamarinFormsMapsApplicationProject()
 {
     PackageReferences.Add(KnownPackages.XamarinFormsMaps_4_0_0_425677);
     MainActivity = MainActivity.Replace("//${AFTER_FORMS_INIT}", "Xamarin.FormsMaps.Init (this, savedInstanceState);");
     //NOTE: API_KEY metadata just has to *exist*
     AndroidManifest = AndroidManifest.Replace("</application>", "<meta-data android:name=\"com.google.android.maps.v2.API_KEY\" android:value=\"\" /></application>");
 }
        protected override void OnPostGenerateGradleAndroidProjectExt(string path)
        {
            var androidManifest = new AndroidManifest(GetManifestPath(path));

            androidManifest.AddOculusMetaData();
            androidManifest.Save();
        }
Example #3
0
        public XamarinAndroidApplicationProject()
        {
            SetProperty("AndroidApplication", "True");

            SetProperty("AndroidResgenClass", "Resource");
            SetProperty("AndroidResgenFile", () => "Resources\\Resource.designer" + Language.DefaultExtension);
            SetProperty("AndroidManifest", "Properties\\AndroidManifest.xml");
            SetProperty(DebugProperties, "AndroidLinkMode", "None");
            SetProperty(ReleaseProperties, "AndroidLinkMode", "SdkOnly");

            AndroidManifest = default_android_manifest;
            LayoutMain      = default_layout_main;
            StringsXml      = default_strings_xml;
            PackageName     = PackageName ?? string.Format("{0}.{0}", ProjectName);

            OtherBuildItems.Add(new BuildItem.NoActionResource("Properties\\AndroidManifest.xml")
            {
                TextContent = () =>
                              AndroidManifest.Replace("${PROJECT_NAME}", ProjectName).
                              Replace("${PACKAGENAME}", PackageName)
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Main.axml")
            {
                TextContent = () => LayoutMain
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\values\\Strings.xml")
            {
                TextContent = () => StringsXml.Replace("${PROJECT_NAME}", ProjectName)
            });

            Sources.Add(new BuildItem.Source(() => "MainActivity" + Language.DefaultExtension)
            {
                TextContent = () => ProcessSourceTemplate(MainActivity ?? DefaultMainActivity)
            });
        }
        public void SignAndroidPackage_DefaultProperties()
        {
            string versionCode = "1",
                   versionName = "1.0",
                   packageName = "com.test";
            var project        = MSBuild.NewProject(testDirectory);

            var projectFile = Path.Combine(tempDirectory, "test.csproj");

            project.Save(projectFile);
            MSBuild.Restore(projectFile);
            MSBuild.Build(projectFile, "SignAndroidPackage");

            var propsPath = Path.Combine(objDirectory, "Xamarin.Android.Lite.props");

            FileAssert.Exists(propsPath);
            var manifestPath = Path.Combine(objDirectory, "AndroidManifest.xml");

            FileAssert.Exists(manifestPath);
            var ns       = AndroidManifest.AndroidNamespace.Namespace;
            var manifest = AndroidManifest.Read(manifestPath);

            Assert.AreEqual(versionCode, manifest.Document.Attribute(ns + "versionCode")?.Value, "versionCode should match");
            Assert.AreEqual(versionName, manifest.Document.Attribute(ns + "versionName")?.Value, "versionName should match");
            Assert.AreEqual(packageName, manifest.Document.Attribute("package")?.Value, "package should match");

            var apkPath = Path.Combine(binDirectory, packageName + ".apk");

            FileAssert.Exists(apkPath);
        }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        androidManifest.SetActivityHardwareAccelerated("true");
        androidManifest.Save();
    }
Example #6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        protected override bool ValidateParameters()
        {
            try
            {
                //
                // Validate the target AndroidManifest input is at least parsable.
                //

                string sourcePath = ProjectManifest.GetMetadata("FullPath");

                var sourceManifest = new AndroidManifest(sourcePath);
            }
            catch (Exception e)
            {
                Log.LogErrorFromException(e, true);

                return(false);
            }

            var inputFiles = new List <ITaskItem>();

            inputFiles.Add(ProjectManifest);

            if (IncludeJarOrZip != null)
            {
                inputFiles.AddRange(IncludeJarOrZip);
            }

            InputFiles = inputFiles.ToArray();

            return(base.ValidateParameters());
        }
        public AndroidManifestHelper()
        {
            var manifestPath = Path.Combine(Application.dataPath, MainManifestPath);

            EnsureManifestExists(manifestPath);
            _manifest = new AndroidManifest(manifestPath);
        }
Example #8
0
        private HashSet <string> GetActivitiesWithMetadata(AndroidManifest doc, string name, string val)
        {
            HashSet <string> set        = new HashSet <string>();
            IEnumerator      enumerator = doc.GetElementsByTagName("meta-data").GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    XmlElement current    = (XmlElement)enumerator.Current;
                    XmlElement parentNode = (XmlElement)current.ParentNode;
                    if (((parentNode != null) && (parentNode.LocalName == "activity")) && ((current.GetAttribute("android:name") == name) && (current.GetAttribute("android:value") == val)))
                    {
                        set.Add(parentNode.GetAttribute("android:name"));
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            return(set);
        }
Example #9
0
 private void SetPermissionAttributes(PostProcessorContext context, AndroidManifest manifestXML, AssemblyReferenceChecker checker)
 {
     if ((this._developmentPlayer || PlayerSettings.Android.forceInternetPermission) || this.doesReferenceNetworkClasses(checker))
     {
         manifestXML.AddUsesPermission("android.permission.INTERNET");
     }
     if (checker.HasReferenceToMethod("UnityEngine.Handheld::Vibrate"))
     {
         manifestXML.AddUsesPermission("android.permission.VIBRATE");
     }
     if (checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::get_internetReachability") || checker.HasReferenceToMethod("UnityEngine.Application::get_internetReachability"))
     {
         manifestXML.AddUsesPermission("android.permission.ACCESS_NETWORK_STATE");
     }
     if (((checker.HasReferenceToMethod("UnityEngine.Input::get_location") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_lastLocation")) || (checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::get_locationServiceStatus") || checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::get_locationServiceEnabledByUser"))) || (checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::StartLocationServiceUpdates") || checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::StopLocationServiceUpdates")))
     {
         manifestXML.AddUsesPermission("android.permission.ACCESS_FINE_LOCATION");
         manifestXML.AddUsesFeature("android.hardware.location.gps", false);
         manifestXML.AddUsesFeature("android.hardware.location", false);
     }
     if (checker.HasReferenceToType("UnityEngine.WebCamTexture"))
     {
         manifestXML.AddUsesPermission("android.permission.CAMERA");
         manifestXML.AddUsesFeature("android.hardware.camera", false);
         manifestXML.AddUsesFeature("android.hardware.camera.autofocus", false);
         manifestXML.AddUsesFeature("android.hardware.camera.front", false);
     }
     if (checker.HasReferenceToType("UnityEngine.Microphone"))
     {
         manifestXML.AddUsesPermission("android.permission.RECORD_AUDIO");
         manifestXML.AddUsesFeature("android.hardware.microphone", false);
     }
     if (PlayerSettings.Android.forceSDCardPermission)
     {
         manifestXML.AddUsesPermission("android.permission.WRITE_EXTERNAL_STORAGE");
     }
     else if (this._developmentPlayer)
     {
         manifestXML.AddUsesPermission("android.permission.WRITE_EXTERNAL_STORAGE", 0x12);
         manifestXML.AddUsesPermission("android.permission.READ_EXTERNAL_STORAGE", 0x12);
     }
     if ((checker.HasReferenceToMethod("UnityEngine.Input::get_acceleration") || checker.HasReferenceToMethod("UnityEngine.Input::GetAccelerationEvent")) || (checker.HasReferenceToMethod("UnityEngine.Input::get_accelerationEvents") || checker.HasReferenceToMethod("UnityEngine.Input::get_accelerationEventCount")))
     {
         manifestXML.AddUsesFeature("android.hardware.sensor.accelerometer", false);
     }
     manifestXML.AddUsesFeature("android.hardware.touchscreen", false);
     if (((checker.HasReferenceToMethod("UnityEngine.Input::get_touches") || checker.HasReferenceToMethod("UnityEngine.Input::GetTouch")) || (checker.HasReferenceToMethod("UnityEngine.Input::get_touchCount") || checker.HasReferenceToMethod("UnityEngine.Input::get_multiTouchEnabled"))) || (((checker.HasReferenceToMethod("UnityEngine.Input::set_multiTouchEnabled") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_touches")) || (checker.HasReferenceToMethod("UnityEngine.iPhoneInput::GetTouch") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_touchCount"))) || (checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_multiTouchEnabled") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::set_multiTouchEnabled"))))
     {
         manifestXML.AddUsesFeature("android.hardware.touchscreen.multitouch", false);
         manifestXML.AddUsesFeature("android.hardware.touchscreen.multitouch.distinct", false);
     }
     if ((checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_acceleration") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::GetAccelerationEvent")) || (checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_accelerationEvents") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_accelerationEventCount")))
     {
         manifestXML.AddUsesFeature("android.hardware.sensor.accelerometer", false);
     }
     if (checker.HasReferenceToMethod("UnityEngine.iPhoneUtils::Vibrate"))
     {
         manifestXML.AddUsesPermission("android.permission.VIBRATE");
     }
 }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        androidManifest.SetMicrophonePermission();
        androidManifest.Save();
    }
Example #11
0
        public void Generate()
        {
            var task = new GenerateManifest {
                BuildEngine      = engine,
                DestinationFile  = temp,
                PackageName      = "com.test.app",
                ApplicationClass = "My.Namespace.App, MyAssembly",
                ActivityName     = "xamarin.android.lite.MainActivity",
                VersionCode      = "12",
                VersionName      = "2.0.0",
                AppTitle         = "MyApp",
                ActivityTitle    = "MyActivity",
            };

            Assert.IsTrue(task.Execute(), "Execute failed!");

            using (var stream = File.OpenRead(temp)) {
                var manifest = AndroidManifest.Read(stream);
                var xml      = @"<manifest xmlns:android=""http://schemas.android.com/apk/res/android"" android:versionCode=""12"" android:versionName=""2.0.0"" package=""com.test.app"" platformBuildVersionCode=""27"" platformBuildVersionName=""8.1.0"">
  <uses-sdk android:minSdkVersion=""19"" android:targetSdkVersion=""27"" />
  <uses-permission android:name=""android.permission.INTERNET"" />
  <uses-permission android:name=""android.permission.READ_EXTERNAL_STORAGE"" />
  <uses-permission android:name=""android.permission.WRITE_EXTERNAL_STORAGE"" />
  <uses-permission android:name=""android.permission.ACCESS_NETWORK_STATE"" />
  <uses-permission android:name=""android.permission.BATTERY_STATS"" />
  <uses-permission android:name=""android.permission.CAMERA"" />
  <uses-permission android:name=""android.permission.FLASHLIGHT"" />
  <uses-permission android:name=""android.permission.ACCESS_COARSE_LOCATION"" />
  <uses-permission android:name=""android.permission.ACCESS_FINE_LOCATION"" />
  <uses-permission android:name=""android.permission.VIBRATE"" />
  <uses-feature android:name=""android.hardware.location"" android:required=""false"" />
  <uses-feature android:name=""android.hardware.location.gps"" android:required=""false"" />
  <uses-feature android:name=""android.hardware.location.network"" android:required=""false"" />
  <application android:label=""MyApp"" android:icon=""2130903040"" android:name=""android.app.Application"" android:debuggable=""true"" android:allowBackup=""true"">
    <meta-data android:name=""Xamarin.Android.Lite.Application"" android:value=""My.Namespace.App, MyAssembly"" />
    <activity android:theme=""2131493263"" android:label=""MyActivity"" android:icon=""2130903040"" android:name=""xamarin.android.lite.MainActivity"" android:configChanges=""1152"">
      <intent-filter>
        <action android:name=""android.intent.action.MAIN"" />
        <category android:name=""android.intent.category.LAUNCHER"" />
      </intent-filter>
    </activity>
    <service android:name=""md5dcb6eccdc824e0677ffae8ccdde42930.KeepAliveService"" />
    <receiver android:label=""Essentials Battery Broadcast Receiver"" android:name=""md5d630c3d3bfb5f5558520331566132d97.BatteryBroadcastReceiver"" android:enabled=""true"" android:exported=""false"" />
    <receiver android:label=""Essentials Connectivity Broadcast Receiver"" android:name=""md5d630c3d3bfb5f5558520331566132d97.ConnectivityBroadcastReceiver"" android:enabled=""true"" android:exported=""false"" />
    <receiver android:label=""Essentials Power Broadcast Receiver"" android:name=""md5d630c3d3bfb5f5558520331566132d97.PowerBroadcastReceiver"" android:enabled=""true"" android:exported=""false"" />
    <receiver android:name=""md51558244f76c53b6aeda52c8a337f2c37.PowerSaveModeBroadcastReceiver"" android:enabled=""true"" android:exported=""false"" />
    <provider android:name=""mono.MonoRuntimeProvider"" android:exported=""false"" android:authorities=""com.test.app.mono.MonoRuntimeProvider.__mono_init_"" android:initOrder=""2147483647"" />
    <receiver android:name=""mono.android.Seppuku"">
      <intent-filter>
        <action android:name=""mono.android.intent.action.SEPPUKU"" />
        <category android:name=""mono.android.intent.category.SEPPUKU.com.test.app"" />
      </intent-filter>
    </receiver>
  </application>
</manifest>";
                Assert.AreEqual(xml, manifest.Document.ToString());
            }
        }
        public XamarinAndroidApplicationProject(string debugConfigurationName = "Debug", string releaseConfigurationName = "Release")
            : base(debugConfigurationName, releaseConfigurationName)
        {
            if (Builder.UseDotNet)
            {
                SetProperty(KnownProperties.OutputType, "Exe");
                SetProperty("XamarinAndroidSupportSkipVerifyVersions", "True");

                // Workaround for AndroidX, see: https://github.com/xamarin/AndroidSupportComponents/pull/239
                Imports.Add(new Import(() => "Directory.Build.targets")
                {
                    TextContent = () =>
                                  @"<Project>
							<PropertyGroup>
								<VectorDrawableCheckBuildToolsVersionTaskBeforeTargets />
							</PropertyGroup>
						</Project>"
                });
            }
            else
            {
                SetProperty("AndroidApplication", "True");
                SetProperty("AndroidResgenClass", "Resource");
                SetProperty("AndroidResgenFile", () => "Resources\\Resource.designer" + Language.DefaultDesignerExtension);
                SetProperty("AndroidManifest", "Properties\\AndroidManifest.xml");
                SetProperty(DebugProperties, "AndroidLinkMode", "None");
                SetProperty(ReleaseProperties, "AndroidLinkMode", "SdkOnly");
                SetProperty(DebugProperties, KnownProperties.EmbedAssembliesIntoApk, "False", "'$(EmbedAssembliesIntoApk)' == ''");
                SetProperty(ReleaseProperties, KnownProperties.EmbedAssembliesIntoApk, "True", "'$(EmbedAssembliesIntoApk)' == ''");
            }

            AndroidManifest = default_android_manifest;
            LayoutMain      = default_layout_main;
            StringsXml      = default_strings_xml;
            PackageName     = PackageName ?? string.Format("{0}.{0}", ProjectName);
            JavaPackageName = JavaPackageName ?? PackageName.ToLowerInvariant();

            OtherBuildItems.Add(new BuildItem.NoActionResource("Properties\\AndroidManifest.xml")
            {
                TextContent = () =>
                              AndroidManifest.Replace("${PROJECT_NAME}", ProjectName).
                              Replace("${PACKAGENAME}", PackageName)
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\layout\\Main.axml")
            {
                TextContent = () => LayoutMain
            });
            AndroidResources.Add(new AndroidItem.AndroidResource("Resources\\values\\Strings.xml")
            {
                TextContent = () => StringsXml.Replace("${PROJECT_NAME}", ProjectName)
            });

            Sources.Add(new BuildItem.Source(() => "MainActivity" + Language.DefaultExtension)
            {
                TextContent = () => ProcessSourceTemplate(MainActivity ?? DefaultMainActivity)
            });
        }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        AndroidManifest androidManifest = new AndroidManifest(GetManifestPath(basePath));

        PangleAndroidAppManifestModifyer.Modify(androidManifest);
        //...

        androidManifest.Save();
    }
Example #14
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
#if !UNITY_2018_1_OR_NEWER
        if (buildTarget == BuildTarget.Android)
        {
            string manifest = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml");
            if (!File.Exists(manifest))
            {
                string manifest0 = Path.Combine(Application.dataPath, "../Temp/StagingArea/AndroidManifest-main.xml");
                if (!File.Exists(manifest0))
                {
                    Debug.LogError("unitywebview: cannot find both Assets/Plugins/Android/AndroidManifest.xml and Temp/StagingArea/AndroidManifest-main.xml. please build the app to generate Assets/Plugins/Android/AndroidManifest.xml and then rebuild it again.");
                    return;
                }
                else
                {
                    File.Copy(manifest0, manifest);
                }
            }
            var changed         = false;
            var androidManifest = new AndroidManifest(manifest);
            changed = (androidManifest.SetHardwareAccelerated(true) || changed);
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
            changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
            changed = (androidManifest.AddCamera() || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
            changed = (androidManifest.AddMicrophone() || changed);
#endif
#if UNITY_5_6_0 || UNITY_5_6_1
            changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
#endif
            if (changed)
            {
                androidManifest.Save();
                Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app.");
            }
        }
#endif

#if UNITY_IOS
        if (buildTarget == BuildTarget.iOS)
        {
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
            UnityEditor.iOS.Xcode.PBXProject proj = new using UnityEditor.iOS.Xcode.PBXProject();
            proj.ReadFromString(File.ReadAllText(projPath));
#if UNITY_2019_3_OR_NEWER
            proj.AddFrameworkToProject(proj.GetUnityFrameworkTargetGuid(), "WebKit.framework", false);
#else
            proj.AddFrameworkToProject(proj.TargetGuidByName("Unity-iPhone"), "WebKit.framework", false);
#endif
            File.WriteAllText(projPath, proj.WriteToString());
        }
#endif
    }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));
        var changed         = androidManifest.SetHardwareAccelerated(true);

        if (changed)
        {
            androidManifest.Save();
        }
    }
Example #16
0
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        // If needed, add condition checks on whether you need to run the modification routine.
        // For example, specific configuration/app options enabled
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        androidManifest.SetHardwareAccel();
        // Add your XML manipulation routines
        androidManifest.Save();
    }
        void Read()
        {
            var doc           = AndroidManifest.Read(binaryManifest);
            var xmlFromBinary = doc.Document.ToString();
            var xmlFromText   = LoadText();

            Assert.IsTrue(doc.Strings?.Count > 0, "Strings should be non-empty!");
            Assert.IsTrue(doc.Resources?.Count > 0, "Resources should be non-empty!");
            Assert.IsFalse(string.IsNullOrEmpty(doc.PlatformBuildVersionName), "FileVersion should be non-empty!");
            Assert.AreEqual(xmlFromText, xmlFromBinary);
        }
    public void OnPostGenerateGradleAndroidProject(string path)
    {
        GenerateGradleProperties(path);

        var androidManifest = new AndroidManifest(GetManifestPath(path));

        if (EditManifest(androidManifest))
        {
            androidManifest.Save();
            Debug.Log("adjusted AndroidManifest.xml.");
        }
    }
    static public void Modify(AndroidManifest androidManifest)
    {
        //权限
        androidManifest.AddPermission("android.permission.INTERNET");
        androidManifest.AddPermission("android.permission.ACCESS_NETWORK_STATE");
        androidManifest.AddPermission("android.permission.WAKE_LOCK");

        //TTMultiProvider
        XmlElement provider2 = androidManifest.AddProvider("com.bytedance.sdk.openadsdk.multipro.TTMultiProvider");

        androidManifest.SetProviderAttribute(provider2, "authorities", "${applicationId}.TTMultiProvider");
        androidManifest.SetProviderAttribute(provider2, "exported", "false");
    }
        protected static void GenerateAndroidManifest(string targetPath, string stagingArea, string packageName, bool debugAttr = true)
        {
            AndroidManifest manifest = new AndroidManifest(Path.Combine(stagingArea, "AndroidManifest.xml"));

            foreach (string str in UnityActivities)
            {
                manifest.RenameActivity(DefaultUnityPackage + "." + str, packageName + "." + str);
            }
            if (!debugAttr)
            {
                manifest.RemoveApplicationFlag("debuggable");
            }
            manifest.SaveAs(Path.Combine(targetPath, "AndroidManifest.xml"));
        }
Example #21
0
    //// for android/unity 2018.1 or newer
    //// cf. https://forum.unity.com/threads/android-hardwareaccelerated-is-forced-false-in-all-activities.532786/
    //// cf. https://github.com/Over17/UnityAndroidManifestCallback

#if UNITY_2018_1_OR_NEWER
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var changed         = false;
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        changed = (androidManifest.SetHardwareAccelerated(true) || changed);
#if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
        changed = (androidManifest.AddCamera() || changed);
#endif
        if (changed)
        {
            androidManifest.Save();
            Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
        }
    }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        // If needed, add condition checks on whether you need to run the modification routine.
        // For example, specific configuration/app options enabled

        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        FritzConfiguration config = FritzConfiguration.GetOrCreateSettings();

        androidManifest.AddAPIKey(config.androidAPIKey);

        // Add your XML manipulation routines

        androidManifest.Save();
    }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var isVr      = PlayerSettings.GetVirtualRealitySupported(BuildTargetGroup.Android);
        var vrSdks    = PlayerSettings.GetVirtualRealitySDKs(BuildTargetGroup.Android);
        var hasOculus = Array.Exists(vrSdks, s => s == OVRManager.OCULUS_UNITY_NAME_STR);

        if (isVr && hasOculus)
        {
            if (OVRDeviceSelector.isTargetDeviceQuest)
            {
                var androidManifest = new AndroidManifest(GetManifestPath(basePath));
                androidManifest.EnableQuestApp();
                androidManifest.Save();
            }
        }
    }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        // If needed, add condition checks on whether you need to run the modification routine.
        // For example, specific configuration/app options enabled
        string manifestPath    = GetManifestPath(basePath);
        var    androidManifest = new AndroidManifest(manifestPath);

        androidManifest.SetUSBHostFeature();
        androidManifest.SetUSBIntents();
        androidManifest.SetUSBMetadata();
        MergeResources(basePath);

        // Add your XML manipulation routines

        androidManifest.Save();
    }
    //// for android/unity 2018.1 or newer
    //// cf. https://forum.unity.com/threads/android-hardwareaccelerated-is-forced-false-in-all-activities.532786/
    //// cf. https://github.com/Over17/UnityAndroidManifestCallback

#if UNITY_2018_1_OR_NEWER
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var changed         = false;
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        changed = (androidManifest.SetHardwareAccelerated(true) || changed);
        changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
        changed = (androidManifest.AddCamera() || changed);
        changed = (androidManifest.AddMicrophone() || changed);
        changed = (androidManifest.AddGallery() || changed);

        if (changed)
        {
            androidManifest.Save();
            Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
        }
    }
Example #26
0
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        string rootProject = Path.Combine(basePath, "..");

        modifyGradleProperties(rootProject);
        overrideRootBuildGradle(rootProject);
        overrideLauncherBuildGradle(rootProject);
        overrideUnityLibBuildGradle(rootProject);

        var lancherModuleManifest = new AndroidManifest(GetManifestPath(rootProject));

        lancherModuleManifest.setApplicationToolReplace("android:label,android:icon,android:roundIcon");
        lancherModuleManifest.Save();

        File.Delete(rootProject + "/unityLibrary/libs/unity-classes.jar");

        Directory.Delete(rootProject + "/unityLibrary/src/main/jniLibs/", true);
    }
Example #27
0
        private void InjectBundleAndSDKVersion(PostProcessorContext context, string manifest)
        {
            int             targetSdkVersion  = context.Get <int>("TargetSDKVersion");
            AndroidManifest manifest2         = new AndroidManifest(manifest);
            string          bundleVersion     = PlayerSettings.bundleVersion;
            int             bundleVersionCode = PlayerSettings.Android.bundleVersionCode;

            manifest2.SetVersion(bundleVersion, bundleVersionCode);
            int minSdkVersion = (int)PlayerSettings.Android.minSdkVersion;

            manifest2.AddUsesSDK(minSdkVersion, targetSdkVersion);
            string bundleIdentifier = PlayerSettings.bundleIdentifier;

            if (this.IsValidAndroidBundleIdentifier(bundleIdentifier))
            {
                manifest2.packageName = bundleIdentifier;
            }
            manifest2.Save();
        }
Example #28
0
    public static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
#if !UNITY_2018_1_OR_NEWER
        if (buildTarget == BuildTarget.Android)
        {
            string manifest = Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml");
            if (!File.Exists(manifest))
            {
                string manifest0 = Path.Combine(Application.dataPath, "../Temp/StagingArea/AndroidManifest-main.xml");
                if (!File.Exists(manifest0))
                {
                    Debug.LogError("unitywebview: cannot find both Assets/Plugins/Android/AndroidManifest.xml and Temp/StagingArea/AndroidManifest-main.xml. please build the app to generate Assets/Plugins/Android/AndroidManifest.xml and then rebuild it again.");
                    return;
                }
                else
                {
                    File.Copy(manifest0, manifest);
                }
            }
            var changed         = false;
            var androidManifest = new AndroidManifest(manifest);
            changed = (androidManifest.SetHardwareAccelerated(true) || changed);
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
            changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
            changed = (androidManifest.AddCamera() || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
            changed = (androidManifest.AddMicrophone() || changed);
#endif
#if UNITY_5_6_0 || UNITY_5_6_1
            changed = (androidManifest.SetActivityName("net.gree.unitywebview.CUnityPlayerActivity") || changed);
#endif
            if (changed)
            {
                androidManifest.Save();
                Debug.LogError("unitywebview: adjusted AndroidManifest.xml. Please rebuild the app.");
            }
        }
#endif
    }
Example #29
0
    //// for android/unity 2018.1 or newer
    //// cf. https://forum.unity.com/threads/android-hardwareaccelerated-is-forced-false-in-all-activities.532786/
    //// cf. https://github.com/Over17/UnityAndroidManifestCallback

#if UNITY_2018_1_OR_NEWER
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var changed         = false;
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        changed = (androidManifest.SetHardwareAccelerated(true) || changed);
#if UNITYWEBVIEW_ANDROID_USES_CLEARTEXT_TRAFFIC
        changed = (androidManifest.SetUsesCleartextTraffic(true) || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_CAMERA
        changed = (androidManifest.AddCamera() || changed);
#endif
#if UNITYWEBVIEW_ANDROID_ENABLE_MICROPHONE
        changed = (androidManifest.AddMicrophone() || changed);
#endif
        if (changed)
        {
            androidManifest.Save();
            Debug.Log("unitywebview: adjusted AndroidManifest.xml.");
        }
    }
        private void CreateSupportsTextureElem(AndroidManifest manifestXML, MobileTextureSubtarget subTarget)
        {
            if ((PlayerSettings.colorSpace == ColorSpace.Linear) && (subTarget != MobileTextureSubtarget.DXT))
            {
                Debug.LogWarning("Linear rendering works only on new Tegra devices");
            }
            switch (subTarget)
            {
                case MobileTextureSubtarget.Generic:
                case MobileTextureSubtarget.ETC:
                    manifestXML.AddSupportsGLTexture("GL_OES_compressed_ETC1_RGB8_texture");
                    break;

                case MobileTextureSubtarget.DXT:
                    manifestXML.AddSupportsGLTexture("GL_EXT_texture_compression_dxt1");
                    manifestXML.AddSupportsGLTexture("GL_EXT_texture_compression_dxt5");
                    manifestXML.AddSupportsGLTexture("GL_EXT_texture_compression_s3tc");
                    break;

                case MobileTextureSubtarget.PVRTC:
                    manifestXML.AddSupportsGLTexture("GL_IMG_texture_compression_pvrtc");
                    break;

                case MobileTextureSubtarget.ATC:
                    manifestXML.AddSupportsGLTexture("GL_AMD_compressed_ATC_texture");
                    manifestXML.AddSupportsGLTexture("GL_ATI_texture_compression_atitc");
                    break;

                case MobileTextureSubtarget.ETC2:
                    break;

                case MobileTextureSubtarget.ASTC:
                    manifestXML.AddSupportsGLTexture("GL_KHR_texture_compression_astc_ldr");
                    break;

                default:
                    Debug.LogWarning("SubTarget not recognized : " + subTarget);
                    break;
            }
        }
Example #31
0
        private void CreateSupportsTextureElem(AndroidManifest manifestXML, MobileTextureSubtarget subTarget)
        {
            if ((PlayerSettings.colorSpace == ColorSpace.Linear) && (subTarget != MobileTextureSubtarget.DXT))
            {
                Debug.LogWarning("Linear rendering works only on new Tegra devices");
            }
            switch (subTarget)
            {
            case MobileTextureSubtarget.Generic:
            case MobileTextureSubtarget.ETC:
                manifestXML.AddSupportsGLTexture("GL_OES_compressed_ETC1_RGB8_texture");
                break;

            case MobileTextureSubtarget.DXT:
                manifestXML.AddSupportsGLTexture("GL_EXT_texture_compression_dxt1");
                manifestXML.AddSupportsGLTexture("GL_EXT_texture_compression_dxt5");
                manifestXML.AddSupportsGLTexture("GL_EXT_texture_compression_s3tc");
                break;

            case MobileTextureSubtarget.PVRTC:
                manifestXML.AddSupportsGLTexture("GL_IMG_texture_compression_pvrtc");
                break;

            case MobileTextureSubtarget.ATC:
                manifestXML.AddSupportsGLTexture("GL_AMD_compressed_ATC_texture");
                manifestXML.AddSupportsGLTexture("GL_ATI_texture_compression_atitc");
                break;

            case MobileTextureSubtarget.ETC2:
                break;

            case MobileTextureSubtarget.ASTC:
                manifestXML.AddSupportsGLTexture("GL_KHR_texture_compression_astc_ldr");
                break;

            default:
                Debug.LogWarning("SubTarget not recognized : " + subTarget);
                break;
            }
        }
        private string PatchManifest(PostProcessorContext context, string manifest)
        {
            BuildTarget platform = context.Get<BuildTarget>("BuildTarget");
            string[] components = new string[] { this._stagingArea, "assets", "bin" };
            string str = Paths.Combine(components);
            AndroidManifest manifestXML = new AndroidManifest(manifest);
            string location = this.PreferredInstallLocationAsString();
            manifestXML.SetInstallLocation(location);
            manifestXML.SetDebuggable(this._developmentPlayer || Unsupported.IsDeveloperBuild());
            int minSdkVersion = (int) PlayerSettings.Android.minSdkVersion;
            string glEsVersion = "0x00020000";
            GraphicsDeviceType[] graphicsAPIs = PlayerSettings.GetGraphicsAPIs(platform);
            if (Enumerable.Contains<GraphicsDeviceType>(graphicsAPIs, GraphicsDeviceType.OpenGLES3) && (minSdkVersion >= 0x12))
            {
                glEsVersion = "0x00030000";
            }
            if (Enumerable.Contains<GraphicsDeviceType>(graphicsAPIs, GraphicsDeviceType.OpenGLES2))
            {
                glEsVersion = "0x00020000";
            }
            if ((glEsVersion == "0x00030000") && (PlayerSettings.openGLRequireES31 || PlayerSettings.openGLRequireES31AEP))
            {
                glEsVersion = "0x00030001";
            }
            manifestXML.AddGLESVersion(glEsVersion);
            if ((glEsVersion == "0x00030001") && PlayerSettings.openGLRequireES31AEP)
            {
                manifestXML.AddUsesFeature("android.hardware.opengles.aep", true);
            }
            if (EditorUserBuildSettings.androidBuildSubtarget != MobileTextureSubtarget.Generic)
            {
                this.CreateSupportsTextureElem(manifestXML, EditorUserBuildSettings.androidBuildSubtarget);
            }
            HashSet<string> set = new HashSet<string>(this.GetActivitiesWithMetadata(manifestXML, "unityplayer.UnityActivity", "true"));
            string[] other = new string[] { "com.unity3d.player.UnityPlayerNativeActivity", "com.unity3d.player.UnityPlayerActivity", "com.unity3d.player.UnityPlayerProxyActivity" };
            set.UnionWith(other);
            string orientationAttr = this.GetOrientationAttr();
            bool flag = false;
            foreach (string str5 in set)
            {
                flag = manifestXML.SetOrientation(str5, orientationAttr) || flag;
                flag = manifestXML.SetLaunchMode(str5, "singleTask") || flag;
                flag = manifestXML.SetConfigChanges(str5, AndroidManifest.AndroidConfigChanges) || flag;
            }
            if (!flag)
            {
                Debug.LogWarning(string.Format("Unable to find unity activity in manifest. You need to make sure orientation attribute is set to {0} manually.", orientationAttr));
            }
            manifestXML.SetApplicationFlag("isGame", PlayerSettings.Android.androidIsGame);
            if (PlayerSettings.Android.androidBannerEnabled)
            {
                manifestXML.SetApplicationBanner("@drawable/app_banner");
            }
            if ((PlayerSettings.Android.androidTVCompatibility && !manifestXML.HasLeanbackLauncherActivity()) && !manifestXML.AddLeanbackLauncherActivity())
            {
                Debug.LogWarning("No activity with LEANBACK_LAUNCHER or LAUNCHER categories found.\nThe build may not be compatible with Android TV. Specify an activity with LEANBACK_LAUNCHER or LAUNCHER category in the manifest, or disable Android TV compatibility in Player Settings.");
            }
            switch (PlayerSettings.Android.androidGamepadSupportLevel)
            {
                case AndroidGamepadSupportLevel.SupportsGamepad:
                    manifestXML.AddUsesFeature("android.hardware.gamepad", false);
                    break;

                case AndroidGamepadSupportLevel.RequiresGamepad:
                    manifestXML.AddUsesFeature("android.hardware.gamepad", true);
                    break;
            }
            if (PlayerSettings.virtualRealitySupported)
            {
                manifestXML.OverrideTheme("@android:style/Theme.Black.NoTitleBar.Fullscreen");
                int num2 = context.Get<int>("GearVRMinSdkVersion");
                if (PlayerSettings.Android.minSdkVersion < num2)
                {
                    Debug.LogWarning("GearVR requires Minimum API Level of 19");
                }
            }
            AssemblyReferenceChecker checker = new AssemblyReferenceChecker();
            bool collectMethods = true;
            bool ignoreSystemDlls = true;
            string[] textArray3 = new string[] { str, "Data", "Managed" };
            string path = Paths.Combine(textArray3);
            checker.CollectReferences(path, collectMethods, 0f, ignoreSystemDlls);
            this.SetPermissionAttributes(context, manifestXML, checker);
            manifestXML.StripUnityLibEntryForNativeActitivy();
            manifestXML.SaveAs(manifest);
            return manifestXML.packageName;
        }
 private HashSet<string> GetActivitiesWithMetadata(AndroidManifest doc, string name, string val)
 {
     HashSet<string> set = new HashSet<string>();
     IEnumerator enumerator = doc.GetElementsByTagName("meta-data").GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             XmlElement current = (XmlElement) enumerator.Current;
             XmlElement parentNode = (XmlElement) current.ParentNode;
             if (((parentNode != null) && (parentNode.LocalName == "activity")) && ((current.GetAttribute("android:name") == name) && (current.GetAttribute("android:value") == val)))
             {
                 set.Add(parentNode.GetAttribute("android:name"));
             }
         }
     }
     finally
     {
         IDisposable disposable = enumerator as IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return set;
 }
 private void InjectBundleAndSDKVersion(PostProcessorContext context, string manifest)
 {
     int targetSdkVersion = context.Get<int>("TargetSDKVersion");
     AndroidManifest manifest2 = new AndroidManifest(manifest);
     string bundleVersion = PlayerSettings.bundleVersion;
     int bundleVersionCode = PlayerSettings.Android.bundleVersionCode;
     manifest2.SetVersion(bundleVersion, bundleVersionCode);
     int minSdkVersion = (int) PlayerSettings.Android.minSdkVersion;
     manifest2.AddUsesSDK(minSdkVersion, targetSdkVersion);
     string bundleIdentifier = PlayerSettings.bundleIdentifier;
     if (this.IsValidAndroidBundleIdentifier(bundleIdentifier))
     {
         manifest2.packageName = bundleIdentifier;
     }
     manifest2.Save();
 }
 private void SetPermissionAttributes(PostProcessorContext context, AndroidManifest manifestXML, AssemblyReferenceChecker checker)
 {
     if ((this._developmentPlayer || PlayerSettings.Android.forceInternetPermission) || this.doesReferenceNetworkClasses(checker))
     {
         manifestXML.AddUsesPermission("android.permission.INTERNET");
     }
     if (checker.HasReferenceToMethod("UnityEngine.Handheld::Vibrate"))
     {
         manifestXML.AddUsesPermission("android.permission.VIBRATE");
     }
     if (checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::get_internetReachability") || checker.HasReferenceToMethod("UnityEngine.Application::get_internetReachability"))
     {
         manifestXML.AddUsesPermission("android.permission.ACCESS_NETWORK_STATE");
     }
     if (((checker.HasReferenceToMethod("UnityEngine.Input::get_location") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_lastLocation")) || (checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::get_locationServiceStatus") || checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::get_locationServiceEnabledByUser"))) || (checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::StartLocationServiceUpdates") || checker.HasReferenceToMethod("UnityEngine.iPhoneSettings::StopLocationServiceUpdates")))
     {
         manifestXML.AddUsesPermission("android.permission.ACCESS_FINE_LOCATION");
         manifestXML.AddUsesFeature("android.hardware.location.gps", false);
         manifestXML.AddUsesFeature("android.hardware.location", false);
     }
     if (checker.HasReferenceToType("UnityEngine.WebCamTexture"))
     {
         manifestXML.AddUsesPermission("android.permission.CAMERA");
         manifestXML.AddUsesFeature("android.hardware.camera", false);
         manifestXML.AddUsesFeature("android.hardware.camera.autofocus", false);
         manifestXML.AddUsesFeature("android.hardware.camera.front", false);
     }
     if (checker.HasReferenceToType("UnityEngine.Microphone"))
     {
         manifestXML.AddUsesPermission("android.permission.RECORD_AUDIO");
         manifestXML.AddUsesFeature("android.hardware.microphone", false);
     }
     if (PlayerSettings.Android.forceSDCardPermission)
     {
         manifestXML.AddUsesPermission("android.permission.WRITE_EXTERNAL_STORAGE");
     }
     else if (this._developmentPlayer)
     {
         manifestXML.AddUsesPermission("android.permission.WRITE_EXTERNAL_STORAGE", 0x12);
         manifestXML.AddUsesPermission("android.permission.READ_EXTERNAL_STORAGE", 0x12);
     }
     if ((checker.HasReferenceToMethod("UnityEngine.Input::get_acceleration") || checker.HasReferenceToMethod("UnityEngine.Input::GetAccelerationEvent")) || (checker.HasReferenceToMethod("UnityEngine.Input::get_accelerationEvents") || checker.HasReferenceToMethod("UnityEngine.Input::get_accelerationEventCount")))
     {
         manifestXML.AddUsesFeature("android.hardware.sensor.accelerometer", false);
     }
     manifestXML.AddUsesFeature("android.hardware.touchscreen", false);
     if (((checker.HasReferenceToMethod("UnityEngine.Input::get_touches") || checker.HasReferenceToMethod("UnityEngine.Input::GetTouch")) || (checker.HasReferenceToMethod("UnityEngine.Input::get_touchCount") || checker.HasReferenceToMethod("UnityEngine.Input::get_multiTouchEnabled"))) || (((checker.HasReferenceToMethod("UnityEngine.Input::set_multiTouchEnabled") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_touches")) || (checker.HasReferenceToMethod("UnityEngine.iPhoneInput::GetTouch") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_touchCount"))) || (checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_multiTouchEnabled") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::set_multiTouchEnabled"))))
     {
         manifestXML.AddUsesFeature("android.hardware.touchscreen.multitouch", false);
         manifestXML.AddUsesFeature("android.hardware.touchscreen.multitouch.distinct", false);
     }
     if ((checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_acceleration") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::GetAccelerationEvent")) || (checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_accelerationEvents") || checker.HasReferenceToMethod("UnityEngine.iPhoneInput::get_accelerationEventCount")))
     {
         manifestXML.AddUsesFeature("android.hardware.sensor.accelerometer", false);
     }
     if (checker.HasReferenceToMethod("UnityEngine.iPhoneUtils::Vibrate"))
     {
         manifestXML.AddUsesPermission("android.permission.VIBRATE");
     }
 }
 public override void Refresh(AndroidManifest manifest)
 {
     if (!manifest.HasMetaData(metaDataName))
     {
         if (!defaulted)
         {
             defaulted = true;
             userInput = defaultValue;
         }
         return;
     }
     var value = manifest.GetMetaData(metaDataName);
     if (userInput == metaDataValue)
         userInput = value;
     metaDataValue = value;
 }
 public override void SetRequirement(AndroidManifest.Requirements requirements)
 {
     if (requirements.metaDatas.ContainsKey(metaDataName))
         requirements.metaDatas[metaDataName] = userInput;
     else
         requirements.metaDatas.Add (metaDataName, userInput);
 }
 public override void Refresh(AndroidManifest manifest)
 {
     if (!manifest.HasMetaData(metaDataName))
     {
         if (!defaulted)
         {
             defaulted = true;
             userInput = defaultValue;
         }
         return;
     }
     var value = manifest.GetMetaData(metaDataName);
     if (((int)userInput == 0) && string.IsNullOrEmpty(metaDataValue))
     {
         userInput = (Gravity)GravityConverter.FromInt(int.Parse(value));
     }
     metaDataValue = value;
 }
 public override void SetRequirement(AndroidManifest.Requirements requirements)
 {
     if (requirements.metaDatas.ContainsKey(metaDataName))
         requirements.metaDatas[metaDataName] = GravityConverter.ToInt(userInput).ToString();
     else
         requirements.metaDatas.Add (metaDataName, GravityConverter.ToInt(userInput).ToString());
 }
 public abstract void SetRequirement(AndroidManifest.Requirements requirements);
 public abstract void Refresh(AndroidManifest manifest);
 public override void SetRequirement(AndroidManifest.Requirements requirements)
 {
     var value = userInput ? trueValue : falseValue;
     if (requirements.metaDatas.ContainsKey(metaDataName))
         requirements.metaDatas[metaDataName] = value;
     else
         requirements.metaDatas.Add(metaDataName, value);
 }
    private void CheckManifest(bool fix)
    {
        if (fix)
        {
            foreach (var f in allFields)
            {
                f.SetRequirement(manifestRequirements);
            }
        }

        var manifest = new AndroidManifest(manifestRequirements);
        manifest.Check(manifestErrors, manifestWarnings, fix);
        manifestExists = manifest.Exists;

        foreach (var f in allFields)
        {
            f.Refresh(manifest);
        }

        Summarize();
    }
 private void UploadAndStartPlayer(PostProcessorContext context, bool retryUpload)
 {
     bool flag = context.Get<bool>("DevelopmentPlayer");
     AndroidDevice device = context.Get<AndroidDevice>("AndroidDevice");
     string path = context.Get<string>("ManifestName");
     if (this.OnProgress != null)
     {
         this.OnProgress(this, "Copying APK package to device " + device.Describe());
     }
     string str2 = device.Install(Path.Combine(this._stagingArea, "Package.apk"), null);
     if (!retryUpload && (str2.Contains("[INSTALL_FAILED_UPDATE_INCOMPATIBLE]") || str2.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 " + device.Describe());
         }
         device.Uninstall(this._packageName, null);
         this.UploadAndStartPlayer(context, true);
     }
     else
     {
         if (((str2.Contains("protocol failure") || str2.Contains("No space left on device")) || (str2.Contains("[INSTALL_FAILED_INSUFFICIENT_STORAGE]") || str2.Contains("[INSTALL_FAILED_UPDATE_INCOMPATIBLE]"))) || ((str2.Contains("[INSTALL_FAILED_MEDIA_UNAVAILABLE]") || str2.Contains("[INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES]")) || str2.Contains("Failure [")))
         {
             Debug.LogError("Installation failed with the following output:\n" + str2);
             CancelPostProcess.AbortBuildPointToConsole("Unable to install APK!", "Installation failed.");
         }
         bool flag2 = flag || Unsupported.IsDeveloperBuild();
         if (this.OnProgress != null)
         {
             this.OnProgress(this, "Setting device property CheckJNI to " + flag2);
         }
         device.SetProperty("debug.checkjni", !flag2 ? "0" : "1", null);
         if (this._useObb && File.Exists(Path.Combine(this._stagingArea, "main.obb")))
         {
             int bundleVersionCode = PlayerSettings.Android.bundleVersionCode;
             string[] strArray = new string[] { "/mnt/shell/emulated", "/mnt/shell/emulated/0/Android", device.ExternalStorageRoot + "/Android" };
             bool flag3 = false;
             Exception exception = null;
             if (this.OnProgress != null)
             {
                 this.OnProgress(this, "Copying APK Expansion file to device " + device.Describe());
             }
             foreach (string str3 in strArray)
             {
                 string str4 = "obb";
                 string str5 = string.Format("main.{0}.{1}.obb", bundleVersionCode.ToString(), this._packageName);
                 string dst = string.Format("{0}/{1}/{2}/{3}", new object[] { str3, str4, this._packageName, str5 });
                 try
                 {
                     device.Push(Path.Combine(this._stagingArea, "main.obb"), dst, null);
                     flag3 = true;
                     break;
                 }
                 catch (Exception exception2)
                 {
                     exception = exception2;
                 }
             }
             if (!flag3)
             {
                 Debug.LogException(exception);
                 CancelPostProcess.AbortBuildPointToConsole("Unable to deploy OBB to device", "Failed pushing OBB file to the device.");
             }
         }
         if (flag)
         {
             if (this.OnProgress != null)
             {
                 this.OnProgress(this, "Setting up profiler tunnel");
             }
             device.Forward(string.Format("tcp:{0}", 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.");
         }
         if (this.OnProgress != null)
         {
             this.OnProgress(this, "Attempting to start Unity Player on device " + device.Describe());
         }
         device.Launch(this._packageName, activityWithLaunchIntent, null);
     }
 }