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

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com