@@ -2510,6 +2510,226 @@ The Flutter Preview device does not support the following plugins from your pubs
2510
2510
returnsNormally,
2511
2511
);
2512
2512
});
2513
+
2514
+ group ('injectPlugins in release mode' , () {
2515
+ const String testPluginName = 'test_plugin' ;
2516
+
2517
+ // Fake pub to override dev dependencies of flutterProject.
2518
+ final Pub fakePubWithTestPluginDevDependency = FakePubWithPrimedDeps (
2519
+ devDependencies: < String > {testPluginName},
2520
+ );
2521
+
2522
+ testUsingContext (
2523
+ 'excludes dev dependencies from Android plugin registrant' ,
2524
+ () async {
2525
+ final Directory pluginDir = createPlugin (
2526
+ name: testPluginName,
2527
+ platforms: const < String , _PluginPlatformInfo > {
2528
+ 'android' : _PluginPlatformInfo (pluginClass: 'Foo' , androidPackage: 'bar.foo' ),
2529
+ },
2530
+ );
2531
+
2532
+ // injectPlugins will fail if main native class not found in expected spot, so add
2533
+ // it first.
2534
+ pluginDir
2535
+ .childDirectory ('android' )
2536
+ .childDirectory ('src' )
2537
+ .childDirectory ('main' )
2538
+ .childDirectory ('java' )
2539
+ .childDirectory ('bar' )
2540
+ .childDirectory ('foo' )
2541
+ .childFile ('Foo.java' )
2542
+ ..createSync (recursive: true )
2543
+ ..writeAsStringSync ('import io.flutter.embedding.engine.plugins.FlutterPlugin;' );
2544
+
2545
+ // Test non-release mode.
2546
+ await injectPlugins (flutterProject, androidPlatform: true , releaseMode: false );
2547
+ final File generatedPluginRegistrant =
2548
+ flutterProject.android.generatedPluginRegistrantFile;
2549
+ expect (generatedPluginRegistrant, exists);
2550
+ expect (generatedPluginRegistrant.readAsStringSync (), contains ('bar.foo.Foo' ));
2551
+
2552
+ // Test release mode.
2553
+ await injectPlugins (flutterProject, androidPlatform: true , releaseMode: true );
2554
+ expect (generatedPluginRegistrant, exists);
2555
+ expect (generatedPluginRegistrant.readAsStringSync (), isNot (contains ('bar.foo.Foo' )));
2556
+ },
2557
+ overrides: < Type , Generator > {
2558
+ FileSystem : () => fs,
2559
+ ProcessManager : () => FakeProcessManager .any (),
2560
+ FeatureFlags : enableExplicitPackageDependencies,
2561
+ Pub : () => fakePubWithTestPluginDevDependency,
2562
+ },
2563
+ );
2564
+
2565
+ testUsingContext (
2566
+ 'excludes dev dependencies from iOS plugin registrant' ,
2567
+ () async {
2568
+ createPlugin (
2569
+ name: testPluginName,
2570
+ platforms: const < String , _PluginPlatformInfo > {
2571
+ 'ios' : _PluginPlatformInfo (pluginClass: 'Foo' ),
2572
+ },
2573
+ );
2574
+
2575
+ final FakeDarwinDependencyManagement dependencyManagement =
2576
+ FakeDarwinDependencyManagement ();
2577
+ const String devDepImport = '#import <$testPluginName /Foo.h>' ;
2578
+
2579
+ // Test non-release mode.
2580
+ await injectPlugins (
2581
+ flutterProject,
2582
+ iosPlatform: true ,
2583
+ darwinDependencyManagement: dependencyManagement,
2584
+ releaseMode: false ,
2585
+ );
2586
+ final File generatedPluginRegistrantImpl =
2587
+ flutterProject.ios.pluginRegistrantImplementation;
2588
+ expect (generatedPluginRegistrantImpl, exists);
2589
+ expect (generatedPluginRegistrantImpl.readAsStringSync (), contains (devDepImport));
2590
+
2591
+ // Test release mode.
2592
+ await injectPlugins (
2593
+ flutterProject,
2594
+ iosPlatform: true ,
2595
+ darwinDependencyManagement: dependencyManagement,
2596
+ releaseMode: true ,
2597
+ );
2598
+ expect (generatedPluginRegistrantImpl, exists);
2599
+ expect (generatedPluginRegistrantImpl.readAsStringSync (), isNot (contains (devDepImport)));
2600
+ },
2601
+ overrides: < Type , Generator > {
2602
+ FileSystem : () => fs,
2603
+ ProcessManager : () => FakeProcessManager .any (),
2604
+ FeatureFlags : enableExplicitPackageDependencies,
2605
+ Pub : () => fakePubWithTestPluginDevDependency,
2606
+ },
2607
+ );
2608
+
2609
+ testUsingContext (
2610
+ 'excludes dev dependencies from Linux plugin registrant' ,
2611
+ () async {
2612
+ createPlugin (
2613
+ name: testPluginName,
2614
+ platforms: const < String , _PluginPlatformInfo > {
2615
+ 'linux' : _PluginPlatformInfo (pluginClass: 'Foo' ),
2616
+ },
2617
+ );
2618
+
2619
+ const String expectedDevDepImport = '#include <$testPluginName /foo.h>' ;
2620
+
2621
+ // Test non-release mode.
2622
+ await injectPlugins (flutterProject, linuxPlatform: true , releaseMode: false );
2623
+ final File generatedPluginRegistrant = flutterProject.linux.managedDirectory.childFile (
2624
+ 'generated_plugin_registrant.cc' ,
2625
+ );
2626
+ expect (generatedPluginRegistrant, exists);
2627
+ expect (generatedPluginRegistrant.readAsStringSync (), contains (expectedDevDepImport));
2628
+
2629
+ // Test release mode.
2630
+ await injectPlugins (flutterProject, linuxPlatform: true , releaseMode: true );
2631
+ expect (generatedPluginRegistrant, exists);
2632
+ expect (
2633
+ generatedPluginRegistrant.readAsStringSync (),
2634
+ isNot (contains (expectedDevDepImport)),
2635
+ );
2636
+ },
2637
+ overrides: < Type , Generator > {
2638
+ FileSystem : () => fs,
2639
+ ProcessManager : () => FakeProcessManager .any (),
2640
+ FeatureFlags : enableExplicitPackageDependencies,
2641
+ Pub : () => fakePubWithTestPluginDevDependency,
2642
+ },
2643
+ );
2644
+
2645
+ testUsingContext (
2646
+ 'excludes dev dependencies from MacOS plugin registrant' ,
2647
+ () async {
2648
+ createPlugin (
2649
+ name: testPluginName,
2650
+ platforms: const < String , _PluginPlatformInfo > {
2651
+ 'macos' : _PluginPlatformInfo (pluginClass: 'Foo' ),
2652
+ },
2653
+ );
2654
+ final FakeDarwinDependencyManagement dependencyManagement =
2655
+ FakeDarwinDependencyManagement ();
2656
+ const String expectedDevDepRegistration = 'Foo.register' ;
2657
+
2658
+ // Test non-release mode.
2659
+ await injectPlugins (
2660
+ flutterProject,
2661
+ macOSPlatform: true ,
2662
+ darwinDependencyManagement: dependencyManagement,
2663
+ releaseMode: false ,
2664
+ );
2665
+ final File generatedPluginRegistrant = flutterProject.macos.managedDirectory.childFile (
2666
+ 'GeneratedPluginRegistrant.swift' ,
2667
+ );
2668
+ expect (generatedPluginRegistrant, exists);
2669
+ expect (
2670
+ generatedPluginRegistrant.readAsStringSync (),
2671
+ contains (expectedDevDepRegistration),
2672
+ );
2673
+
2674
+ // Test release mode.
2675
+ await injectPlugins (
2676
+ flutterProject,
2677
+ macOSPlatform: true ,
2678
+ darwinDependencyManagement: dependencyManagement,
2679
+ releaseMode: true ,
2680
+ );
2681
+ expect (generatedPluginRegistrant, exists);
2682
+ expect (
2683
+ generatedPluginRegistrant.readAsStringSync (),
2684
+ isNot (contains (expectedDevDepRegistration)),
2685
+ );
2686
+ },
2687
+ overrides: < Type , Generator > {
2688
+ FileSystem : () => fs,
2689
+ ProcessManager : () => FakeProcessManager .any (),
2690
+ FeatureFlags : enableExplicitPackageDependencies,
2691
+ Pub : () => fakePubWithTestPluginDevDependency,
2692
+ },
2693
+ );
2694
+
2695
+ testUsingContext (
2696
+ 'excludes dev dependencies from Windows plugin registrant' ,
2697
+ () async {
2698
+ createPlugin (
2699
+ name: testPluginName,
2700
+ platforms: const < String , _PluginPlatformInfo > {
2701
+ 'windows' : _PluginPlatformInfo (pluginClass: 'Foo' ),
2702
+ },
2703
+ );
2704
+
2705
+ const String expectedDevDepRegistration = '#include <$testPluginName /foo.h>' ;
2706
+
2707
+ // Test non-release mode.
2708
+ await injectPlugins (flutterProject, windowsPlatform: true , releaseMode: false );
2709
+ final File generatedPluginRegistrantImpl = flutterProject.windows.managedDirectory
2710
+ .childFile ('generated_plugin_registrant.cc' );
2711
+ expect (generatedPluginRegistrantImpl, exists);
2712
+ expect (
2713
+ generatedPluginRegistrantImpl.readAsStringSync (),
2714
+ contains (expectedDevDepRegistration),
2715
+ );
2716
+
2717
+ // Test release mode.
2718
+ await injectPlugins (flutterProject, windowsPlatform: true , releaseMode: true );
2719
+ expect (generatedPluginRegistrantImpl, exists);
2720
+ expect (
2721
+ generatedPluginRegistrantImpl.readAsStringSync (),
2722
+ isNot (contains (expectedDevDepRegistration)),
2723
+ );
2724
+ },
2725
+ overrides: < Type , Generator > {
2726
+ FileSystem : () => fs,
2727
+ ProcessManager : () => FakeProcessManager .any (),
2728
+ FeatureFlags : enableExplicitPackageDependencies,
2729
+ Pub : () => fakePubWithTestPluginDevDependency,
2730
+ },
2731
+ );
2732
+ });
2513
2733
});
2514
2734
2515
2735
testUsingContext (
@@ -2718,6 +2938,17 @@ class FakeAndroidProject extends Fake implements AndroidProject {
2718
2938
AndroidEmbeddingVersionResult computeEmbeddingVersion () {
2719
2939
return AndroidEmbeddingVersionResult (embeddingVersion, 'reasons for version' );
2720
2940
}
2941
+
2942
+ @override
2943
+ File get generatedPluginRegistrantFile => hostAppGradleRoot
2944
+ .childDirectory ('app' )
2945
+ .childDirectory ('src' )
2946
+ .childDirectory ('main' )
2947
+ .childDirectory ('java' )
2948
+ .childDirectory ('io' )
2949
+ .childDirectory ('flutter' )
2950
+ .childDirectory ('plugins' )
2951
+ .childFile ('GeneratedPluginRegistrant.java' );
2721
2952
}
2722
2953
2723
2954
class FakeWebProject extends Fake implements WebProject {
0 commit comments