Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adjusted not to directly include core*.aar. #744

Merged
merged 2 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions dist/package/Assets/Plugins/Android/core-1.6.0.aar.meta

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/Android/install-nofragment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion plugins/Android/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion plugins/Android/webview-nofragment/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ android {
}

dependencies {
compileOnly files('./libs/classes.jar')
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
}
2 changes: 1 addition & 1 deletion plugins/Android/webview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ android {
}

dependencies {
compileOnly files('./libs/classes.jar')
compileOnly fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.core:core:1.6.0'
}
Empty file.
Binary file removed plugins/Android/webview/libs/core-1.6.0.aar
Binary file not shown.
77 changes: 77 additions & 0 deletions plugins/Editor/UnityWebViewPostprocessBuild.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<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 '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
Expand Down Expand Up @@ -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)]
Expand All @@ -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
Expand Down