diff --git a/dist/package/Assets/Plugins/Android/core-1.6.0.aar.meta b/dist/package/Assets/Plugins/Android/core-1.6.0.aar.meta deleted file mode 100644 index cb3ff5a9..00000000 --- a/dist/package/Assets/Plugins/Android/core-1.6.0.aar.meta +++ /dev/null @@ -1,32 +0,0 @@ -fileFormatVersion: 2 -guid: 878a0a9f4379d44a6add9a66f2f187ba -PluginImporter: - externalObjects: {} - serializedVersion: 2 - iconMap: {} - executionOrder: {} - defineConstraints: [] - isPreloaded: 0 - isOverridable: 0 - isExplicitlyReferenced: 0 - validateReferences: 1 - platformData: - - first: - Android: Android - second: - enabled: 1 - settings: {} - - first: - Any: - second: - enabled: 0 - settings: {} - - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - userData: - assetBundleName: - assetBundleVariant: diff --git a/plugins/Android/install-nofragment.sh b/plugins/Android/install-nofragment.sh index dd489c9b..63e608f2 100755 --- a/plugins/Android/install-nofragment.sh +++ b/plugins/Android/install-nofragment.sh @@ -41,6 +41,6 @@ cp ${UNITY_JAVA_LIB} ${LIBS_DIR} DEST_DIR='../../build/Packager/Assets/Plugins/Android' mkdir -p ${DEST_DIR} cp ${BUILD_DIR}/build/outputs/aar/*.aar ${DEST_DIR}/WebViewPlugin.aar -rm -f ${DEST_DIR}/core*.aar +rm -f ${DEST_DIR}/core*.aar.tmpl popd diff --git a/plugins/Android/install.sh b/plugins/Android/install.sh index dac2bd08..b0891672 100755 --- a/plugins/Android/install.sh +++ b/plugins/Android/install.sh @@ -45,6 +45,7 @@ cp ${UNITY_JAVA_LIB} ${LIBS_DIR} DEST_DIR='../../build/Packager/Assets/Plugins/Android' mkdir -p ${DEST_DIR} cp ${BUILD_DIR}/build/outputs/aar/*.aar ${DEST_DIR}/WebViewPlugin.aar -cp ${BUILD_DIR}/libs/core*.aar ${DEST_DIR} +core_aar=`basename ${BUILD_DIR}/libs-ext/core*.aar` +cp ${BUILD_DIR}/libs-ext/$core_aar ${DEST_DIR}/$core_aar.tmpl popd diff --git a/plugins/Android/webview-nofragment/build.gradle b/plugins/Android/webview-nofragment/build.gradle index 11b34892..e10c6788 100644 --- a/plugins/Android/webview-nofragment/build.gradle +++ b/plugins/Android/webview-nofragment/build.gradle @@ -20,5 +20,5 @@ android { } dependencies { - compileOnly files('./libs/classes.jar') + compileOnly fileTree(dir: 'libs', include: ['*.jar']) } diff --git a/plugins/Android/webview/build.gradle b/plugins/Android/webview/build.gradle index 82fb3a11..2add17a9 100644 --- a/plugins/Android/webview/build.gradle +++ b/plugins/Android/webview/build.gradle @@ -20,6 +20,6 @@ android { } dependencies { - compileOnly files('./libs/classes.jar') + compileOnly fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.core:core:1.6.0' } diff --git a/dist/package/Assets/Plugins/Android/core-1.6.0.aar b/plugins/Android/webview/libs-ext/core-1.6.0.aar similarity index 100% rename from dist/package/Assets/Plugins/Android/core-1.6.0.aar rename to plugins/Android/webview/libs-ext/core-1.6.0.aar diff --git a/plugins/Android/webview/libs/.gitkeep b/plugins/Android/webview/libs/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/plugins/Android/webview/libs/core-1.6.0.aar b/plugins/Android/webview/libs/core-1.6.0.aar deleted file mode 100644 index cdf16635..00000000 Binary files a/plugins/Android/webview/libs/core-1.6.0.aar and /dev/null differ diff --git a/plugins/Editor/UnityWebViewPostprocessBuild.cs b/plugins/Editor/UnityWebViewPostprocessBuild.cs index 349ffca4..3aaa381f 100644 --- a/plugins/Editor/UnityWebViewPostprocessBuild.cs +++ b/plugins/Editor/UnityWebViewPostprocessBuild.cs @@ -1,7 +1,9 @@ #if UNITY_EDITOR +using System.Collections.Generic; using System.Collections; using System.IO; using System.Reflection; +using System.Text.RegularExpressions; using System.Text; using System.Xml; using System; @@ -28,6 +30,48 @@ public void OnPostGenerateGradleAndroidProject(string basePath) { 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(); + 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 '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 @@ -60,6 +104,21 @@ private string GetManifestPath(string basePath) { return pathBuilder.ToString(); } + private string GetBuildGradlePath(string basePath) { + var pathBuilder = new StringBuilder(basePath); + pathBuilder.Append(Path.DirectorySeparatorChar).Append("build.gradle"); + return pathBuilder.ToString(); + } + + private string GetGradlePropertiesPath(string basePath) { + var pathBuilder = new StringBuilder(basePath); + if (basePath.EndsWith("unityLibrary")) { + pathBuilder.Append(Path.DirectorySeparatorChar).Append(".."); + } + pathBuilder.Append(Path.DirectorySeparatorChar).Append("gradle.properties"); + return pathBuilder.ToString(); + } + //// for others [PostProcessBuild(100)] @@ -80,6 +139,24 @@ public static void OnPostprocessBuild(BuildTarget buildTarget, string path) { 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/core.*.aar$")) { + 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