Look for APKs at the path used by Android Gradle plugin 3.0 (#10798)
Fixes https://github.com/flutter/flutter/issues/10630
This commit is contained in:
@@ -211,6 +211,17 @@ Future<Null> buildGradleProjectV1(String gradle) async {
|
||||
printStatus('Built $gradleAppOutV1 (${getSizeAsMB(apkFile.lengthSync())}).');
|
||||
}
|
||||
|
||||
File findApkFile(String buildDirectory, String buildModeName) {
|
||||
final String apkFilename = 'app-$buildModeName.apk';
|
||||
File apkFile = fs.file('$buildDirectory/$apkFilename');
|
||||
if (apkFile.existsSync())
|
||||
return apkFile;
|
||||
apkFile = fs.file('$buildDirectory/$buildModeName/$apkFilename');
|
||||
if (apkFile.existsSync())
|
||||
return apkFile;
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<Null> buildGradleProjectV2(String gradle, String buildModeName, String target, String kernelPath) async {
|
||||
final String assembleTask = "assemble${toTitleCase(buildModeName)}";
|
||||
|
||||
@@ -244,8 +255,9 @@ Future<Null> buildGradleProjectV2(String gradle, String buildModeName, String ta
|
||||
throwToolExit('Gradle build failed: $exitcode', exitCode: exitcode);
|
||||
|
||||
final String buildDirectory = getGradleAppOutDirV2();
|
||||
final String apkFilename = 'app-$buildModeName.apk';
|
||||
final File apkFile = fs.file('$buildDirectory/$apkFilename');
|
||||
final File apkFile = findApkFile(buildDirectory, buildModeName);
|
||||
if (apkFile == null)
|
||||
throwToolExit('Gradle build failed to produce an Android package.');
|
||||
// Copy the APK to app.apk, so `flutter run`, `flutter install`, etc. can find it.
|
||||
apkFile.copySync('$buildDirectory/app.apk');
|
||||
|
||||
|
||||
34
packages/flutter_tools/test/android/gradle_test.dart
Normal file
34
packages/flutter_tools/test/android/gradle_test.dart
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright 2017 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 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/android/gradle.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../src/context.dart';
|
||||
|
||||
const String _kBuildDirectory = '/build/app/outputs';
|
||||
|
||||
void main() {
|
||||
FileSystem fs;
|
||||
|
||||
setUp(() {
|
||||
fs = new MemoryFileSystem();
|
||||
fs.directory('$_kBuildDirectory/release').createSync(recursive: true);
|
||||
fs.file('$_kBuildDirectory/app-debug.apk').createSync();
|
||||
fs.file('$_kBuildDirectory/release/app-release.apk').createSync();
|
||||
});
|
||||
|
||||
group('gradle', () {
|
||||
testUsingContext('findApkFile', () {
|
||||
expect(findApkFile(_kBuildDirectory, 'debug').path,
|
||||
'/build/app/outputs/app-debug.apk');
|
||||
expect(findApkFile(_kBuildDirectory, 'release').path,
|
||||
'/build/app/outputs/release/app-release.apk');
|
||||
}, overrides: <Type, Generator>{
|
||||
FileSystem: () => fs,
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user