Skip to content

Commit fdcbb36

Browse files
author
Stewart Miles
committed
Added option to auto-resolve Android libraries on build.
*If* Callbacks.PostProcessSceneAttribute(0) is called before the Android build (Unity version specific) Android auto-resolution will run if it's enabled. This adds a setting to that will enable / disable resolution during the build process without affecting interactive auto-resolution. Fixes googlesamples#196 Bug: 132072419 Change-Id: Idba8ffa249952b2288adc6653f11458b5089725f
1 parent a7a76d7 commit fdcbb36

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

source/PlayServicesResolver/src/PlayServicesPreBuild.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private static void WarnIfAutoResolveDisabled() {
1818
return;
1919

2020
if (SettingsDialog.AutoResolutionDisabledWarning &&
21-
!SettingsDialog.EnableAutoResolution) {
21+
!(SettingsDialog.EnableAutoResolution || SettingsDialog.AutoResolveOnBuild)) {
2222
Debug.LogWarning("Warning: Auto-resolution of Android dependencies is disabled! " +
2323
"Ensure you have run the resolver manually." +
2424
"\n\nWith auto-resolution of Android dependencies disabled you " +
@@ -41,4 +41,4 @@ private static void BuildComplete(BuildTarget target, string pathToBuiltProject)
4141
HasWarned = false;
4242
}
4343
}
44-
}
44+
}

source/PlayServicesResolver/src/PlayServicesResolver.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,9 @@ private static void OnPostProcessScene() {
880880
if (UnityEngine.Application.isPlaying) return;
881881
// If the Android resolver isn't enabled or automatic resolution is disabled,
882882
// do nothing.
883-
if (Resolver == null || !Resolver.AutomaticResolutionEnabled()) return;
883+
if (Resolver == null || !GooglePlayServices.SettingsDialog.AutoResolveOnBuild) {
884+
return;
885+
}
884886
// If post-processing has already been executed since this module was loaded, don't
885887
// do so again.
886888
scenesProcessed++;

source/PlayServicesResolver/src/SettingsDialog.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class SettingsDialog : EditorWindow {
3030
/// </summary>
3131
private class Settings {
3232
internal bool enableAutoResolution;
33+
internal bool autoResolveOnBuild;
3334
internal bool useGradleDaemon;
3435
internal bool installAndroidPackages;
3536
internal string packageDir;
@@ -45,6 +46,7 @@ private class Settings {
4546
/// </summary>
4647
internal Settings() {
4748
enableAutoResolution = SettingsDialog.EnableAutoResolution;
49+
autoResolveOnBuild = SettingsDialog.AutoResolveOnBuild;
4850
useGradleDaemon = SettingsDialog.UseGradleDaemon;
4951
installAndroidPackages = SettingsDialog.InstallAndroidPackages;
5052
packageDir = SettingsDialog.PackageDir;
@@ -62,6 +64,7 @@ internal Settings() {
6264
internal void Save() {
6365
SettingsDialog.UseGradleDaemon = useGradleDaemon;
6466
SettingsDialog.EnableAutoResolution = enableAutoResolution;
67+
SettingsDialog.AutoResolveOnBuild = autoResolveOnBuild;
6568
SettingsDialog.InstallAndroidPackages = installAndroidPackages;
6669
if (SettingsDialog.ConfigurablePackageDir) SettingsDialog.PackageDir = packageDir;
6770
SettingsDialog.ExplodeAars = explodeAars;
@@ -75,6 +78,7 @@ internal void Save() {
7578

7679
const string Namespace = "GooglePlayServices.";
7780
private const string AutoResolveKey = Namespace + "AutoResolverEnabled";
81+
private const string AutoResolveOnBuildKey = Namespace + "AutoResolveOnBuild";
7882
private const string PackageInstallKey = Namespace + "AndroidPackageInstallationEnabled";
7983
private const string PackageDirKey = Namespace + "PackageDirectory";
8084
private const string ExplodeAarsKey = Namespace + "ExplodeAars";
@@ -89,6 +93,7 @@ internal void Save() {
8993
// List of preference keys, used to restore default settings.
9094
private static string[] PreferenceKeys = new[] {
9195
AutoResolveKey,
96+
AutoResolveOnBuildKey,
9297
PackageInstallKey,
9398
PackageDirKey,
9499
ExplodeAarsKey,
@@ -133,6 +138,13 @@ internal static bool EnableAutoResolution {
133138
get { return projectSettings.GetBool(AutoResolveKey, true); }
134139
}
135140

141+
internal static bool AutoResolveOnBuild {
142+
set {
143+
projectSettings.SetBool(AutoResolveOnBuildKey, value);
144+
}
145+
get { return projectSettings.GetBool(AutoResolveOnBuildKey, true); }
146+
}
147+
136148
internal static bool UseGradleDaemon {
137149
private set { projectSettings.SetBool(UseGradleDaemonKey, value); }
138150
get { return projectSettings.GetBool(UseGradleDaemonKey, false); }
@@ -179,7 +191,7 @@ internal static bool UseProjectSettings {
179191
// Whether AARs that use variable expansion should be exploded when Gradle builds are
180192
// enabled.
181193
internal static bool ExplodeAars {
182-
private set { projectSettings.SetBool(ExplodeAarsKey, value); }
194+
set { projectSettings.SetBool(ExplodeAarsKey, value); }
183195
get { return projectSettings.GetBool(ExplodeAarsKey, true); }
184196
}
185197

@@ -231,7 +243,7 @@ internal static string ValidatePackageDir(string directory) {
231243
}
232244

233245
public void Initialize() {
234-
minSize = new Vector2(350, 425);
246+
minSize = new Vector2(425, 445);
235247
position = new Rect(UnityEngine.Screen.width / 3, UnityEngine.Screen.height / 3,
236248
minSize.x, minSize.y);
237249
}
@@ -265,6 +277,19 @@ public void OnGUI() {
265277
GUILayout.Label("Enable Auto-Resolution", EditorStyles.boldLabel);
266278
settings.enableAutoResolution = EditorGUILayout.Toggle(settings.enableAutoResolution);
267279
GUILayout.EndHorizontal();
280+
GUILayout.Label(
281+
settings.enableAutoResolution ?
282+
("Android libraries will be downloaded and processed in the editor.") :
283+
("Android libraries will *not* be downloaded or processed in the editor."));
284+
285+
GUILayout.BeginHorizontal();
286+
GUILayout.Label("Enable Resolution On Build", EditorStyles.boldLabel);
287+
settings.autoResolveOnBuild = EditorGUILayout.Toggle(settings.autoResolveOnBuild);
288+
GUILayout.EndHorizontal();
289+
GUILayout.Label(
290+
settings.autoResolveOnBuild ?
291+
("Android libraries will be downloaded and processed in a pre-build step.") :
292+
("Android libraries will *not* be downloaded or processed in a pre-build step."));
268293

269294
GUILayout.BeginHorizontal();
270295
GUILayout.Label("Install Android Packages", EditorStyles.boldLabel);
@@ -308,7 +333,8 @@ public void OnGUI() {
308333

309334
// Disable the ability to toggle the auto-resolution disabled warning
310335
// when auto resolution is enabled.
311-
EditorGUI.BeginDisabledGroup(settings.enableAutoResolution);
336+
EditorGUI.BeginDisabledGroup(settings.enableAutoResolution ||
337+
settings.autoResolveOnBuild);
312338
GUILayout.BeginHorizontal();
313339
GUILayout.Label("Auto-Resolution Disabled Warning", EditorStyles.boldLabel);
314340
settings.autoResolutionDisabledWarning =

0 commit comments

Comments
 (0)