1// Copyright (c) 2016 The Chromium 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 5import 'dart:async'; 6 7import 'package:flutter_devicelab/framework/apk_utils.dart'; 8import 'package:flutter_devicelab/framework/framework.dart'; 9import 'package:flutter_devicelab/framework/utils.dart'; 10import 'package:path/path.dart' as path; 11 12Future<void> main() async { 13 await task(() async { 14 try { 15 await runProjectTest((FlutterProject project) async { 16 section('App bundle content for task bundleRelease without explicit target platform'); 17 await project.runGradleTask('bundleRelease'); 18 19 final String releaseBundle = path.join( 20 project.rootPath, 21 'build', 22 'app', 23 'outputs', 24 'bundle', 25 'release', 26 'app.aab', 27 ); 28 checkItContains<String>(<String>[ 29 'base/manifest/AndroidManifest.xml', 30 'base/dex/classes.dex', 31 'base/lib/arm64-v8a/libapp.so', 32 'base/lib/arm64-v8a/libflutter.so', 33 'base/lib/armeabi-v7a/libapp.so', 34 'base/lib/armeabi-v7a/libflutter.so', 35 ], await getFilesInAppBundle(releaseBundle)); 36 }); 37 38 await runProjectTest((FlutterProject project) async { 39 section('App bundle content using flavors without explicit target platform'); 40 // Add a few flavors. 41 await project.addProductFlavors(<String> [ 42 'production', 43 'staging', 44 'development', 45 'flavor_underscore', // https://github.com/flutter/flutter/issues/36067 46 ]); 47 // Build the production flavor in release mode. 48 await project.runGradleTask('bundleProductionRelease'); 49 50 final String bundleFromGradlePath = path.join( 51 project.rootPath, 52 'build', 53 'app', 54 'outputs', 55 'bundle', 56 'productionRelease', 57 'app.aab', 58 ); 59 checkItContains<String>(<String>[ 60 'base/manifest/AndroidManifest.xml', 61 'base/dex/classes.dex', 62 'base/lib/arm64-v8a/libapp.so', 63 'base/lib/arm64-v8a/libflutter.so', 64 'base/lib/armeabi-v7a/libapp.so', 65 'base/lib/armeabi-v7a/libflutter.so', 66 ], await getFilesInAppBundle(bundleFromGradlePath)); 67 68 section('Build app bundle using the flutter tool - flavor: flavor_underscore'); 69 70 int exitCode; 71 await inDirectory(project.rootPath, () async { 72 exitCode = await flutter( 73 'build', 74 options: <String>[ 75 'appbundle', 76 '--flavor=flavor_underscore', 77 '--verbose', 78 ], 79 ); 80 }); 81 82 if (exitCode != 0) { 83 throw TaskResult.failure('flutter build appbundle command exited with code: $exitCode'); 84 } 85 86 final String flavorUnderscoreBundlePath = path.join( 87 project.rootPath, 88 'build', 89 'app', 90 'outputs', 91 'bundle', 92 'flavor_underscoreRelease', 93 'app.aab', 94 ); 95 checkItContains<String>(<String>[ 96 'base/manifest/AndroidManifest.xml', 97 'base/dex/classes.dex', 98 'base/lib/arm64-v8a/libapp.so', 99 'base/lib/arm64-v8a/libflutter.so', 100 'base/lib/armeabi-v7a/libapp.so', 101 'base/lib/armeabi-v7a/libflutter.so', 102 ], await getFilesInAppBundle(flavorUnderscoreBundlePath)); 103 104 section('Build app bundle using the flutter tool - flavor: production'); 105 106 await inDirectory(project.rootPath, () async { 107 exitCode = await flutter( 108 'build', 109 options: <String>[ 110 'appbundle', 111 '--flavor=production', 112 '--verbose', 113 ], 114 ); 115 }); 116 117 if (exitCode != 0) { 118 throw TaskResult.failure('flutter build appbundle command exited with code: $exitCode'); 119 } 120 121 final String productionBundlePath = path.join( 122 project.rootPath, 123 'build', 124 'app', 125 'outputs', 126 'bundle', 127 'productionRelease', 128 'app.aab', 129 ); 130 checkItContains<String>(<String>[ 131 'base/manifest/AndroidManifest.xml', 132 'base/dex/classes.dex', 133 'base/lib/arm64-v8a/libapp.so', 134 'base/lib/arm64-v8a/libflutter.so', 135 'base/lib/armeabi-v7a/libapp.so', 136 'base/lib/armeabi-v7a/libflutter.so', 137 ], await getFilesInAppBundle(productionBundlePath)); 138 }); 139 140 await runProjectTest((FlutterProject project) async { 141 section('App bundle content for task bundleRelease with target platform = android-arm'); 142 await project.runGradleTask('bundleRelease', 143 options: <String>['-Ptarget-platform=android-arm']); 144 145 final String releaseBundle = path.join( 146 project.rootPath, 147 'build', 148 'app', 149 'outputs', 150 'bundle', 151 'release', 152 'app.aab', 153 ); 154 155 final Iterable<String> bundleFiles = await getFilesInAppBundle(releaseBundle); 156 157 checkItContains<String>(<String>[ 158 'base/manifest/AndroidManifest.xml', 159 'base/dex/classes.dex', 160 'base/lib/armeabi-v7a/libapp.so', 161 'base/lib/armeabi-v7a/libflutter.so', 162 ], bundleFiles); 163 164 checkItDoesNotContain<String>(<String>[ 165 'base/lib/arm64-v8a/libapp.so', 166 'base/lib/arm64-v8a/libflutter.so', 167 ], bundleFiles); 168 }); 169 return TaskResult.success(null); 170 } on TaskResult catch (taskResult) { 171 return taskResult; 172 } catch (e) { 173 return TaskResult.failure(e.toString()); 174 } 175 }); 176} 177