gradle_plugin_bundle_test.dart 6.21 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_devicelab/framework/apk_utils.dart';
import 'package:flutter_devicelab/framework/framework.dart';
7
import 'package:flutter_devicelab/framework/task_result.dart';
8
import 'package:flutter_devicelab/framework/utils.dart';
9
import 'package:path/path.dart' as path;
10 11

Future<void> main() async {
12 13 14 15 16
  final Iterable<String> baseAabFiles = <String>[
    'base/dex/classes.dex',
    'base/manifest/AndroidManifest.xml',
  ];
  final Iterable<String> flutterAabAssets = flutterAssets.map((String file) => 'base/$file');
17 18
  await task(() async {
    try {
19
      await runProjectTest((FlutterProject project) async {
20
        section('App bundle content for task bundleRelease without explicit target platform');
21 22 23 24 25 26

        await inDirectory(project.rootPath, () {
          return flutter('build', options: <String>[
            'appbundle',
          ]);
        });
27

28
        final String releaseBundle = path.join(
29 30 31 32 33 34
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'release',
35
          'app-release.aab',
36
        );
37
        checkCollectionContains<String>(<String>[
38 39
          ...baseAabFiles,
          ...flutterAabAssets,
40 41 42 43
          'base/lib/arm64-v8a/libapp.so',
          'base/lib/arm64-v8a/libflutter.so',
          'base/lib/armeabi-v7a/libapp.so',
          'base/lib/armeabi-v7a/libflutter.so',
44
        ], await getFilesInAppBundle(releaseBundle));
45 46
      });

47 48 49
      await runProjectTest((FlutterProject project) async {
        section('App bundle content using flavors without explicit target platform');
        // Add a few flavors.
50 51 52 53 54 55
        await project.addProductFlavors(<String> [
          'production',
          'staging',
          'development',
          'flavor_underscore', // https://github.com/flutter/flutter/issues/36067
        ]);
56
        // Build the production flavor in release mode.
57 58 59 60 61 62 63
        await inDirectory(project.rootPath, () {
          return flutter('build', options: <String>[
            'appbundle',
            '--flavor',
            'production',
          ]);
        });
64

65 66 67 68 69 70 71
        final String bundleFromGradlePath = path.join(
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'productionRelease',
72
          'app-production-release.aab',
73
        );
74
        checkCollectionContains<String>(<String>[
75 76
          ...baseAabFiles,
          ...flutterAabAssets,
77 78 79 80 81 82 83 84
          'base/lib/arm64-v8a/libapp.so',
          'base/lib/arm64-v8a/libflutter.so',
          'base/lib/armeabi-v7a/libapp.so',
          'base/lib/armeabi-v7a/libflutter.so',
        ], await getFilesInAppBundle(bundleFromGradlePath));

        section('Build app bundle using the flutter tool - flavor: flavor_underscore');

85 86
        int exitCode = await inDirectory(project.rootPath, ()  {
          return flutter(
87
            'build',
88 89 90 91 92
            options: <String>[
              'appbundle',
              '--flavor=flavor_underscore',
              '--verbose',
            ],
93
          );
94
        });
95

96 97 98
        if (exitCode != 0) {
          throw TaskResult.failure('flutter build appbundle command exited with code: $exitCode');
        }
99

100 101 102 103 104 105 106
        final String flavorUnderscoreBundlePath = path.join(
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'flavor_underscoreRelease',
107
          'app-flavor_underscore-release.aab',
108
        );
109
        checkCollectionContains<String>(<String>[
110 111
          ...baseAabFiles,
          ...flutterAabAssets,
112 113 114 115
          'base/lib/arm64-v8a/libapp.so',
          'base/lib/arm64-v8a/libflutter.so',
          'base/lib/armeabi-v7a/libapp.so',
          'base/lib/armeabi-v7a/libflutter.so',
116 117 118 119
        ], await getFilesInAppBundle(flavorUnderscoreBundlePath));

        section('Build app bundle using the flutter tool - flavor: production');

120 121
        exitCode = await inDirectory(project.rootPath, () {
          return flutter(
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
            'build',
            options: <String>[
              'appbundle',
              '--flavor=production',
              '--verbose',
            ],
          );
        });

        if (exitCode != 0) {
          throw TaskResult.failure('flutter build appbundle command exited with code: $exitCode');
        }

        final String productionBundlePath = path.join(
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'productionRelease',
142
          'app-production-release.aab',
143
        );
144
        checkCollectionContains<String>(<String>[
145 146
          ...baseAabFiles,
          ...flutterAabAssets,
147 148 149 150 151
          'base/lib/arm64-v8a/libapp.so',
          'base/lib/arm64-v8a/libflutter.so',
          'base/lib/armeabi-v7a/libapp.so',
          'base/lib/armeabi-v7a/libflutter.so',
        ], await getFilesInAppBundle(productionBundlePath));
152 153 154
      });

      await runProjectTest((FlutterProject project) async {
155
        section('App bundle content for task bundleRelease with target platform = android-arm');
156 157 158 159 160 161 162 163 164 165

        await inDirectory(project.rootPath, () {
          return flutter(
            'build',
            options: <String>[
              'appbundle',
              '--target-platform=android-arm',
            ],
          );
        });
166

167
        final String releaseBundle = path.join(
168 169 170 171 172 173
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'release',
174
          'app-release.aab',
175
        );
176

177
        final Iterable<String> bundleFiles = await getFilesInAppBundle(releaseBundle);
178
        checkCollectionContains<String>(<String>[
179 180
          ...baseAabFiles,
          ...flutterAabAssets,
181 182 183 184
          'base/lib/armeabi-v7a/libapp.so',
          'base/lib/armeabi-v7a/libflutter.so',
        ], bundleFiles);

185
        checkCollectionDoesNotContain<String>(<String>[
186 187 188 189 190 191 192 193 194 195 196 197
          'base/lib/arm64-v8a/libapp.so',
          'base/lib/arm64-v8a/libflutter.so',
        ], bundleFiles);
      });
      return TaskResult.success(null);
    } on TaskResult catch (taskResult) {
      return taskResult;
    } catch (e) {
      return TaskResult.failure(e.toString());
    }
  });
}