@@ -48,7 +48,7 @@ class FlutterExtension {
48
48
* Specifies the relative directory to the Flutter project directory.
49
49
* In an app project, this is ../.. since the app's build.gradle is under android/app.
50
50
*/
51
- String source
51
+ String source = ' ../.. '
52
52
53
53
/* * Allows to override the target file. Otherwise, the target is lib/main.dart. */
54
54
String target
@@ -418,7 +418,7 @@ class FlutterPlugin implements Plugin<Project> {
418
418
419
419
/**
420
420
* Compares semantic versions ignoring labels.
421
- *
421
+ *
422
422
* If the versions are equal (ignoring labels), returns one of the two strings arbitrarily.
423
423
*
424
424
* If minor or patch are omitted (non-conformant to semantic versioning), they are considered zero.
@@ -459,6 +459,9 @@ class FlutterPlugin implements Plugin<Project> {
459
459
460
460
getPluginList(). each { plugin ->
461
461
Project pluginProject = project. rootProject. findProject(plugin. key)
462
+ if (pluginProject == null ) {
463
+ return
464
+ }
462
465
pluginProject. afterEvaluate {
463
466
int pluginCompileSdkVersion = pluginProject. android. compileSdkVersion. substring(8 ) as int
464
467
maxPluginCompileSdkVersion = Math . max(pluginCompileSdkVersion, maxPluginCompileSdkVersion)
@@ -476,15 +479,7 @@ class FlutterPlugin implements Plugin<Project> {
476
479
}
477
480
}
478
481
}
479
- }
480
- }
481
-
482
- /**
483
- * Returns `true` if the given path contains an `android/build.gradle` file.
484
- */
485
- private Boolean doesSupportAndroidPlatform (String path ) {
486
- File editableAndroidProject = new File (path, ' android' + File . separator + ' build.gradle' )
487
- return editableAndroidProject. exists()
482
+ }
488
483
}
489
484
490
485
/**
@@ -495,8 +490,7 @@ class FlutterPlugin implements Plugin<Project> {
495
490
private void configurePluginDependencies (Object dependencyObject ) {
496
491
assert dependencyObject. name instanceof String
497
492
Project pluginProject = project. rootProject. findProject(" :${ dependencyObject.name} " )
498
- if (pluginProject == null ||
499
- ! doesSupportAndroidPlatform(pluginProject. projectDir. parentFile. path)) {
493
+ if (pluginProject == null ) {
500
494
return
501
495
}
502
496
assert dependencyObject. dependencies instanceof List
@@ -506,8 +500,7 @@ class FlutterPlugin implements Plugin<Project> {
506
500
return
507
501
}
508
502
Project dependencyProject = project. rootProject. findProject(" :$pluginDependencyName " )
509
- if (dependencyProject == null ||
510
- ! doesSupportAndroidPlatform(dependencyProject. projectDir. parentFile. path)) {
503
+ if (dependencyProject == null ) {
511
504
return
512
505
}
513
506
// Wait for the Android plugin to load and add the dependency to the plugin project.
@@ -519,17 +512,27 @@ class FlutterPlugin implements Plugin<Project> {
519
512
}
520
513
}
521
514
515
+ /* * Gets the list of plugins that support the Android platform. */
522
516
private Properties getPluginList () {
523
- File pluginsFile = new File (project. projectDir. parentFile. parentFile, ' .flutter-plugins' )
524
- Properties allPlugins = readPropertiesIfExist(pluginsFile)
517
+ Map meta = getDependenciesMetadata()
525
518
Properties androidPlugins = new Properties ()
526
- allPlugins. each { name , path ->
527
- if (doesSupportAndroidPlatform(path)) {
528
- androidPlugins. setProperty(name, path)
519
+ if (meta == null ) {
520
+ return androidPlugins
521
+ }
522
+ assert meta. plugins instanceof Map
523
+ assert meta. plugins. android instanceof List
524
+
525
+ // This logic must be kept in sync with the logic in app_plugin_loader.gradle.
526
+ meta. plugins. android. each { androidPlugin ->
527
+ assert androidPlugin. name instanceof String
528
+ assert androidPlugin. path instanceof String
529
+ // Skip plugins that have no native build (such as a Dart-only implementation
530
+ // of a federated plugin).
531
+ def needsBuild = androidPlugin. containsKey(' native_build' ) ? androidPlugin[' native_build' ] : true
532
+ if (! needsBuild) {
533
+ return
529
534
}
530
- // TODO(amirh): log an error if this plugin was specified to be an Android
531
- // plugin according to the new schema, and was missing a build.gradle file.
532
- // https://github.com/flutter/flutter/issues/40784
535
+ androidPlugins. setProperty(androidPlugin. name, androidPlugin. path)
533
536
}
534
537
return androidPlugins
535
538
}
@@ -557,14 +560,31 @@ class FlutterPlugin implements Plugin<Project> {
557
560
// This means, `plugin-a` depends on `plugin-b` and `plugin-c`.
558
561
// `plugin-b` depends on `plugin-c`.
559
562
// `plugin-c` doesn't depend on anything.
560
- File pluginsDependencyFile = new File (project. projectDir. parentFile. parentFile, ' .flutter-plugins-dependencies' )
563
+ Map meta = getDependenciesMetadata()
564
+ if (meta == null ) {
565
+ return []
566
+ }
567
+ assert meta. dependencyGraph instanceof List
568
+ return meta. dependencyGraph
569
+ }
570
+
571
+ private Map parsedFlutterPluginsDependencies
572
+
573
+ /**
574
+ * Parses <project-src>/.flutter-plugins-dependencies
575
+ */
576
+ private Map getDependenciesMetadata () {
577
+ if (parsedFlutterPluginsDependencies) {
578
+ return parsedFlutterPluginsDependencies
579
+ }
580
+ File pluginsDependencyFile = new File (getFlutterSourceDirectory(), ' .flutter-plugins-dependencies' )
561
581
if (pluginsDependencyFile. exists()) {
562
582
def object = new JsonSlurper (). parseText(pluginsDependencyFile. text)
563
583
assert object instanceof Map
564
- assert object . dependencyGraph instanceof List
565
- return object. dependencyGraph
584
+ parsedFlutterPluginsDependencies = object
585
+ return object
566
586
}
567
- return []
587
+ return null
568
588
}
569
589
570
590
private static String toCammelCase (List<String > parts ) {
0 commit comments