Copy APK into a known location, so it can be easily discovered (#53718)

This commit is contained in:
Emmanuel Garcia 2020-04-01 10:03:56 -07:00 committed by GitHub
parent b6423e454d
commit e61ab4a832
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 17 deletions

View file

@ -80,8 +80,7 @@ Future<void> main() async {
'build',
'app',
'outputs',
'apk',
'release',
'flutter-apk',
'app-release.apk',
));
@ -118,8 +117,7 @@ Future<void> main() async {
'build',
'app',
'outputs',
'apk',
'debug',
'flutter-apk',
'app-debug.apk',
));

View file

@ -77,8 +77,7 @@ Future<void> main() async {
'build',
'app',
'outputs',
'apk',
'release',
'flutter-apk',
'app-release.apk',
));
@ -116,8 +115,7 @@ Future<void> main() async {
'build',
'app',
'outputs',
'apk',
'debug',
'flutter-apk',
'app-debug.apk',
));

View file

@ -84,8 +84,7 @@ Future<void> main() async {
'build',
'app',
'outputs',
'apk',
'release',
'flutter-apk',
'app-release.apk',
));
@ -118,8 +117,7 @@ Future<void> main() async {
'build',
'app',
'outputs',
'apk',
'debug',
'flutter-apk',
'app-debug.apk',
));

View file

@ -332,10 +332,10 @@ class FlutterPluginProject {
String get rootPath => path.join(parent.path, name);
String get examplePath => path.join(rootPath, 'example');
String get exampleAndroidPath => path.join(examplePath, 'android');
String get debugApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'apk', 'debug', 'app-debug.apk');
String get releaseApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'apk', 'release', 'app-release.apk');
String get releaseArmApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'apk', 'release', 'app-armeabi-v7a-release.apk');
String get releaseArm64ApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'apk', 'release', 'app-arm64-v8a-release.apk');
String get debugApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'flutter-apk', 'app-debug.apk');
String get releaseApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'flutter-apk', 'app-release.apk');
String get releaseArmApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'flutter-apk','app-armeabi-v7a-release.apk');
String get releaseArm64ApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'flutter-apk', 'app-arm64-v8a-release.apk');
String get releaseBundlePath => path.join(examplePath, 'build', 'app', 'outputs', 'bundle', 'release', 'app.aab');
Future<void> runGradleTask(String task, {List<String> options}) async {

View file

@ -757,7 +757,49 @@ class FlutterPlugin implements Plugin<Project> {
}
}
if (project.android.hasProperty("applicationVariants")) {
project.android.applicationVariants.all addFlutterDeps
project.android.applicationVariants.all { variant ->
addFlutterDeps(variant)
// Copy the output APKs into a known location, so `flutter run` or `flutter build apk`
// can discover them. By default, this is `<app-dir>/build/app/outputs/flutter-apk/<filename>.apk`.
//
// The filename consists of `app<-abi>?<-flavor-name>?-<build-mode>.apk`.
// Where:
// * `abi` can be `armeabi-v7a|arm64-v8a|x86|x86_64` only if the flag `split-per-abi` is set.
// * `flavor-name` is the flavor used to build the app in lower case if the assemble task is called.
// * `build-mode` can be `release|debug|profile`.
variant.outputs.all { output ->
// `assemble` became `assembleProvider` in AGP 3.3.0.
def assembleTask = variant.hasProperty("assembleProvider")
? variant.assembleProvider.get()
: variant.assemble
assembleTask.doLast {
// `packageApplication` became `packageApplicationProvider` in AGP 3.3.0.
def outputDirectory = variant.hasProperty("packageApplicationProvider")
? variant.packageApplicationProvider.get().outputDirectory
: variant.packageApplication.outputDirectory
// `outputDirectory` is a `DirectoryProperty` in AGP 4.1.
String outputDirectoryStr = outputDirectory.metaClass.respondsTo(outputDirectory, "get")
? outputDirectory.get()
: outputDirectory
String filename = "app"
String abi = output.getFilter(OutputFile.ABI)
if (abi != null && !abi.isEmpty()) {
filename += "-${abi}"
}
if (variant.flavorName != null && !variant.flavorName.isEmpty()) {
filename += "-${variant.flavorName.toLowerCase()}"
}
filename += "-${buildModeFor(variant.buildType)}"
project.copy {
from new File("$outputDirectoryStr/${output.outputFileName}")
into new File("${project.buildDir}/outputs/flutter-apk");
rename {
return "${filename}.apk"
}
}
}
}
}
} else {
project.android.libraryVariants.all addFlutterDeps
}