public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        androidManifest.SetActivityHardwareAccelerated("true");
        androidManifest.Save();
    }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));

        androidManifest.SetMicrophonePermission();
        androidManifest.Save();
    }
        protected override void OnPostGenerateGradleAndroidProjectExt(string path)
        {
            var androidManifest = new AndroidManifest(GetManifestPath(path));

            androidManifest.AddOculusMetaData();
            androidManifest.Save();
        }
Exemple #4
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)
    {
        AndroidManifest androidManifest = new AndroidManifest(GetManifestPath(basePath));

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

        androidManifest.Save();
    }
Exemple #6
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();
    }
    public void OnPostGenerateGradleAndroidProject(string basePath)
    {
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));
        var changed         = androidManifest.SetHardwareAccelerated(true);

        if (changed)
        {
            androidManifest.Save();
        }
    }
    public void OnPostGenerateGradleAndroidProject(string path)
    {
        GenerateGradleProperties(path);

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

        if (EditManifest(androidManifest))
        {
            androidManifest.Save();
            Debug.Log("adjusted AndroidManifest.xml.");
        }
    }
Exemple #9
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.");
        }
    }
        public void Regenerate()
        {
            GetSocialModifications.ForEach(node =>
            {
                _manifest.RemoveSimilar(node);
                _manifest.Add(node);
            });

            DeprecatedModifications.ForEach(node =>
            {
                _manifest.RemoveSimilar(node);
            });

            _manifest.Save();

            Debug.Log("GetSocial: successfully regenerated AndroidManifest.xml with GetSocial modifications");
        }
Exemple #15
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);
    }
Exemple #16
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();
        }
Exemple #17
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
    }
Exemple #18
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.");
        }
    }
Exemple #19
0
        void SetupApiKey()
        {
            var manifestPath = Path.Combine(Application.dataPath, MainManifestPath);

            EnsureManifestExists(manifestPath);

            var changed  = false;
            var apiKey   = new MetaData("com.google.android.geo.API_KEY", GoogleMapsViewSettings.AndroidApiKey.Trim());
            var manifest = new AndroidManifest(manifestPath);

            if (!manifest.Contains(apiKey))
            {
                manifest.RemoveSimilar(apiKey);
                manifest.Add(apiKey);
                changed = true;
            }

            // https://developers.google.com/maps/documentation/android-sdk/config#specify_requirement_for_apache_http_legacy_library
            if (!manifest.Contains(UsesApacheHttpLibrary))
            {
                manifest.RemoveSimilar(UsesApacheHttpLibrary);
                manifest.Add(UsesApacheHttpLibrary);
                changed = true;
            }

            if (GoogleMapsViewSettings.AddLocationPermission && !manifest.Contains(LocationPermission))
            {
                manifest.Add(LocationPermission);
                changed = true;
            }

            if (changed)
            {
                manifest.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

    public void OnPostGenerateGradleAndroidProject(string basePath) {
        Debug.Log("adjusted AndroidManifest.xml.");
        var androidManifest = new AndroidManifest(GetManifestPath(basePath));
        androidManifest.SetHardwareAccelerated(true);
        androidManifest.Save();
    }
    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);
            if (!nofragment)
            {
                changed = (androidManifest.AddFileProvider("Assets/Plugins/Android") || changed);
                var files = Directory.GetFiles("Assets/Plugins/Android/");
                var found = false;
                foreach (var file in files)
                {
                    if (Regex.IsMatch(file, @"^Assets/Plugins/Android/(androidx\.core\.)?core-.*.aar$"))
                    {
                        Debug.LogError("XXX");
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    foreach (var file in files)
                    {
                        var match = Regex.Match(file, @"^Assets/Plugins/Android/(core.*.aar).tmpl$");
                        if (match.Success)
                        {
                            var name = match.Groups[1].Value;
                            File.Copy(file, "Assets/Plugins/Android/" + name);
                            break;
                        }
                    }
                }
            }
            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 (buildTarget == BuildTarget.iOS)
        {
            string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
            var    type     = Type.GetType("UnityEditor.iOS.Xcode.PBXProject, UnityEditor.iOS.Extensions.Xcode");
            if (type == null)
            {
                Debug.LogError("unitywebview: failed to get PBXProject. please install iOS build support.");
                return;
            }
            var src = File.ReadAllText(projPath);
            //dynamic proj = type.GetConstructor(Type.EmptyTypes).Invoke(null);
            var proj = type.GetConstructor(Type.EmptyTypes).Invoke(null);
            //proj.ReadFromString(src);
            {
                var method = type.GetMethod("ReadFromString");
                method.Invoke(proj, new object[] { src });
            }
            var target = "";
#if UNITY_2019_3_OR_NEWER
            //target = proj.GetUnityFrameworkTargetGuid();
            {
                var method = type.GetMethod("GetUnityFrameworkTargetGuid");
                target = (string)method.Invoke(proj, null);
            }
#else
            //target = proj.TargetGuidByName("Unity-iPhone");
            {
                var method = type.GetMethod("TargetGuidByName");
                target = (string)method.Invoke(proj, new object[] { "Unity-iPhone" });
            }
#endif
            //proj.AddFrameworkToProject(target, "WebKit.framework", false);
            {
                var method = type.GetMethod("AddFrameworkToProject");
                method.Invoke(proj, new object[] { target, "WebKit.framework", false });
            }
#if UNITYWEBVIEW_IOS_ALLOW_FILE_URLS
            // proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-DUNITYWEBVIEW_IOS_ALLOW_FILE_URLS");
            {
                var method = type.GetMethod("AddBuildProperty", new Type[] { typeof(string), typeof(string), typeof(string) });
                method.Invoke(proj, new object[] { target, "OTHER_CFLAGS", "-DUNITYWEBVIEW_IOS_ALLOW_FILE_URLS" });
            }
#endif
            var dst = "";
            //dst = proj.WriteToString();
            {
                var method = type.GetMethod("WriteToString");
                dst = (string)method.Invoke(proj, null);
            }
            File.WriteAllText(projPath, dst);
        }
    }
    //// 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));

        if (!nofragment)
        {
            changed = (androidManifest.AddFileProvider(basePath) || changed);
            {
                var path   = GetBuildGradlePath(basePath);
                var lines0 = File.ReadAllText(path).Replace("\r\n", "\n").Replace("\r", "\n").Split(new[] { '\n' });
                {
                    var lines          = new List <string>();
                    var independencies = false;
                    foreach (var line in lines0)
                    {
                        if (line == "dependencies {")
                        {
                            independencies = true;
                        }
                        else if (independencies && line == "}")
                        {
                            independencies = false;
                            lines.Add("    implementation 'androidx.core:core:1.6.0'");
                        }
                        else if (independencies)
                        {
                            if (line.Contains("implementation(name: 'core") ||
                                line.Contains("implementation(name: 'androidx.core.core") ||
                                line.Contains("implementation 'androidx.core:core"))
                            {
                                break;
                            }
                        }
                        lines.Add(line);
                    }
                    if (lines.Count > lines0.Length)
                    {
                        File.WriteAllText(path, string.Join("\n", lines) + "\n");
                    }
                }
            }
            {
                var path   = GetGradlePropertiesPath(basePath);
                var lines0 = "";
                var lines  = "";
                if (File.Exists(path))
                {
                    lines0 = File.ReadAllText(path).Replace("\r\n", "\n").Replace("\r", "\n") + "\n";
                    lines  = lines0;
                }
                if (!lines.Contains("android.useAndroidX=true"))
                {
                    lines += "android.useAndroidX=true\n";
                }
                if (!lines.Contains("android.enableJetifier=true"))
                {
                    lines += "android.enableJetifier=true\n";
                }
                if (lines != lines0)
                {
                    File.WriteAllText(path, lines);
                }
            }
        }
        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 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();
 }