build_aar_module_test.dart 6.79 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

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

    section('Create module project');

    final Directory tempDir = Directory.systemTemp.createTempSync('flutter_module_test.');
    final Directory projectDir = Directory(path.join(tempDir.path, 'hello'));
    try {
      await inDirectory(tempDir, () async {
        await flutter(
          'create',
          options: <String>['--org', 'io.flutter.devicelab', '--template', 'module', 'hello'],
        );
      });

      section('Add plugins');

      final File pubspec = File(path.join(projectDir.path, 'pubspec.yaml'));
      String content = pubspec.readAsStringSync();
      content = content.replaceFirst(
        '\ndependencies:\n',
45
        '\ndependencies:\n  device_info: 0.4.1\n  package_info: 0.4.0+9\n',
46 47 48 49 50 51 52 53 54 55 56 57 58 59
      );
      pubspec.writeAsStringSync(content, flush: true);
      await inDirectory(projectDir, () async {
        await flutter(
          'packages',
          options: <String>['get'],
        );
      });

      section('Build release AAR');

      await inDirectory(projectDir, () async {
        await flutter(
          'build',
60
          options: <String>['aar', '--release', '--verbose'],
61 62 63 64 65 66 67 68 69 70 71
        );
      });

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

72 73
      section('Check release Maven artifacts');

74 75 76 77 78 79 80 81 82 83 84
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_release',
        '1.0',
        'flutter_release-1.0.aar',
      ));

85
      final String releasePom = path.join(
86 87 88 89 90 91 92 93
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_release',
        '1.0',
        'flutter_release-1.0.pom',
94
      );
95

96
      checkFileExists(releasePom);
97

98 99 100 101 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 138 139 140 141
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'plugins',
        'deviceinfo',
        'device_info_release',
        '1.0',
        'device_info_release-1.0.aar',
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'plugins',
        'deviceinfo',
        'device_info_release',
        '1.0',
        'device_info_release-1.0.pom',
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'plugins',
        'packageinfo',
        'package_info_release',
        '1.0',
        'package_info_release-1.0.aar',
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'plugins',
        'packageinfo',
        'package_info_release',
        '1.0',
        'package_info_release-1.0.pom',
      ));

142
      section('Check AOT blobs in release POM');
143

144 145 146 147
      checkFileContains(<String>[
        'flutter_embedding_release',
        'armeabi_v7a_release',
        'arm64_v8a_release',
148 149 150
        'x86_64_release',
        'package_info_release',
        'device_info_release',
151
      ], releasePom);
152

153 154
      section('Check assets in release AAR');

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

177 178 179 180 181 182 183 184 185
      section('Build debug AAR');

      await inDirectory(projectDir, () async {
        await flutter(
          'build',
          options: <String>['aar', '--verbose', '--debug'],
        );
      });

186 187
      section('Check debug Maven artifacts');

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

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

210
      checkFileExists(debugPom);
211

212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'plugins',
        'deviceinfo',
        'device_info_debug',
        '1.0',
        'device_info_debug-1.0.aar',
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'plugins',
        'deviceinfo',
        'device_info_debug',
        '1.0',
        'device_info_debug-1.0.pom',
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'plugins',
        'packageinfo',
        'package_info_debug',
        '1.0',
        'package_info_debug-1.0.aar',
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'plugins',
        'packageinfo',
        'package_info_debug',
        '1.0',
        'package_info_debug-1.0.pom',
      ));

256
      section('Check AOT blobs in debug POM');
257

258 259 260 261 262 263
      checkFileContains(<String>[
        'flutter_embedding_debug',
        'x86_debug',
        'x86_64_debug',
        'armeabi_v7a_debug',
        'arm64_v8a_debug',
264 265
        'package_info_debug',
        'device_info_debug',
266
      ], debugPom);
267 268 269 270 271 272 273 274 275 276 277 278 279 280

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

281
      checkCollectionContains<String>(<String>[
282
        ...flutterAssets,
283
        ...debugAssets,
284 285
      ], debugAar);

286
      return TaskResult.success(null);
287 288
    } on TaskResult catch (taskResult) {
      return taskResult;
289 290 291 292 293 294 295
    } catch (e) {
      return TaskResult.failure(e.toString());
    } finally {
      rmTree(tempDir);
    }
  });
}