Skip to content

Commit dc19bd0

Browse files
committed
Add two Android Resolver settings related to custom local Maven repo path (googlesamples#604)
Adding two settings in Android Resolver settings to determine whether EDM4U inject custom local Maven repo path as a relative path or full path. Before this settings, EDM4U has internal logic to always use full path when exporting project and relative path when not. Provide the new options so that the developers can choose to make it consistent or use full path to avoid certain Unity bugs. Also improve Android Resolver Setting UI by moving buttons out of the scroll view so that they are always at the bottom of the setting windows.
1 parent b140d1f commit dc19bd0

File tree

2 files changed

+87
-8
lines changed

2 files changed

+87
-8
lines changed

source/AndroidResolver/src/PlayServicesResolver.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,16 +2120,24 @@ internal static IList<string> GradleMavenReposLines(ICollection<Dependency> depe
21202120
var lines = new List<string>();
21212121
if (dependencies.Count > 0) {
21222122
var exportEnabled = GradleProjectExportEnabled;
2123+
var useFullPath = (
2124+
exportEnabled &&
2125+
SettingsDialogObj.UseFullCustomMavenRepoPathWhenExport ) || (
2126+
!exportEnabled &&
2127+
SettingsDialogObj.UseFullCustomMavenRepoPathWhenNotExport);
2128+
21232129
var projectPath = FileUtils.PosixPathSeparators(Path.GetFullPath("."));
21242130
var projectFileUri = GradleResolver.RepoPathToUri(projectPath);
21252131
lines.Add("([rootProject] + (rootProject.subprojects as List)).each { project ->");
21262132
lines.Add(" project.repositories {");
21272133
// projectPath will point to the Unity project root directory as Unity will
21282134
// generate the root Gradle project in "Temp/gradleOut" when *not* exporting a
21292135
// gradle project.
2130-
lines.Add(String.Format(
2131-
" def unityProjectPath = $/{0}**DIR_UNITYPROJECT**/$" +
2132-
".replace(\"\\\\\", \"/\")", GradleWrapper.FILE_SCHEME));
2136+
if (!useFullPath) {
2137+
lines.Add(String.Format(
2138+
" def unityProjectPath = $/{0}**DIR_UNITYPROJECT**/$" +
2139+
".replace(\"\\\\\", \"/\")", GradleWrapper.FILE_SCHEME));
2140+
}
21332141
lines.Add(" maven {");
21342142
lines.Add(" url \"https://maven.google.com\"");
21352143
lines.Add(" }");
@@ -2154,9 +2162,7 @@ internal static IList<string> GradleMavenReposLines(ICollection<Dependency> depe
21542162
repoPath = relativePath;
21552163
}
21562164

2157-
// If "Export Gradle Project" setting is enabled, gradle project expects
2158-
// absolute path.
2159-
if (exportEnabled) {
2165+
if (useFullPath) {
21602166
// build.gradle expects file:/// URI so file separator will be "/" in anycase
21612167
// and we must NOT use Path.Combine here because it will use "\" for win platforms
21622168
repoUri = String.Format("\"{0}/{1}\"", projectFileUri, repoPath);
@@ -2541,6 +2547,8 @@ internal static Dictionary<string, string> GetResolutionSettings() {
25412547
{"explodeAars", SettingsDialogObj.ExplodeAars.ToString()},
25422548
{"patchAndroidManifest", SettingsDialogObj.PatchAndroidManifest.ToString()},
25432549
{"patchMainTemplateGradle", SettingsDialogObj.PatchMainTemplateGradle.ToString()},
2550+
{"useFullCustomMavenRepoPathWhenExport", SettingsDialogObj.UseFullCustomMavenRepoPathWhenExport.ToString()},
2551+
{"useFullCustomMavenRepoPathWhenNotExport", SettingsDialogObj.UseFullCustomMavenRepoPathWhenNotExport.ToString()},
25442552
{"localMavenRepoDir", SettingsDialogObj.LocalMavenRepoDir.ToString()},
25452553
{"useJetifier", SettingsDialogObj.UseJetifier.ToString()},
25462554
{"bundleId", GetAndroidApplicationId()},
@@ -2558,6 +2566,8 @@ internal static Dictionary<string, string> GetResolutionSettings() {
25582566
"explodeAars",
25592567
"patchAndroidManifest",
25602568
"patchMainTemplateGradle",
2569+
"useFullCustomMavenRepoPathWhenExport",
2570+
"useFullCustomMavenRepoPathWhenNotExport",
25612571
"localMavenRepoDir",
25622572
"useJetifier",
25632573
"gradleBuildEnabled",

source/AndroidResolver/src/SettingsDialog.cs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ private class Settings {
3939
internal bool patchAndroidManifest;
4040
internal bool patchMainTemplateGradle;
4141
internal bool patchPropertiesTemplateGradle;
42+
internal bool useFullCustomMavenRepoPathWhenExport;
43+
internal bool useFullCustomMavenRepoPathWhenNotExport;
4244
internal string localMavenRepoDir;
4345
internal bool useJetifier;
4446
internal bool verboseLogging;
@@ -60,6 +62,8 @@ internal Settings() {
6062
patchAndroidManifest = SettingsDialog.PatchAndroidManifest;
6163
patchMainTemplateGradle = SettingsDialog.PatchMainTemplateGradle;
6264
patchPropertiesTemplateGradle = SettingsDialog.PatchPropertiesTemplateGradle;
65+
useFullCustomMavenRepoPathWhenExport = SettingsDialog.UseFullCustomMavenRepoPathWhenExport;
66+
useFullCustomMavenRepoPathWhenNotExport = SettingsDialog.UseFullCustomMavenRepoPathWhenNotExport;
6367
localMavenRepoDir = SettingsDialog.LocalMavenRepoDir;
6468
useJetifier = SettingsDialog.UseJetifier;
6569
verboseLogging = SettingsDialog.VerboseLogging;
@@ -82,6 +86,8 @@ internal void Save() {
8286
SettingsDialog.PatchAndroidManifest = patchAndroidManifest;
8387
SettingsDialog.PatchMainTemplateGradle = patchMainTemplateGradle;
8488
SettingsDialog.PatchPropertiesTemplateGradle = patchPropertiesTemplateGradle;
89+
SettingsDialog.UseFullCustomMavenRepoPathWhenExport = useFullCustomMavenRepoPathWhenExport;
90+
SettingsDialog.UseFullCustomMavenRepoPathWhenNotExport = useFullCustomMavenRepoPathWhenNotExport;
8591
SettingsDialog.LocalMavenRepoDir = localMavenRepoDir;
8692
SettingsDialog.UseJetifier = useJetifier;
8793
SettingsDialog.VerboseLogging = verboseLogging;
@@ -101,6 +107,8 @@ internal void Save() {
101107
private const string PatchAndroidManifestKey = Namespace + "PatchAndroidManifest";
102108
private const string PatchMainTemplateGradleKey = Namespace + "PatchMainTemplateGradle";
103109
private const string PatchPropertiesTemplateGradleKey = Namespace + "PatchPropertiesTemplateGradle";
110+
private const string UseFullCustomMavenRepoPathWhenExportKey = Namespace + "UseFullCustomMavenRepoPathWhenExport";
111+
private const string UseFullCustomMavenRepoPathWhenNotExportKey = Namespace + "UseFullCustomMavenRepoPathWhenNotExport";
104112
private const string LocalMavenRepoDirKey = Namespace + "LocalMavenRepoDir";
105113
private const string UseJetifierKey = Namespace + "UseJetifier";
106114
private const string VerboseLoggingKey = Namespace + "VerboseLogging";
@@ -120,6 +128,8 @@ internal void Save() {
120128
PatchAndroidManifestKey,
121129
PatchMainTemplateGradleKey,
122130
PatchPropertiesTemplateGradleKey,
131+
UseFullCustomMavenRepoPathWhenExportKey,
132+
UseFullCustomMavenRepoPathWhenNotExportKey,
123133
LocalMavenRepoDirKey,
124134
UseJetifierKey,
125135
VerboseLoggingKey,
@@ -245,6 +255,16 @@ internal static bool PatchPropertiesTemplateGradle {
245255
get { return projectSettings.GetBool(PatchPropertiesTemplateGradleKey, true); }
246256
}
247257

258+
internal static bool UseFullCustomMavenRepoPathWhenExport {
259+
set { projectSettings.SetBool(UseFullCustomMavenRepoPathWhenExportKey, value); }
260+
get { return projectSettings.GetBool(UseFullCustomMavenRepoPathWhenExportKey, true); }
261+
}
262+
263+
internal static bool UseFullCustomMavenRepoPathWhenNotExport {
264+
set { projectSettings.SetBool(UseFullCustomMavenRepoPathWhenNotExportKey, value); }
265+
get { return projectSettings.GetBool(UseFullCustomMavenRepoPathWhenNotExportKey, false); }
266+
}
267+
248268
internal static string LocalMavenRepoDir {
249269
private set { projectSettings.SetString(LocalMavenRepoDirKey, value); }
250270
get {
@@ -337,6 +357,8 @@ public void OnEnable() {
337357
/// Called when the GUI should be rendered.
338358
/// </summary>
339359
public void OnGUI() {
360+
GUI.skin.label.wordWrap = true;
361+
340362
GUILayout.BeginVertical();
341363
GUILayout.Label(String.Format("Android Resolver (version {0}.{1}.{2})",
342364
AndroidResolverVersionNumber.Value.Major,
@@ -477,6 +499,44 @@ public void OnGUI() {
477499
}
478500

479501
if (settings.patchMainTemplateGradle) {
502+
GUILayout.Label("Use Full Custom Local Maven Repo Path", EditorStyles.boldLabel);
503+
GUILayout.BeginHorizontal();
504+
GUILayout.Label(" When building Android app through Unity", EditorStyles.boldLabel);
505+
settings.useFullCustomMavenRepoPathWhenNotExport =
506+
EditorGUILayout.Toggle(settings.useFullCustomMavenRepoPathWhenNotExport);
507+
GUILayout.EndHorizontal();
508+
GUILayout.BeginHorizontal();
509+
GUILayout.Label(" When exporting Android project", EditorStyles.boldLabel);
510+
settings.useFullCustomMavenRepoPathWhenExport =
511+
EditorGUILayout.Toggle(settings.useFullCustomMavenRepoPathWhenExport);
512+
GUILayout.EndHorizontal();
513+
514+
GUILayout.Label(
515+
"EDM4U can inject custom local Maven repo to Gradle template files " +
516+
"differnetly depending on whether 'Export Project' in Build Settings is " +
517+
"enabled or not.\n" +
518+
"If checked, custom local Maven repo path will look like the following. " +
519+
"This is best if the Unity project is always under the same path, or when " +
520+
"Unity editor has bugs which fail to resolve template variables like " +
521+
"'**DIR_UNITYPROJECT**'");
522+
GUILayout.Box(
523+
" maven {\n" +
524+
" url \"file:////path/to/myUnityProject/path/to/m2repository\"\n" +
525+
" }", EditorStyles.wordWrappedMiniLabel);
526+
GUILayout.Label(
527+
"If unchecked, custom local Maven repo path will look like the following. " +
528+
"This is best if the Unity projects locates in different folders on " +
529+
"different workstations. 'unityProjectPath' will be resolved at build time " +
530+
"using template variables like '**DIR_UNITYPROJECT**'");
531+
GUILayout.Box(
532+
" def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace(\"\\\", \"/\")\n" +
533+
" maven {\n" +
534+
" url (unityProjectPath + \"/path/to/m2repository\")\n" +
535+
" }", EditorStyles.wordWrappedMiniLabel);
536+
GUILayout.Label(
537+
"Note that EDM4U always uses full path if the custom local Maven repo is NOT " +
538+
"under Unity project folder.");
539+
480540
GUILayout.BeginHorizontal();
481541
string previousDir = settings.localMavenRepoDir;
482542
GUILayout.Label("Local Maven Repo Directory", EditorStyles.boldLabel);
@@ -543,6 +603,10 @@ public void OnGUI() {
543603
settings.useProjectSettings = EditorGUILayout.Toggle(settings.useProjectSettings);
544604
GUILayout.EndHorizontal();
545605

606+
GUILayout.EndVertical();
607+
EditorGUILayout.EndScrollView();
608+
609+
GUILayout.BeginVertical();
546610
GUILayout.Space(10);
547611

548612
if (GUILayout.Button("Reset to Defaults")) {
@@ -581,6 +645,12 @@ public void OnGUI() {
581645
new KeyValuePair<string, string>(
582646
"patchAndroidManifest",
583647
SettingsDialog.PatchAndroidManifest.ToString()),
648+
new KeyValuePair<string, string>(
649+
"UseFullCustomMavenRepoPathWhenNotExport",
650+
SettingsDialog.UseFullCustomMavenRepoPathWhenNotExport.ToString()),
651+
new KeyValuePair<string, string>(
652+
"UseFullCustomMavenRepoPathWhenExport",
653+
SettingsDialog.UseFullCustomMavenRepoPathWhenExport.ToString()),
584654
new KeyValuePair<string, string>(
585655
"localMavenRepoDir",
586656
SettingsDialog.LocalMavenRepoDir.ToString()),
@@ -604,9 +674,8 @@ public void OnGUI() {
604674
}
605675
if (closeWindow) Close();
606676
GUILayout.EndHorizontal();
607-
608677
GUILayout.EndVertical();
609-
EditorGUILayout.EndScrollView();
678+
610679
GUILayout.EndVertical();
611680
}
612681
}

0 commit comments

Comments
 (0)