@@ -538,6 +538,12 @@ protected override bool Read(string filename, Logger logger) {
538
538
// Project level settings for this module.
539
539
private static ProjectSettings settings = new ProjectSettings ( PREFERENCE_NAMESPACE ) ;
540
540
541
+ /// <summary>
542
+ /// Polls for changes to TargetSdk.
543
+ /// </summary>
544
+ private static PlayServicesResolver . PropertyPoller < string > targetSdkPoller =
545
+ new PlayServicesResolver . PropertyPoller < string > ( "iOS Target SDK" ) ;
546
+
541
547
// Search for a file up to a maximum search depth stopping the
542
548
// depth first search each time the specified file is found.
543
549
private static List < string > FindFile (
@@ -676,7 +682,12 @@ exception is TypeInitializationException ||
676
682
! ExecutionEnvironment . InBatchMode ) {
677
683
RunOnMainThread . Run ( ( ) => { AutoInstallCocoapods ( ) ; } , runNow : false ) ;
678
684
}
679
-
685
+ // Install / remove target SDK property poller.
686
+ SetEnablePollTargetSdk ( PodfileGenerationEnabled ) ;
687
+ // Load XML dependencies on the next editor update.
688
+ if ( PodfileGenerationEnabled ) {
689
+ RunOnMainThread . Run ( RefreshXmlDependencies , runNow : false ) ;
690
+ }
680
691
681
692
// Prompt the user to use workspaces if they aren't at least using project level
682
693
// integration.
@@ -826,7 +837,21 @@ private static bool LegacyCocoapodsInstallEnabled {
826
837
public static bool PodfileGenerationEnabled {
827
838
get { return settings . GetBool ( PREFERENCE_PODFILE_GENERATION_ENABLED ,
828
839
defaultValue : true ) ; }
829
- set { settings . SetBool ( PREFERENCE_PODFILE_GENERATION_ENABLED , value ) ; }
840
+ set {
841
+ settings . SetBool ( PREFERENCE_PODFILE_GENERATION_ENABLED , value ) ;
842
+ SetEnablePollTargetSdk ( value ) ;
843
+ }
844
+ }
845
+
846
+ /// <summary>
847
+ /// Enable / disable target SDK polling.
848
+ /// </summary>
849
+ private static void SetEnablePollTargetSdk ( bool enable ) {
850
+ if ( enable && EditorUserBuildSettings . activeBuildTarget == BuildTarget . iOS ) {
851
+ RunOnMainThread . OnUpdate += PollTargetSdk ;
852
+ } else {
853
+ RunOnMainThread . OnUpdate -= PollTargetSdk ;
854
+ }
830
855
}
831
856
832
857
/// <summary>
@@ -1104,41 +1129,38 @@ private static void AddPodInternal(string podName,
1104
1129
return ;
1105
1130
}
1106
1131
pods [ podName ] = pod ;
1132
+ ScheduleCheckTargetSdk ( ) ;
1133
+ }
1107
1134
1108
- UpdateTargetSdk ( pod ) ;
1135
+ /// <summary>
1136
+ /// Determine whether the target SDK has changed.
1137
+ /// </summary>
1138
+ private static void PollTargetSdk ( ) {
1139
+ targetSdkPoller . Poll ( ( ) => TargetSdk ,
1140
+ ( previousValue , currentValue ) => { ScheduleCheckTargetSdk ( ) ; } ) ;
1109
1141
}
1110
1142
1143
+ // ID of the job which checks that the target SDK is correct for the currently selected set of
1144
+ // Cocoapods.
1145
+ private static int checkTargetSdkJobId = 0 ;
1146
+
1111
1147
/// <summary>
1112
- /// Update the iOS target SDK if it's lower than the minimum SDK
1113
- /// version specified by the pod .
1148
+ /// Schedule a check to ensure target SDK is configured correctly given the set of selected
1149
+ /// Cocoapods .
1114
1150
/// </summary>
1115
- /// <param name="pod">Pod to query for the minimum supported version.
1116
- /// </param>
1117
- /// <param name="notifyUser">Whether to write to the log to notify the
1118
- /// user of a build setting change.</param>
1119
- /// <returns>true if the SDK version was changed, false
1120
- /// otherwise.</returns>
1121
- private static bool UpdateTargetSdk ( Pod pod ,
1122
- bool notifyUser = true ) {
1123
- int currentVersion = TargetSdkVersion ;
1124
- int minVersion = pod . MinTargetSdkToVersion ( ) ;
1125
- if ( currentVersion >= minVersion ) {
1126
- return false ;
1127
- }
1128
- if ( notifyUser ) {
1129
- string oldSdk = TargetSdk ;
1130
- TargetSdkVersion = minVersion ;
1131
- Log ( "iOS Target SDK changed from " + oldSdk + " to " +
1132
- TargetSdk + " required by the " + pod . name + " pod" ) ;
1133
- }
1134
- return true ;
1151
+ private static void ScheduleCheckTargetSdk ( ) {
1152
+ RunOnMainThread . Cancel ( checkTargetSdkJobId ) ;
1153
+ checkTargetSdkJobId = RunOnMainThread . Schedule ( ( ) => {
1154
+ UpdateTargetSdk ( false ) ;
1155
+ } , 500.0 /* delay in milliseconds before running the check */ ) ;
1135
1156
}
1136
1157
1137
1158
/// <summary>
1138
1159
/// Update the target SDK if it's required.
1139
1160
/// </summary>
1161
+ /// <param name="runningBuild">Whether the build is being processed.</param>
1140
1162
/// <returns>true if the SDK was updated, false otherwise.</returns>
1141
- public static bool UpdateTargetSdk ( ) {
1163
+ public static bool UpdateTargetSdk ( bool runningBuild ) {
1142
1164
var minVersionAndPodNames = TargetSdkNeedsUpdate ( ) ;
1143
1165
if ( minVersionAndPodNames . Value != null ) {
1144
1166
var minVersionString =
@@ -1157,12 +1179,14 @@ public static bool UpdateTargetSdk() {
1157
1179
"Yes" , cancel : "No" ) ;
1158
1180
if ( update ) {
1159
1181
TargetSdkVersion = minVersionAndPodNames . Key ;
1160
- string errorString = (
1161
- "Target SDK has been updated from " + TargetSdk +
1162
- " to " + minVersionString + ". You must restart the " +
1163
- "build for this change to take effect." ) ;
1164
- EditorUtility . DisplayDialog (
1165
- "Target SDK updated." , errorString , "OK" ) ;
1182
+ if ( runningBuild ) {
1183
+ string errorString = (
1184
+ "Target SDK has been updated from " + TargetSdk +
1185
+ " to " + minVersionString + ". You must restart the " +
1186
+ "build for this change to take effect." ) ;
1187
+ EditorUtility . DisplayDialog (
1188
+ "Target SDK updated." , errorString , "OK" ) ;
1189
+ }
1166
1190
return true ;
1167
1191
}
1168
1192
}
@@ -1173,26 +1197,24 @@ public static bool UpdateTargetSdk() {
1173
1197
/// Determine whether the target SDK needs to be updated based upon pod
1174
1198
/// dependencies.
1175
1199
/// </summary>
1176
- /// <returns>Key value pair of minimum SDK version (key) and
1200
+ /// <returns>Key value pair of maximum of the minimum SDK versions (key) and
1177
1201
/// a list of pod names that require it (value) if the currently
1178
1202
/// selected target SDK version does not satisfy pod requirements, the list
1179
1203
/// (value) is null otherwise.</returns>
1180
1204
private static KeyValuePair < int , List < string > > TargetSdkNeedsUpdate ( ) {
1181
- var kvpair = new KeyValuePair < int , List < string > > ( 0 , null ) ;
1182
- var podListsByVersion = Pod . BucketByMinSdkVersion ( pods . Values ) ;
1183
- if ( podListsByVersion . Count == 0 ) {
1184
- return kvpair ;
1185
- }
1186
- KeyValuePair < int , List < string > > minVersionAndPodName = kvpair ;
1187
- foreach ( var versionAndPodList in podListsByVersion ) {
1188
- minVersionAndPodName = versionAndPodList ;
1189
- break ;
1190
- }
1191
- int currentVersion = TargetSdkVersion ;
1192
- if ( currentVersion >= minVersionAndPodName . Key ) {
1193
- return kvpair ;
1205
+ var emptyVersionAndPodNames = new KeyValuePair < int , List < string > > ( 0 , null ) ;
1206
+ var minVersionAndPodNames = emptyVersionAndPodNames ;
1207
+ int maxOfMinRequiredVersions = 0 ;
1208
+ foreach ( var versionAndPodList in Pod . BucketByMinSdkVersion ( pods . Values ) ) {
1209
+ if ( versionAndPodList . Key > maxOfMinRequiredVersions ) {
1210
+ maxOfMinRequiredVersions = versionAndPodList . Key ;
1211
+ minVersionAndPodNames = versionAndPodList ;
1212
+ }
1194
1213
}
1195
- return minVersionAndPodName ;
1214
+ // If the target SDK version exceeds the minimum required version return an empty tuple
1215
+ // otherwise return the minimum required SDK version and the set of pods that need it.
1216
+ return TargetSdkVersion >= maxOfMinRequiredVersions ? emptyVersionAndPodNames :
1217
+ minVersionAndPodNames ;
1196
1218
}
1197
1219
1198
1220
// Get the path of an xcode project relative to the specified directory.
@@ -1527,6 +1549,29 @@ public static void InstallCocoapods(bool interactive, string workingDirectory,
1527
1549
if ( ! interactive ) complete . WaitOne ( ) ;
1528
1550
}
1529
1551
1552
+ /// <summary>
1553
+ /// Called by Unity when all assets have been updated. This refreshes the Pods loaded from
1554
+ /// XML files.
1555
+ /// </summary>
1556
+ /// <param name="importedAssets">Imported assets. (unused)</param>
1557
+ /// <param name="deletedAssets">Deleted assets. (unused)</param>
1558
+ /// <param name="movedAssets">Moved assets. (unused)</param>
1559
+ /// <param name="movedFromAssetPaths">Moved from asset paths. (unused)</param>
1560
+ private static void OnPostprocessAllAssets ( string [ ] importedAssets ,
1561
+ string [ ] deletedAssets ,
1562
+ string [ ] movedAssets ,
1563
+ string [ ] movedFromAssetPaths ) {
1564
+ if ( ! CocoapodsIntegrationEnabled ) return ;
1565
+ bool dependencyFileChanged = false ;
1566
+ var changedAssets = new List < string > ( importedAssets ) ;
1567
+ changedAssets . AddRange ( deletedAssets ) ;
1568
+ foreach ( var asset in changedAssets ) {
1569
+ dependencyFileChanged = xmlDependencies . IsDependenciesFile ( asset ) ;
1570
+ if ( dependencyFileChanged ) break ;
1571
+ }
1572
+ if ( dependencyFileChanged ) RefreshXmlDependencies ( ) ;
1573
+ }
1574
+
1530
1575
/// <summary>
1531
1576
/// Refresh XML dependencies if the plugin is enabled.
1532
1577
/// </summary>
@@ -2150,7 +2195,7 @@ private static CommandLine.Result RunPodCommand(
2150
2195
public static void OnPostProcessInstallPods ( BuildTarget buildTarget ,
2151
2196
string pathToBuiltProject ) {
2152
2197
if ( ! InjectDependencies ( ) || ! PodfileGenerationEnabled ) return ;
2153
- if ( UpdateTargetSdk ( ) ) return ;
2198
+ if ( UpdateTargetSdk ( true ) ) return ;
2154
2199
if ( ! CocoapodsIntegrationEnabled || ! cocoapodsToolsInstallPresent ) {
2155
2200
Log ( String . Format (
2156
2201
"Cocoapod installation is disabled.\n " +
0 commit comments