"Fossies" - the Fresh Open Source Software Archive

Member "flutter-1.22.4/dev/devicelab/bin/tasks/module_host_with_custom_build_test.dart" (13 Nov 2020, 8125 Bytes) of package /linux/misc/flutter-1.22.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Dart source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // Copyright 2014 The Flutter Authors. All rights reserved.
    2 // Use of this source code is governed by a BSD-style license that can be
    3 // found in the LICENSE file.
    4 
    5 import 'dart:async';
    6 import 'dart:io';
    7 
    8 import 'package:flutter_devicelab/framework/apk_utils.dart';
    9 import 'package:flutter_devicelab/framework/framework.dart';
   10 import 'package:flutter_devicelab/framework/utils.dart';
   11 import 'package:path/path.dart' as path;
   12 
   13 final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
   14 final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradlew';
   15 
   16 /// Tests that the Android app containing a Flutter module can be built when
   17 /// it has custom build types and flavors.
   18 Future<void> main() async {
   19   await task(() async {
   20 
   21     section('Find Java');
   22 
   23     final String javaHome = await findJavaHome();
   24     if (javaHome == null) {
   25       return TaskResult.failure('Could not find Java');
   26     }
   27 
   28     print('\nUsing JAVA_HOME=$javaHome');
   29 
   30     section('Create Flutter module project');
   31 
   32     final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.');
   33     final Directory projectDir = Directory(path.join(tempDir.path, 'hello'));
   34     try {
   35       await inDirectory(tempDir, () async {
   36         await flutter(
   37           'create',
   38           options: <String>['--org', 'io.flutter.devicelab', '--template=module', 'hello'],
   39         );
   40       });
   41 
   42       section('Run flutter pub get');
   43 
   44       await inDirectory(projectDir, () async {
   45         await flutter(
   46           'pub',
   47           options: <String>['get'],
   48         );
   49       });
   50 
   51       section('Add to existing Android app');
   52 
   53       final Directory hostAppDir = Directory(path.join(tempDir.path, 'hello_host_app_with_custom_build'));
   54       mkdir(hostAppDir);
   55       recursiveCopy(
   56         Directory(
   57           path.join(
   58             flutterDirectory.path,
   59             'dev',
   60             'integration_tests',
   61             'module_host_with_custom_build_v2_embedding',
   62           ),
   63         ),
   64         hostAppDir,
   65       );
   66       copy(
   67         File(path.join(projectDir.path, '.android', gradlew)),
   68         hostAppDir,
   69       );
   70       copy(
   71         File(path.join(projectDir.path, '.android', 'gradle', 'wrapper', 'gradle-wrapper.jar')),
   72         Directory(path.join(hostAppDir.path, 'gradle', 'wrapper')),
   73       );
   74 
   75       final Function clean = () async {
   76         section('Clean');
   77         await inDirectory(hostAppDir, () async {
   78           await exec(gradlewExecutable,
   79             <String>['clean'],
   80             environment: <String, String>{
   81               'JAVA_HOME': javaHome,
   82             },
   83           );
   84         });
   85       };
   86 
   87       if (!Platform.isWindows) {
   88         section('Make $gradlewExecutable executable');
   89         await inDirectory(hostAppDir, () async {
   90           await exec('chmod', <String>['+x', gradlewExecutable]);
   91         });
   92       }
   93 
   94       section('Build debug APKs');
   95 
   96       section('Run app:assembleDemoDebug');
   97 
   98       await inDirectory(hostAppDir, () async {
   99         await exec(gradlewExecutable,
  100           <String>['app:assembleDemoDebug'],
  101           environment: <String, String>{
  102             'JAVA_HOME': javaHome,
  103           },
  104         );
  105       });
  106 
  107       final String demoDebugApk = path.join(
  108         hostAppDir.path,
  109         'app',
  110         'build',
  111         'outputs',
  112         'apk',
  113         'demo',
  114         'debug',
  115         'app-demo-debug.apk',
  116       );
  117 
  118       if (!exists(File(demoDebugApk))) {
  119         return TaskResult.failure('Failed to build app-demo-debug.apk');
  120       }
  121 
  122       section('Verify snapshots in app-demo-debug.apk');
  123 
  124       checkCollectionContains<String>(<String>[
  125         ...flutterAssets,
  126         ...debugAssets,
  127       ], await getFilesInApk(demoDebugApk));
  128 
  129       await clean();
  130 
  131       // Change the order of the task and ensure that flutter_assets are in the APK.
  132       // https://github.com/flutter/flutter/pull/41333
  133       section('Run app:assembleDemoDebug - Merge assets before processing manifest');
  134 
  135       await inDirectory(hostAppDir, () async {
  136         await exec(gradlewExecutable,
  137           <String>[
  138             // Normally, `app:processDemoDebugManifest` runs before `app:mergeDemoDebugAssets`.
  139             // In this case, we run `app:mergeDemoDebugAssets` first.
  140             'app:mergeDemoDebugAssets',
  141             'app:processDemoDebugManifest',
  142             'app:assembleDemoDebug',
  143           ],
  144           environment: <String, String>{
  145             'JAVA_HOME': javaHome,
  146           },
  147         );
  148       });
  149 
  150       final String demoDebugApk2 = path.join(
  151         hostAppDir.path,
  152         'app',
  153         'build',
  154         'outputs',
  155         'apk',
  156         'demo',
  157         'debug',
  158         'app-demo-debug.apk',
  159       );
  160 
  161       if (!exists(File(demoDebugApk2))) {
  162         return TaskResult.failure('Failed to build app-demo-debug.apk');
  163       }
  164 
  165       section('Verify snapshots in app-demo-debug.apk');
  166 
  167       checkCollectionContains<String>(<String>[
  168         ...flutterAssets,
  169         ...debugAssets,
  170       ], await getFilesInApk(demoDebugApk2));
  171 
  172       await clean();
  173 
  174       section('Run app:assembleDemoStaging');
  175 
  176       await inDirectory(hostAppDir, () async {
  177         await exec(gradlewExecutable,
  178           <String>['app:assembleDemoStaging'],
  179           environment: <String, String>{
  180             'JAVA_HOME': javaHome,
  181           },
  182         );
  183       });
  184 
  185       final String demoStagingApk = path.join(
  186         hostAppDir.path,
  187         'app',
  188         'build',
  189         'outputs',
  190         'apk',
  191         'demo',
  192         'staging',
  193         'app-demo-staging.apk',
  194       );
  195 
  196       if (!exists(File(demoStagingApk))) {
  197         return TaskResult.failure('Failed to build app-demo-staging.apk');
  198       }
  199 
  200       section('Verify snapshots in app-demo-staging.apk');
  201 
  202       checkCollectionContains<String>(<String>[
  203         ...flutterAssets,
  204         ...debugAssets,
  205       ], await getFilesInApk(demoStagingApk));
  206 
  207       await clean();
  208 
  209       section('Build release APKs');
  210 
  211       section('Run app:assembleDemoRelease');
  212 
  213       await inDirectory(hostAppDir, () async {
  214         await exec(gradlewExecutable,
  215           <String>['app:assembleDemoRelease'],
  216           environment: <String, String>{
  217             'JAVA_HOME': javaHome,
  218           },
  219         );
  220       });
  221 
  222       final String demoReleaseApk = path.join(
  223         hostAppDir.path,
  224         'app',
  225         'build',
  226         'outputs',
  227         'apk',
  228         'demo',
  229         'release',
  230         'app-demo-release-unsigned.apk',
  231       );
  232 
  233       if (!exists(File(demoReleaseApk))) {
  234         return TaskResult.failure('Failed to build app-demo-release-unsigned.apk');
  235       }
  236 
  237       section('Verify AOT ELF in app-demo-release-unsigned.apk');
  238 
  239       checkCollectionContains<String>(<String>[
  240         ...flutterAssets,
  241         'lib/arm64-v8a/libflutter.so',
  242         'lib/arm64-v8a/libapp.so',
  243         'lib/armeabi-v7a/libflutter.so',
  244         'lib/armeabi-v7a/libapp.so',
  245       ], await getFilesInApk(demoReleaseApk));
  246 
  247       await clean();
  248 
  249       section('Run app:assembleDemoProd');
  250 
  251        await inDirectory(hostAppDir, () async {
  252         await exec(gradlewExecutable,
  253           <String>['app:assembleDemoProd'],
  254           environment: <String, String>{
  255             'JAVA_HOME': javaHome,
  256           },
  257         );
  258       });
  259 
  260       final String demoProdApk = path.join(
  261         hostAppDir.path,
  262         'app',
  263         'build',
  264         'outputs',
  265         'apk',
  266         'demo',
  267         'prod',
  268         'app-demo-prod-unsigned.apk',
  269       );
  270 
  271       if (!exists(File(demoProdApk))) {
  272         return TaskResult.failure('Failed to build app-demo-prod-unsigned.apk');
  273       }
  274 
  275       section('Verify AOT ELF in app-demo-prod-unsigned.apk');
  276 
  277       checkCollectionContains<String>(<String>[
  278         ...flutterAssets,
  279         'lib/arm64-v8a/libapp.so',
  280         'lib/arm64-v8a/libflutter.so',
  281         'lib/armeabi-v7a/libapp.so',
  282         'lib/armeabi-v7a/libflutter.so',
  283       ], await getFilesInApk(demoProdApk));
  284 
  285       return TaskResult.success(null);
  286     } on TaskResult catch (taskResult) {
  287       return taskResult;
  288     } catch (e) {
  289       return TaskResult.failure(e.toString());
  290     } finally {
  291       rmTree(tempDir);
  292     }
  293   });
  294 }