From e61ab4a8324abb0dde014755b6e916d4120cec21 Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Wed, 1 Apr 2020 10:03:56 -0700 Subject: [PATCH] Copy APK into a known location, so it can be easily discovered (#53718) --- .../bin/tasks/gradle_jetifier_test.dart | 6 +-- .../gradle_plugin_dependencies_test.dart | 6 +-- ...adle_plugins_without_annotations_test.dart | 6 +-- dev/devicelab/lib/framework/apk_utils.dart | 8 ++-- packages/flutter_tools/gradle/flutter.gradle | 44 ++++++++++++++++++- 5 files changed, 53 insertions(+), 17 deletions(-) diff --git a/dev/devicelab/bin/tasks/gradle_jetifier_test.dart b/dev/devicelab/bin/tasks/gradle_jetifier_test.dart index 08991f95f20..fa5b8f9629f 100644 --- a/dev/devicelab/bin/tasks/gradle_jetifier_test.dart +++ b/dev/devicelab/bin/tasks/gradle_jetifier_test.dart @@ -80,8 +80,7 @@ Future main() async { 'build', 'app', 'outputs', - 'apk', - 'release', + 'flutter-apk', 'app-release.apk', )); @@ -118,8 +117,7 @@ Future main() async { 'build', 'app', 'outputs', - 'apk', - 'debug', + 'flutter-apk', 'app-debug.apk', )); diff --git a/dev/devicelab/bin/tasks/gradle_plugin_dependencies_test.dart b/dev/devicelab/bin/tasks/gradle_plugin_dependencies_test.dart index 68d38bd59e6..92576f99e32 100644 --- a/dev/devicelab/bin/tasks/gradle_plugin_dependencies_test.dart +++ b/dev/devicelab/bin/tasks/gradle_plugin_dependencies_test.dart @@ -77,8 +77,7 @@ Future main() async { 'build', 'app', 'outputs', - 'apk', - 'release', + 'flutter-apk', 'app-release.apk', )); @@ -116,8 +115,7 @@ Future main() async { 'build', 'app', 'outputs', - 'apk', - 'debug', + 'flutter-apk', 'app-debug.apk', )); diff --git a/dev/devicelab/bin/tasks/gradle_plugins_without_annotations_test.dart b/dev/devicelab/bin/tasks/gradle_plugins_without_annotations_test.dart index 8562980ae0a..ed4c76096b4 100644 --- a/dev/devicelab/bin/tasks/gradle_plugins_without_annotations_test.dart +++ b/dev/devicelab/bin/tasks/gradle_plugins_without_annotations_test.dart @@ -84,8 +84,7 @@ Future main() async { 'build', 'app', 'outputs', - 'apk', - 'release', + 'flutter-apk', 'app-release.apk', )); @@ -118,8 +117,7 @@ Future main() async { 'build', 'app', 'outputs', - 'apk', - 'debug', + 'flutter-apk', 'app-debug.apk', )); diff --git a/dev/devicelab/lib/framework/apk_utils.dart b/dev/devicelab/lib/framework/apk_utils.dart index 31223c2ea81..1eb4955267b 100644 --- a/dev/devicelab/lib/framework/apk_utils.dart +++ b/dev/devicelab/lib/framework/apk_utils.dart @@ -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 runGradleTask(String task, {List options}) async { diff --git a/packages/flutter_tools/gradle/flutter.gradle b/packages/flutter_tools/gradle/flutter.gradle index 91d948688b6..3e26e4523ad 100644 --- a/packages/flutter_tools/gradle/flutter.gradle +++ b/packages/flutter_tools/gradle/flutter.gradle @@ -757,7 +757,49 @@ class FlutterPlugin implements Plugin { } } 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 `/build/app/outputs/flutter-apk/.apk`. + // + // The filename consists of `app<-abi>?<-flavor-name>?-.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 }