gradle_plugin_bundle_test.dart 5.62 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright (c) 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter_devicelab/framework/apk_utils.dart';
import 'package:flutter_devicelab/framework/framework.dart';
import 'package:flutter_devicelab/framework/utils.dart';
10
import 'package:path/path.dart' as path;
11 12 13 14

Future<void> main() async {
  await task(() async {
    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 21 22 23 24 25 26 27
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'release',
          'app.aab',
        );
28 29 30 31 32 33 34
        checkItContains<String>(<String>[
          'base/manifest/AndroidManifest.xml',
          'base/dex/classes.dex',
          'base/lib/arm64-v8a/libapp.so',
          'base/lib/arm64-v8a/libflutter.so',
          'base/lib/armeabi-v7a/libapp.so',
          'base/lib/armeabi-v7a/libflutter.so',
35
        ], await getFilesInAppBundle(releaseBundle));
36 37
      });

38 39 40
      await runProjectTest((FlutterProject project) async {
        section('App bundle content using flavors without explicit target platform');
        // Add a few flavors.
41 42 43 44 45 46
        await project.addProductFlavors(<String> [
          'production',
          'staging',
          'development',
          'flavor_underscore', // https://github.com/flutter/flutter/issues/36067
        ]);
47 48 49
        // Build the production flavor in release mode.
        await project.runGradleTask('bundleProductionRelease');

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
        final String bundleFromGradlePath = path.join(
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'productionRelease',
          'app.aab',
        );
        checkItContains<String>(<String>[
          'base/manifest/AndroidManifest.xml',
          'base/dex/classes.dex',
          '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');

        int exitCode;
        await inDirectory(project.rootPath, () async {
          exitCode = await flutter(
73
            'build',
74 75 76 77 78
            options: <String>[
              'appbundle',
              '--flavor=flavor_underscore',
              '--verbose',
            ],
79
          );
80
        });
81

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

86 87 88 89 90 91 92 93 94
        final String flavorUnderscoreBundlePath = path.join(
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'flavor_underscoreRelease',
          'app.aab',
        );
95 96 97 98 99 100 101
        checkItContains<String>(<String>[
          'base/manifest/AndroidManifest.xml',
          'base/dex/classes.dex',
          'base/lib/arm64-v8a/libapp.so',
          'base/lib/arm64-v8a/libflutter.so',
          'base/lib/armeabi-v7a/libapp.so',
          'base/lib/armeabi-v7a/libflutter.so',
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        ], await getFilesInAppBundle(flavorUnderscoreBundlePath));

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

        await inDirectory(project.rootPath, () async {
          exitCode = await flutter(
            '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',
          'app.aab',
        );
        checkItContains<String>(<String>[
          'base/manifest/AndroidManifest.xml',
          'base/dex/classes.dex',
          '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));
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 144
            options: <String>['-Ptarget-platform=android-arm']);

145
        final String releaseBundle = path.join(
146 147 148 149 150 151 152 153
          project.rootPath,
          'build',
          'app',
          'outputs',
          'bundle',
          'release',
          'app.aab',
        );
154

155
        final Iterable<String> bundleFiles = await getFilesInAppBundle(releaseBundle);
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176

        checkItContains<String>(<String>[
          'base/manifest/AndroidManifest.xml',
          'base/dex/classes.dex',
          'base/lib/armeabi-v7a/libapp.so',
          'base/lib/armeabi-v7a/libflutter.so',
        ], bundleFiles);

        checkItDoesNotContain<String>(<String>[
          '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());
    }
  });
}