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

5 6
// @dart = 2.8

7 8
import 'dart:io';

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

15 16 17
final String platformLineSep = Platform.isWindows ? '\r\n': '\n';


18
final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
19
final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradlew';
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

/// Tests that AARs can be built on module projects.
Future<void> main() async {
  await task(() async {

    section('Find Java');

    final String javaHome = await findJavaHome();
    if (javaHome == null)
      return TaskResult.failure('Could not find Java');
    print('\nUsing JAVA_HOME=$javaHome');

    final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.');
    final Directory projectDir = Directory(path.join(tempDir.path, 'hello'));
    try {
35 36
      section('Create module project');

37 38 39 40 41 42 43
      await inDirectory(tempDir, () async {
        await flutter(
          'create',
          options: <String>['--org', 'io.flutter.devicelab', '--template', 'module', 'hello'],
        );
      });

44 45 46 47 48
      section('Create plugin that supports android platform');

      await inDirectory(tempDir, () async {
        await flutter(
          'create',
49
          options: <String>['--org', 'io.flutter.devicelab', '--template', 'plugin', '--platforms=android', 'plugin_with_android'],
50 51 52
        );
      });

53
      section("Create plugin that doesn't support android project");
54 55 56 57

      await inDirectory(tempDir, () async {
        await flutter(
          'create',
58
          options: <String>['--org', 'io.flutter.devicelab', '--template', 'plugin', '--platforms=ios', 'plugin_without_android'],
59 60
        );
      });
61

62 63 64 65
      section('Add plugins to pubspec.yaml');

      final File modulePubspec = File(path.join(projectDir.path, 'pubspec.yaml'));
      String content = modulePubspec.readAsStringSync();
66
      content = content.replaceFirst(
67 68 69 70 71 72
        '${platformLineSep}dependencies:$platformLineSep',
        '${platformLineSep}dependencies:$platformLineSep'
          '  plugin_with_android:$platformLineSep'
          '    path: ../plugin_with_android$platformLineSep'
          '  plugin_without_android:$platformLineSep'
          '    path: ../plugin_without_android$platformLineSep',
73
      );
74 75 76 77
      modulePubspec.writeAsStringSync(content, flush: true);

      section('Run packages get in module project');

78 79 80 81 82 83 84 85 86 87 88 89
      await inDirectory(projectDir, () async {
        await flutter(
          'packages',
          options: <String>['get'],
        );
      });

      section('Build release AAR');

      await inDirectory(projectDir, () async {
        await flutter(
          'build',
90
          options: <String>['aar', '--verbose'],
91 92 93 94 95 96 97 98 99 100 101
        );
      });

      final String repoPath = path.join(
        projectDir.path,
        'build',
        'host',
        'outputs',
        'repo',
      );

102 103
      section('Check release Maven artifacts');

104 105 106 107 108 109 110 111 112 113 114
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_release',
        '1.0',
        'flutter_release-1.0.aar',
      ));

115
      final String releasePom = path.join(
116 117 118 119 120 121 122 123
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_release',
        '1.0',
        'flutter_release-1.0.pom',
124
      );
125

126
      checkFileExists(releasePom);
127

128 129 130 131
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
132 133 134
        'devicelab',
        'plugin_with_android',
        'plugin_with_android_release',
135
        '1.0',
136
        'plugin_with_android_release-1.0.aar',
137 138 139 140 141 142
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
143 144 145
        'devicelab',
        'plugin_with_android',
        'plugin_with_android_release',
146
        '1.0',
147
        'plugin_with_android_release-1.0.pom',
148 149
      ));

150
      section('Check AOT blobs in release POM');
151

152 153 154 155
      checkFileContains(<String>[
        'flutter_embedding_release',
        'armeabi_v7a_release',
        'arm64_v8a_release',
156
        'x86_64_release',
157
        'plugin_with_android_release',
158
      ], releasePom);
159

160 161
      section('Check assets in release AAR');

162
      checkCollectionContains<String>(
163 164 165 166 167
        <String>[
          ...flutterAssets,
          // AOT snapshots
          'jni/arm64-v8a/libapp.so',
          'jni/armeabi-v7a/libapp.so',
168
          'jni/x86_64/libapp.so',
169 170 171 172 173 174 175 176 177 178 179 180 181 182
        ],
        await getFilesInAar(
          path.join(
            repoPath,
            'io',
            'flutter',
            'devicelab',
            'hello',
            'flutter_release',
            '1.0',
            'flutter_release-1.0.aar',
          )
        )
      );
183

184 185
      section('Check debug Maven artifacts');

186 187 188 189 190 191
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
192
        'flutter_debug',
193
        '1.0',
194
        'flutter_debug-1.0.aar',
195 196
      ));

197
      final String debugPom = path.join(
198 199 200 201 202 203 204 205
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_debug',
        '1.0',
        'flutter_debug-1.0.pom',
206
      );
207

208
      checkFileExists(debugPom);
209

210 211 212 213
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
214 215 216
        'devicelab',
        'plugin_with_android',
        'plugin_with_android_debug',
217
        '1.0',
218
        'plugin_with_android_debug-1.0.aar',
219 220 221 222 223 224
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
225 226 227
        'devicelab',
        'plugin_with_android',
        'plugin_with_android_debug',
228
        '1.0',
229
        'plugin_with_android_debug-1.0.pom',
230 231
      ));

232
      section('Check AOT blobs in debug POM');
233

234 235 236 237 238 239
      checkFileContains(<String>[
        'flutter_embedding_debug',
        'x86_debug',
        'x86_64_debug',
        'armeabi_v7a_debug',
        'arm64_v8a_debug',
240
        'plugin_with_android_debug',
241
      ], debugPom);
242 243 244 245 246 247 248 249 250 251 252 253 254 255

      section('Check assets in debug AAR');

      final Iterable<String> debugAar = await getFilesInAar(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_debug',
        '1.0',
        'flutter_debug-1.0.aar',
      ));

256
      checkCollectionContains<String>(<String>[
257
        ...flutterAssets,
258
        ...debugAssets,
259 260
      ], debugAar);

261
      return TaskResult.success(null);
262 263
    } on TaskResult catch (taskResult) {
      return taskResult;
264 265 266
    } catch (e) {
      return TaskResult.failure(e.toString());
    } finally {
267
      // rmTree(tempDir);
268 269 270
    }
  });
}