Skip to content

Add two Android Resolver settings related to custom local Maven repo path #604

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

Merged
merged 2 commits into from
Mar 23, 2023
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
22 changes: 16 additions & 6 deletions source/AndroidResolver/src/PlayServicesResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2120,16 +2120,24 @@ internal static IList<string> GradleMavenReposLines(ICollection<Dependency> depe
var lines = new List<string>();
if (dependencies.Count > 0) {
var exportEnabled = GradleProjectExportEnabled;
var useFullPath = (
exportEnabled &&
SettingsDialogObj.UseFullCustomMavenRepoPathWhenExport ) || (
!exportEnabled &&
SettingsDialogObj.UseFullCustomMavenRepoPathWhenNotExport);

var projectPath = FileUtils.PosixPathSeparators(Path.GetFullPath("."));
var projectFileUri = GradleResolver.RepoPathToUri(projectPath);
lines.Add("([rootProject] + (rootProject.subprojects as List)).each { project ->");
lines.Add(" project.repositories {");
// projectPath will point to the Unity project root directory as Unity will
// generate the root Gradle project in "Temp/gradleOut" when *not* exporting a
// gradle project.
lines.Add(String.Format(
" def unityProjectPath = $/{0}**DIR_UNITYPROJECT**/$" +
".replace(\"\\\\\", \"/\")", GradleWrapper.FILE_SCHEME));
if (!useFullPath) {
lines.Add(String.Format(
" def unityProjectPath = $/{0}**DIR_UNITYPROJECT**/$" +
".replace(\"\\\\\", \"/\")", GradleWrapper.FILE_SCHEME));
}
lines.Add(" maven {");
lines.Add(" url \"https://maven.google.com\"");
lines.Add(" }");
Expand All @@ -2154,9 +2162,7 @@ internal static IList<string> GradleMavenReposLines(ICollection<Dependency> depe
repoPath = relativePath;
}

// If "Export Gradle Project" setting is enabled, gradle project expects
// absolute path.
if (exportEnabled) {
if (useFullPath) {
// build.gradle expects file:/// URI so file separator will be "/" in anycase
// and we must NOT use Path.Combine here because it will use "\" for win platforms
repoUri = String.Format("\"{0}/{1}\"", projectFileUri, repoPath);
Expand Down Expand Up @@ -2541,6 +2547,8 @@ internal static Dictionary<string, string> GetResolutionSettings() {
{"explodeAars", SettingsDialogObj.ExplodeAars.ToString()},
{"patchAndroidManifest", SettingsDialogObj.PatchAndroidManifest.ToString()},
{"patchMainTemplateGradle", SettingsDialogObj.PatchMainTemplateGradle.ToString()},
{"useFullCustomMavenRepoPathWhenExport", SettingsDialogObj.UseFullCustomMavenRepoPathWhenExport.ToString()},
{"useFullCustomMavenRepoPathWhenNotExport", SettingsDialogObj.UseFullCustomMavenRepoPathWhenNotExport.ToString()},
{"localMavenRepoDir", SettingsDialogObj.LocalMavenRepoDir.ToString()},
{"useJetifier", SettingsDialogObj.UseJetifier.ToString()},
{"bundleId", GetAndroidApplicationId()},
Expand All @@ -2558,6 +2566,8 @@ internal static Dictionary<string, string> GetResolutionSettings() {
"explodeAars",
"patchAndroidManifest",
"patchMainTemplateGradle",
"useFullCustomMavenRepoPathWhenExport",
"useFullCustomMavenRepoPathWhenNotExport",
"localMavenRepoDir",
"useJetifier",
"gradleBuildEnabled",
Expand Down
73 changes: 71 additions & 2 deletions source/AndroidResolver/src/SettingsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ private class Settings {
internal bool patchAndroidManifest;
internal bool patchMainTemplateGradle;
internal bool patchPropertiesTemplateGradle;
internal bool useFullCustomMavenRepoPathWhenExport;
internal bool useFullCustomMavenRepoPathWhenNotExport;
internal string localMavenRepoDir;
internal bool useJetifier;
internal bool verboseLogging;
Expand All @@ -60,6 +62,8 @@ internal Settings() {
patchAndroidManifest = SettingsDialog.PatchAndroidManifest;
patchMainTemplateGradle = SettingsDialog.PatchMainTemplateGradle;
patchPropertiesTemplateGradle = SettingsDialog.PatchPropertiesTemplateGradle;
useFullCustomMavenRepoPathWhenExport = SettingsDialog.UseFullCustomMavenRepoPathWhenExport;
useFullCustomMavenRepoPathWhenNotExport = SettingsDialog.UseFullCustomMavenRepoPathWhenNotExport;
localMavenRepoDir = SettingsDialog.LocalMavenRepoDir;
useJetifier = SettingsDialog.UseJetifier;
verboseLogging = SettingsDialog.VerboseLogging;
Expand All @@ -82,6 +86,8 @@ internal void Save() {
SettingsDialog.PatchAndroidManifest = patchAndroidManifest;
SettingsDialog.PatchMainTemplateGradle = patchMainTemplateGradle;
SettingsDialog.PatchPropertiesTemplateGradle = patchPropertiesTemplateGradle;
SettingsDialog.UseFullCustomMavenRepoPathWhenExport = useFullCustomMavenRepoPathWhenExport;
SettingsDialog.UseFullCustomMavenRepoPathWhenNotExport = useFullCustomMavenRepoPathWhenNotExport;
SettingsDialog.LocalMavenRepoDir = localMavenRepoDir;
SettingsDialog.UseJetifier = useJetifier;
SettingsDialog.VerboseLogging = verboseLogging;
Expand All @@ -101,6 +107,8 @@ internal void Save() {
private const string PatchAndroidManifestKey = Namespace + "PatchAndroidManifest";
private const string PatchMainTemplateGradleKey = Namespace + "PatchMainTemplateGradle";
private const string PatchPropertiesTemplateGradleKey = Namespace + "PatchPropertiesTemplateGradle";
private const string UseFullCustomMavenRepoPathWhenExportKey = Namespace + "UseFullCustomMavenRepoPathWhenExport";
private const string UseFullCustomMavenRepoPathWhenNotExportKey = Namespace + "UseFullCustomMavenRepoPathWhenNotExport";
private const string LocalMavenRepoDirKey = Namespace + "LocalMavenRepoDir";
private const string UseJetifierKey = Namespace + "UseJetifier";
private const string VerboseLoggingKey = Namespace + "VerboseLogging";
Expand All @@ -120,6 +128,8 @@ internal void Save() {
PatchAndroidManifestKey,
PatchMainTemplateGradleKey,
PatchPropertiesTemplateGradleKey,
UseFullCustomMavenRepoPathWhenExportKey,
UseFullCustomMavenRepoPathWhenNotExportKey,
LocalMavenRepoDirKey,
UseJetifierKey,
VerboseLoggingKey,
Expand Down Expand Up @@ -245,6 +255,16 @@ internal static bool PatchPropertiesTemplateGradle {
get { return projectSettings.GetBool(PatchPropertiesTemplateGradleKey, true); }
}

internal static bool UseFullCustomMavenRepoPathWhenExport {
set { projectSettings.SetBool(UseFullCustomMavenRepoPathWhenExportKey, value); }
get { return projectSettings.GetBool(UseFullCustomMavenRepoPathWhenExportKey, true); }
}

internal static bool UseFullCustomMavenRepoPathWhenNotExport {
set { projectSettings.SetBool(UseFullCustomMavenRepoPathWhenNotExportKey, value); }
get { return projectSettings.GetBool(UseFullCustomMavenRepoPathWhenNotExportKey, false); }
}

internal static string LocalMavenRepoDir {
private set { projectSettings.SetString(LocalMavenRepoDirKey, value); }
get {
Expand Down Expand Up @@ -337,6 +357,8 @@ public void OnEnable() {
/// Called when the GUI should be rendered.
/// </summary>
public void OnGUI() {
GUI.skin.label.wordWrap = true;

GUILayout.BeginVertical();
GUILayout.Label(String.Format("Android Resolver (version {0}.{1}.{2})",
AndroidResolverVersionNumber.Value.Major,
Expand Down Expand Up @@ -477,6 +499,44 @@ public void OnGUI() {
}

if (settings.patchMainTemplateGradle) {
GUILayout.Label("Use Full Custom Local Maven Repo Path", EditorStyles.boldLabel);
GUILayout.BeginHorizontal();
GUILayout.Label(" When building Android app through Unity", EditorStyles.boldLabel);
settings.useFullCustomMavenRepoPathWhenNotExport =
EditorGUILayout.Toggle(settings.useFullCustomMavenRepoPathWhenNotExport);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label(" When exporting Android project", EditorStyles.boldLabel);
settings.useFullCustomMavenRepoPathWhenExport =
EditorGUILayout.Toggle(settings.useFullCustomMavenRepoPathWhenExport);
GUILayout.EndHorizontal();

GUILayout.Label(
"EDM4U can inject custom local Maven repo to Gradle template files " +
"differnetly depending on whether 'Export Project' in Build Settings is " +
"enabled or not.\n" +
"If checked, custom local Maven repo path will look like the following. " +
"This is best if the Unity project is always under the same path, or when " +
"Unity editor has bugs which fail to resolve template variables like " +
"'**DIR_UNITYPROJECT**'");
GUILayout.Box(
" maven {\n" +
" url \"file:////path/to/myUnityProject/path/to/m2repository\"\n" +
" }", EditorStyles.wordWrappedMiniLabel);
GUILayout.Label(
"If unchecked, custom local Maven repo path will look like the following. " +
"This is best if the Unity projects locates in different folders on " +
"different workstations. 'unityProjectPath' will be resolved at build time " +
"using template variables like '**DIR_UNITYPROJECT**'");
GUILayout.Box(
" def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace(\"\\\", \"/\")\n" +
" maven {\n" +
" url (unityProjectPath + \"/path/to/m2repository\")\n" +
" }", EditorStyles.wordWrappedMiniLabel);
GUILayout.Label(
"Note that EDM4U always uses full path if the custom local Maven repo is NOT " +
"under Unity project folder.");

GUILayout.BeginHorizontal();
string previousDir = settings.localMavenRepoDir;
GUILayout.Label("Local Maven Repo Directory", EditorStyles.boldLabel);
Expand Down Expand Up @@ -543,6 +603,10 @@ public void OnGUI() {
settings.useProjectSettings = EditorGUILayout.Toggle(settings.useProjectSettings);
GUILayout.EndHorizontal();

GUILayout.EndVertical();
EditorGUILayout.EndScrollView();

GUILayout.BeginVertical();
GUILayout.Space(10);

if (GUILayout.Button("Reset to Defaults")) {
Expand Down Expand Up @@ -581,6 +645,12 @@ public void OnGUI() {
new KeyValuePair<string, string>(
"patchAndroidManifest",
SettingsDialog.PatchAndroidManifest.ToString()),
new KeyValuePair<string, string>(
"UseFullCustomMavenRepoPathWhenNotExport",
SettingsDialog.UseFullCustomMavenRepoPathWhenNotExport.ToString()),
new KeyValuePair<string, string>(
"UseFullCustomMavenRepoPathWhenExport",
SettingsDialog.UseFullCustomMavenRepoPathWhenExport.ToString()),
new KeyValuePair<string, string>(
"localMavenRepoDir",
SettingsDialog.LocalMavenRepoDir.ToString()),
Expand All @@ -604,9 +674,8 @@ public void OnGUI() {
}
if (closeWindow) Close();
GUILayout.EndHorizontal();

GUILayout.EndVertical();
EditorGUILayout.EndScrollView();

GUILayout.EndVertical();
}
}
Expand Down