build_aar_module_test.dart 6.7 KB
Newer Older
1 2 3 4 5 6 7
// Copyright (c) 2019 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 'dart:io';

8
import 'package:flutter_devicelab/framework/apk_utils.dart';
9 10 11 12 13 14 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 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
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';
final String gradlewExecutable = Platform.isWindows ? gradlew : './$gradlew';

/// 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',
        '\ndependencies:\n  device_info:\n  package_info:\n',
      );
      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',
          options: <String>['aar', '--verbose'],
        );
      });

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

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_release',
        '1.0',
        'flutter_release-1.0.aar',
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_release',
        '1.0',
        'flutter_release-1.0.pom',
      ));

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

138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
      section('Check assets in release AAR');

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

      checkItContains<String>(<String>[
        'assets/flutter_assets/FontManifest.json',
        'assets/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf',
      ], releaseAar);

      section('Check AOT blobs in release AAR');

      checkItContains<String>(<String>[
        'jni/arm64-v8a/libapp.so',
        'jni/arm64-v8a/libflutter.so',
        'jni/armeabi-v7a/libapp.so',
        'jni/armeabi-v7a/libflutter.so',
      ], releaseAar);

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
      section('Build debug AAR');

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

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
180
        'flutter_debug',
181
        '1.0',
182
        'flutter_debug-1.0.aar',
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 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
      ));

      checkFileExists(path.join(
        repoPath,
        'io',
        'flutter',
        'devicelab',
        'hello',
        'flutter_debug',
        '1.0',
        'flutter_debug-1.0.pom',
      ));

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

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

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

      checkItContains<String>(<String>[
        'assets/flutter_assets/FontManifest.json',
        'assets/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf',
        // JIT snapshots.
        'assets/flutter_assets/isolate_snapshot_data',
        'assets/flutter_assets/kernel_blob.bin',
        'assets/flutter_assets/vm_snapshot_data',
      ], debugAar);

      section('Check AOT blobs in debug AAR');

      checkItContains<String>(<String>[
        'jni/arm64-v8a/libflutter.so',
        'jni/armeabi-v7a/libflutter.so',
        'jni/x86/libflutter.so',
        'jni/x86_64/libflutter.so',
      ], debugAar);

272
      return TaskResult.success(null);
273 274
    } on TaskResult catch (taskResult) {
      return taskResult;
275 276 277 278 279 280 281
    } catch (e) {
      return TaskResult.failure(e.toString());
    } finally {
      rmTree(tempDir);
    }
  });
}