@@ -18,6 +18,7 @@ namespace GooglePlayServices {
18
18
using System ;
19
19
using System . Collections . Generic ;
20
20
using System . IO ;
21
+ using System . Linq ;
21
22
using System . Text . RegularExpressions ;
22
23
using System . Threading ;
23
24
using System . Xml ;
@@ -1747,7 +1748,7 @@ private static void ScheduleResolve(bool forceResolution, bool closeWindowOnComp
1747
1748
new ResolutionJob (
1748
1749
isAutoResolveJob ,
1749
1750
( ) => {
1750
- ResolveUnsafeAfterJetifierCheck (
1751
+ ResolveUnsafeAfterMainTemplateCheck (
1751
1752
( success ) => {
1752
1753
SignalResolveJobComplete ( ( ) => {
1753
1754
if ( resolutionCompleteWithResult != null ) {
@@ -1763,6 +1764,72 @@ private static void ScheduleResolve(bool forceResolution, bool closeWindowOnComp
1763
1764
if ( firstJob ) ExecuteNextResolveJob ( ) ;
1764
1765
}
1765
1766
1767
+ /// <summary>
1768
+ /// Ensures that the mainTemplate.gradle and gradle.properties files are present in the project,
1769
+ /// creating them via the Unity Editor's template files if needed.
1770
+ /// </summary>
1771
+ /// <returns>True if both files are present.</returns>
1772
+ private static bool EnableGradleTemplates ( ) {
1773
+ return GradleTemplateResolver . EnsureGradleTemplateEnabled ( GradleTemplateResolver . GradleTemplateFilename ) &&
1774
+ GradleTemplateResolver . EnsureGradleTemplateEnabled ( GradleTemplateResolver . GradlePropertiesTemplateFilename ) ;
1775
+ }
1776
+
1777
+ /// <summary>
1778
+ /// Resolve dependencies after checking if mainTemplate.gradle is enabled (or previously disabled).
1779
+ /// </summary>
1780
+ /// <param name="resolutionComplete">Delegate called when resolution is complete
1781
+ /// with a parameter that indicates whether it succeeded or failed.</param>
1782
+ /// <param name="forceResolution">Whether resolution should be executed when no dependencies
1783
+ /// have changed. This is useful if a dependency specifies a wildcard in the version
1784
+ /// expression.</param>
1785
+ /// <param name="isAutoResolveJob">Whether this is an auto-resolution job.</param>
1786
+ /// <param name="closeWindowOnCompletion">Whether to unconditionally close the resolution
1787
+ /// window when complete.</param>
1788
+ private static void ResolveUnsafeAfterMainTemplateCheck ( Action < bool > resolutionComplete ,
1789
+ bool forceResolution ,
1790
+ bool isAutoResolveJob ,
1791
+ bool closeWindowOnCompletion ) {
1792
+ // If mainTemplate.gradle is already enabled, or if the user has rejected the switch,
1793
+ // move to the next step.
1794
+ if ( GradleTemplateEnabled ||
1795
+ SettingsDialogObj . UserRejectedGradleUpgrade ) {
1796
+ ResolveUnsafeAfterJetifierCheck ( resolutionComplete , forceResolution , isAutoResolveJob , closeWindowOnCompletion ) ;
1797
+ return ;
1798
+ }
1799
+
1800
+ // Else, if there are no resolved files tracked by this (aka, it hasn't been run before),
1801
+ // turn on mainTemplate, and log a message to the user.
1802
+ // Or, if using Batch mode, we want to enable the templates as well, since that is now the
1803
+ // desired default behavior. If Users want to preserve the old method, they can save their
1804
+ // SettingsObject with the UserRejectedGradleUpgrade option enabled.
1805
+ if ( ExecutionEnvironment . InBatchMode || ! PlayServicesResolver . FindLabeledAssets ( ) . Any ( ) ) {
1806
+ EnableGradleTemplates ( ) ;
1807
+ ResolveUnsafeAfterJetifierCheck ( resolutionComplete , forceResolution , isAutoResolveJob , closeWindowOnCompletion ) ;
1808
+ return ;
1809
+ }
1810
+
1811
+ // Else, prompt the user to turn it on for them.
1812
+ DialogWindow . Display (
1813
+ "Enable Android Gradle templates?" ,
1814
+ "Android Resolver recommends using Gradle templates " +
1815
+ "for managing Android dependencies. The old method of downloading " +
1816
+ "the dependencies into Plugins/Android is no longer recommended." ,
1817
+ DialogWindow . Option . Selected0 , "Enable" , "Disable" ,
1818
+ complete : ( selectedOption ) => {
1819
+ switch ( selectedOption ) {
1820
+ case DialogWindow . Option . Selected0 : // Enable
1821
+ EnableGradleTemplates ( ) ;
1822
+ break ;
1823
+ case DialogWindow . Option . Selected1 : // Disable
1824
+ SettingsDialogObj . UserRejectedGradleUpgrade = true ;
1825
+ break ;
1826
+ }
1827
+
1828
+ // Either way, proceed with the resolution.
1829
+ ResolveUnsafeAfterJetifierCheck ( resolutionComplete , forceResolution , isAutoResolveJob , closeWindowOnCompletion ) ;
1830
+ } ) ;
1831
+ }
1832
+
1766
1833
/// <summary>
1767
1834
/// Resolve dependencies after checking the configuration is compatible with the Jetifier
1768
1835
/// settings.
0 commit comments