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

import 'dart:async';
import 'dart:io';

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

final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
14
final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradlew';
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

/// 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 {
30 31
      section('Create module project');

32 33 34 35 36 37 38
      await inDirectory(tempDir, () async {
        await flutter(
          'create',
          options: <String>['--org', 'io.flutter.devicelab', '--template', 'module', 'hello'],
        );
      });

39 40 41 42 43
      section('Create plugin that supports android platform');

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

      section('Create plugin that doesn\'t support android project');

      await inDirectory(tempDir, () async {
        await flutter(
          'create',
53
          options: <String>['--org', 'io.flutter.devicelab', '--template', 'plugin', '--platforms=ios', 'plugin_without_android'],
54 55
        );
      });
56

57 58 59 60
      section('Add plugins to pubspec.yaml');

      final File modulePubspec = File(path.join(projectDir.path, 'pubspec.yaml'));
      String content = modulePubspec.readAsStringSync();
61 62
      content = content.replaceFirst(
        '\ndependencies:\n',
63 64 65 66 67
        '\ndependencies:\n'
          '  plugin_with_android:\n'
          '    path: ../plugin_with_android\n'
          '  plugin_without_android:\n'
          '    path: ../plugin_without_android\n',
68
      );
69 70 71 72
      modulePubspec.writeAsStringSync(content, flush: true);

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

73 74 75 76 77 78 79 80 81 82 83 84
      await inDirectory(projectDir, () async {
        await flutter(
          'packages',
          options: <String>['get'],
        );
      });

      section('Build release AAR');

      await inDirectory(projectDir, () async {
        await flutter(
          'build',
85
          options: <String>['aar', '--verbose'],
86 87 88 89 90 91 92 93 94 95 96
        );
      });

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

97 98
      section('Check release Maven artifacts');

99 100 101 102 103 104 105 106 107 108 109
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_release',
        '1.0',
        'flutter_release-1.0.aar',
      ));

110
      final String releasePom = path.join(
111 112 113 114 115 116 117 118
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_release',
        '1.0',
        'flutter_release-1.0.pom',
119
      );
120

121
      checkFileExists(releasePom);
122

123 124 125 126
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
127 128 129
        'devicelab',
        'plugin_with_android',
        'plugin_with_android_release',
130
        '1.0',
131
        'plugin_with_android_release-1.0.aar',
132 133 134 135 136 137
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
138 139 140
        'devicelab',
        'plugin_with_android',
        'plugin_with_android_release',
141
        '1.0',
142
        'plugin_with_android_release-1.0.pom',
143 144
      ));

145
      section('Check AOT blobs in release POM');
146

147 148 149 150
      checkFileContains(<String>[
        'flutter_embedding_release',
        'armeabi_v7a_release',
        'arm64_v8a_release',
151
        'x86_64_release',
152
        'plugin_with_android_release',
153
      ], releasePom);
154

155 156
      section('Check assets in release AAR');

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

179 180
      section('Check debug Maven artifacts');

181 182 183 184 185 186
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
187
        'flutter_debug',
188
        '1.0',
189
        'flutter_debug-1.0.aar',
190 191
      ));

192
      final String debugPom = path.join(
193 194 195 196 197 198 199 200
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_debug',
        '1.0',
        'flutter_debug-1.0.pom',
201
      );
202

203
      checkFileExists(debugPom);
204

205 206 207 208
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
209 210 211
        'devicelab',
        'plugin_with_android',
        'plugin_with_android_debug',
212
        '1.0',
213
        'plugin_with_android_debug-1.0.aar',
214 215 216 217 218 219
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
220 221 222
        'devicelab',
        'plugin_with_android',
        'plugin_with_android_debug',
223
        '1.0',
224
        'plugin_with_android_debug-1.0.pom',
225 226
      ));

227
      section('Check AOT blobs in debug POM');
228

229 230 231 232 233 234
      checkFileContains(<String>[
        'flutter_embedding_debug',
        'x86_debug',
        'x86_64_debug',
        'armeabi_v7a_debug',
        'arm64_v8a_debug',
235
        'plugin_with_android_debug',
236
      ], debugPom);
237 238 239 240 241 242 243 244 245 246 247 248 249 250

      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',
      ));

251
      checkCollectionContains<String>(<String>[
252
        ...flutterAssets,
253
        ...debugAssets,
254 255
      ], debugAar);

256
      return TaskResult.success(null);
257 258
    } on TaskResult catch (taskResult) {
      return taskResult;
259 260 261 262 263 264 265
    } catch (e) {
      return TaskResult.failure(e.toString());
    } finally {
      rmTree(tempDir);
    }
  });
}