build_aar_module_test.dart 6.8 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 'dart:io';

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

13 14 15
final String platformLineSep = Platform.isWindows ? '\r\n': '\n';


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

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

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

42 43 44 45 46
      section('Create plugin that supports android platform');

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

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

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

60 61 62 63
      section('Add plugins to pubspec.yaml');

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

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

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

      section('Build release AAR');

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

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

100 101
      section('Check release Maven artifacts');

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

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

124
      checkFileExists(releasePom);
125

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

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

148
      section('Check AOT blobs in release POM');
149

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

158 159
      section('Check assets in release AAR');

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

182 183
      section('Check debug Maven artifacts');

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

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

206
      checkFileExists(debugPom);
207

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

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

230
      section('Check AOT blobs in debug POM');
231

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

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

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

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