コード例 #1
0
    private void PatchAndroidManifest(string root)
    {
        var manifestFilePath = GetManifestFilePath(root);
        var manifest         = new UniWebViewAndroidManifest(manifestFilePath);

        var changed = false;

        Debug.Log("<UniWebView> Set hardware accelerated to enable smooth web view experience and HTML5 support like video and canvas.");
        changed = manifest.SetHardwareAccelerated() || changed;

        var settings = UniWebViewEditorSettings.GetOrCreateSettings();

        if (settings.usesCleartextTraffic)
        {
            changed = manifest.SetUsesCleartextTraffic() || changed;
        }
        if (settings.writeExternalStorage)
        {
            changed = manifest.AddWriteExternalStoragePermission() || changed;
        }
        if (settings.accessFineLocation)
        {
            changed = manifest.AddAccessFineLocationPermission() || changed;
        }

        if (changed)
        {
            manifest.Save();
        }
    }
コード例 #2
0
    public static void Patch(string filePath)
    {
        string[] lines = File.ReadAllLines(filePath);

        bool hasAndroidXProperty = lines.Any(text => text.Contains("android.useAndroidX"));
        bool hasJetifierProperty = lines.Any(text => text.Contains("android.enableJetifier"));

        StringBuilder builder = new StringBuilder();

        foreach (string each in lines)
        {
            builder.AppendLine(each);
        }

        if (!hasAndroidXProperty)
        {
            builder.AppendLine("android.useAndroidX=true");
        }

        if (!hasJetifierProperty && UniWebViewEditorSettings.GetOrCreateSettings().enableJetifier)
        {
            builder.AppendLine("android.enableJetifier=true");
        }

        File.WriteAllText(filePath, builder.ToString());
    }
コード例 #3
0
    private void PatchBuildGradle(string root)
    {
        var gradleFilePath = GetGradleFilePath(root);
        var config         = new UniWebViewGradleConfig(gradleFilePath);

        var kotlinPrefix  = "implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:";
        var kotlinVersion = "1.4.10'";

        var browserPrefix  = "implementation 'androidx.browser:browser:";
        var browserVersion = "1.2.0'";

        var settings = UniWebViewEditorSettings.GetOrCreateSettings();

        var dependenciesNode = config.ROOT.FindChildNodeByName("dependencies");

        if (dependenciesNode != null)
        {
            // Add kotlin
            if (settings.addsKotlin)
            {
                dependenciesNode.ReplaceContenOrAddStartsWith(kotlinPrefix, kotlinPrefix + kotlinVersion);
                Debug.Log("<UniWebView> Updated Kotlin dependency in build.gradle.");
            }

            // Add browser package
            if (settings.addsAndroidBrowser)
            {
                dependenciesNode.ReplaceContenOrAddStartsWith(browserPrefix, browserPrefix + browserVersion);
                Debug.Log("<UniWebView> Updated Browser dependency in build.gradle.");
            }
        }
        else
        {
            Debug.LogError("UniWebViewPostBuildProcessor didn't find the `dependencies` field in build.gradle.");
            Debug.LogError("Although we can continue to add a `dependencies`, make sure you have setup Gradle and the template correctly.");

            var newNode = new UniWebViewGradleNode("dependencies", config.ROOT);
            if (settings.addsKotlin)
            {
                newNode.AppendContentNode(kotlinPrefix + kotlinVersion);
            }
            if (settings.addsAndroidBrowser)
            {
                newNode.AppendContentNode(browserPrefix + browserVersion);
            }
            newNode.AppendContentNode("implementation(name: 'UniWebView', ext:'aar')");
            config.ROOT.AppendChildNode(newNode);
        }
        config.Save();
    }