multidex_build_test.dart 1.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
// Copyright 2014 The Flutter 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 'package:file/file.dart';
import 'package:flutter_tools/src/base/io.dart';

import '../src/common.dart';
import 'test_data/multidex_project.dart';
import 'test_driver.dart';
import 'test_utils.dart';

void main() {
14 15
  late Directory tempDir;
  late FlutterRunTestDriver flutter;
16 17 18

  setUp(() async {
    tempDir = createResolvedTempDirectorySync('run_test.');
19
    flutter = FlutterRunTestDriver(tempDir);
20 21 22
  });

  tearDown(() async {
23
    await flutter.stop();
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
    tryToDelete(tempDir);
  });

  testWithoutContext('simple build apk succeeds', () async {
    final MultidexProject project = MultidexProject(true);
    await project.setUpIn(tempDir);
    final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
    final ProcessResult result = await processManager.run(<String>[
      flutterBin,
      ...getLocalEngineArguments(),
      'build',
      'apk',
      '--debug',
    ], workingDirectory: tempDir.path);

    expect(result.exitCode, 0);
    expect(result.stdout.toString(), contains('app-debug.apk'));
  });

  testWithoutContext('simple build apk without FlutterMultiDexApplication fails', () async {
    final MultidexProject project = MultidexProject(false);
    await project.setUpIn(tempDir);
    final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
    final ProcessResult result = await processManager.run(<String>[
      flutterBin,
      ...getLocalEngineArguments(),
      'build',
      'apk',
      '--debug',
    ], workingDirectory: tempDir.path);

    expect(result.stderr.toString(), contains('Cannot fit requested classes in a single dex file'));
    expect(result.stderr.toString(), contains('The number of method references in a .dex file cannot exceed 64K.'));
    expect(result.exitCode, 1);
  });
}