@@ -667,35 +667,40 @@ private void GradleResolution(
667
667
668
668
}
669
669
// Process / explode copied AARs.
670
- ProcessAars ( destinationDirectory , new HashSet < string > ( copiedArtifacts ) ) ;
671
-
672
- // Look up the original Dependency structure for each missing artifact.
673
- var missingArtifactsAsDependencies = new List < Dependency > ( ) ;
674
- foreach ( var artifact in missingArtifacts ) {
675
- Dependency dep ;
676
- if ( ! allDependencies . TryGetValue ( artifact , out dep ) ) {
677
- // If this fails, something may have gone wrong with the Gradle script.
678
- // Rather than failing hard, fallback to recreating the Dependency
679
- // class with the partial data we have now.
680
- var components = new List < string > ( artifact . Split ( new char [ ] { ':' } ) ) ;
681
- if ( components . Count < 2 ) {
682
- PlayServicesResolver . Log (
683
- String . Format (
684
- "Found invalid missing artifact {0}\n " +
685
- "Something went wrong with the gradle artifact download " +
686
- "script\n ." +
687
- "Please report a bug" , artifact ) ,
688
- level : LogLevel . Warning ) ;
689
- continue ;
690
- } else if ( components . Count < 3 || components [ 2 ] == "+" ) {
691
- components . Add ( "LATEST" ) ;
670
+ ProcessAars (
671
+ destinationDirectory , new HashSet < string > ( copiedArtifacts ) ,
672
+ ( ) => {
673
+ // Look up the original Dependency structure for each missing artifact.
674
+ var missingArtifactsAsDependencies = new List < Dependency > ( ) ;
675
+ foreach ( var artifact in missingArtifacts ) {
676
+ Dependency dep ;
677
+ if ( ! allDependencies . TryGetValue ( artifact , out dep ) ) {
678
+ // If this fails, something may have gone wrong with the Gradle
679
+ // script. Rather than failing hard, fallback to recreating the
680
+ // Dependency class with the partial data we have now.
681
+ var components = new List < string > (
682
+ artifact . Split ( new char [ ] { ':' } ) ) ;
683
+ if ( components . Count < 2 ) {
684
+ PlayServicesResolver . Log (
685
+ String . Format (
686
+ "Found invalid missing artifact {0}\n " +
687
+ "Something went wrong with the gradle artifact " +
688
+ "download script\n ." +
689
+ "Please report a bug" , artifact ) ,
690
+ level : LogLevel . Warning ) ;
691
+ continue ;
692
+ } else if ( components . Count < 3 || components [ 2 ] == "+" ) {
693
+ components . Add ( "LATEST" ) ;
694
+ }
695
+ dep = new Dependency ( components [ 0 ] , components [ 1 ] , components [ 2 ] ) ;
696
+ }
697
+ missingArtifactsAsDependencies . Add ( dep ) ;
692
698
}
693
- dep = new Dependency ( components [ 0 ] , components [ 1 ] , components [ 2 ] ) ;
694
- }
695
- missingArtifactsAsDependencies . Add ( dep ) ;
696
- }
697
- if ( logErrorOnMissingArtifacts ) LogMissingDependenciesError ( missingArtifacts ) ;
698
- resolutionComplete ( missingArtifactsAsDependencies ) ;
699
+ if ( logErrorOnMissingArtifacts ) {
700
+ LogMissingDependenciesError ( missingArtifacts ) ;
701
+ }
702
+ resolutionComplete ( missingArtifactsAsDependencies ) ;
703
+ } ) ;
699
704
} ;
700
705
701
706
// Executes gradleComplete on the main thread.
@@ -1328,23 +1333,37 @@ private string FindAarInTargetPath(string aarPath) {
1328
1333
/// <param name="dir">The directory to process.</param>
1329
1334
/// <param name="updatedFiles">Set of files that were recently updated and should be
1330
1335
/// processed.</param>
1331
- /// <param name="displayProgress">Display a progress bar while processing.</param>
1332
- private void ProcessAars ( string dir , HashSet < string > updatedFiles ,
1333
- bool displayProgress = true ) {
1336
+ /// <param name="complete">Executed when this process is complete.</param>
1337
+ private void ProcessAars ( string dir , HashSet < string > updatedFiles , Action complete ) {
1334
1338
// Get set of AAR files and directories we're managing.
1335
- var aars = new HashSet < string > ( PlayServicesResolver . FindLabeledAssets ( ) ) ;
1336
- foreach ( var aarData in aarExplodeData . Values ) aars . Add ( aarData . path ) ;
1339
+ var uniqueAars = new HashSet < string > ( PlayServicesResolver . FindLabeledAssets ( ) ) ;
1340
+ foreach ( var aarData in aarExplodeData . Values ) uniqueAars . Add ( aarData . path ) ;
1341
+ var aars = new Queue < string > ( uniqueAars ) ;
1337
1342
1338
1343
const string progressBarTitle = "Processing AARs..." ;
1339
- float numberOfAars = ( float ) aars . Count ;
1340
- int aarIndex = 0 ;
1341
- displayProgress &= ( numberOfAars > 0 && ! ExecutionEnvironment . InBatchMode ) ;
1342
- try {
1343
- foreach ( string aarPath in aars ) {
1344
+ int numberOfAars = aars . Count ;
1345
+ bool displayProgress = ( numberOfAars > 0 && ! ExecutionEnvironment . InBatchMode ) ;
1346
+
1347
+ if ( numberOfAars == 0 ) {
1348
+ complete ( ) ;
1349
+ return ;
1350
+ }
1351
+ // EditorUtility.DisplayProgressBar can't be called multiple times per UI thread tick
1352
+ // in some versions of Unity so perform increment processing on each UI thread tick.
1353
+ RunOnMainThread . PollOnUpdateUntilComplete ( ( ) => {
1354
+ int remainingAars = aars . Count ;
1355
+ bool allAarsProcessed = remainingAars == 0 ;
1356
+ // Since the completion callback can trigger an update, remove this closure from
1357
+ // the polling job list if complete.
1358
+ if ( allAarsProcessed ) return true ;
1359
+ int processedAars = numberOfAars - remainingAars ;
1360
+ string aarPath = aars . Dequeue ( ) ;
1361
+ remainingAars -- ;
1362
+ allAarsProcessed = remainingAars == 0 ;
1363
+ float progress = ( float ) processedAars / ( float ) numberOfAars ;
1364
+ try {
1344
1365
if ( displayProgress ) {
1345
- EditorUtility . DisplayProgressBar ( progressBarTitle , aarPath ,
1346
- ( float ) aarIndex / numberOfAars ) ;
1347
- aarIndex ++ ;
1366
+ EditorUtility . DisplayProgressBar ( progressBarTitle , aarPath , progress ) ;
1348
1367
}
1349
1368
bool explode = ShouldExplode ( aarPath ) ;
1350
1369
var aarData = FindAarExplodeDataEntry ( aarPath ) ;
@@ -1365,7 +1384,8 @@ private void ProcessAars(string dir, HashSet<string> updatedFiles,
1365
1384
} else if ( aarPath != aarData . path ) {
1366
1385
// Clean up previously expanded / exploded versions of the AAR.
1367
1386
PlayServicesResolver . Log (
1368
- String . Format ( "Cleaning up previously exploded AAR {0}" , aarPath ) ,
1387
+ String . Format ( "Cleaning up previously exploded AAR {0}" ,
1388
+ aarPath ) ,
1369
1389
level : LogLevel . Verbose ) ;
1370
1390
FileUtils . DeleteExistingFileOrDirectory (
1371
1391
DetermineExplodedAarPath ( aarPath ) ) ;
@@ -1374,11 +1394,15 @@ private void ProcessAars(string dir, HashSet<string> updatedFiles,
1374
1394
aarData . gradleExport = PlayServicesResolver . GradleProjectExportEnabled ;
1375
1395
aarData . TargetAbis = AndroidAbis . Current ;
1376
1396
}
1397
+ SaveAarExplodeCache ( ) ;
1398
+ } finally {
1399
+ if ( allAarsProcessed ) {
1400
+ if ( displayProgress ) EditorUtility . ClearProgressBar ( ) ;
1401
+ complete ( ) ;
1402
+ }
1377
1403
}
1378
- SaveAarExplodeCache ( ) ;
1379
- } finally {
1380
- if ( displayProgress ) EditorUtility . ClearProgressBar ( ) ;
1381
- }
1404
+ return allAarsProcessed ;
1405
+ } ) ;
1382
1406
}
1383
1407
1384
1408
/// <summary>
0 commit comments