Skip to content

Commit e61ab4a

Browse files
author
Emmanuel Garcia
authored
Copy APK into a known location, so it can be easily discovered (flutter#53718)
1 parent b6423e4 commit e61ab4a

File tree

5 files changed

+53
-17
lines changed

5 files changed

+53
-17
lines changed

dev/devicelab/bin/tasks/gradle_jetifier_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ Future<void> main() async {
8080
'build',
8181
'app',
8282
'outputs',
83-
'apk',
84-
'release',
83+
'flutter-apk',
8584
'app-release.apk',
8685
));
8786

@@ -118,8 +117,7 @@ Future<void> main() async {
118117
'build',
119118
'app',
120119
'outputs',
121-
'apk',
122-
'debug',
120+
'flutter-apk',
123121
'app-debug.apk',
124122
));
125123

dev/devicelab/bin/tasks/gradle_plugin_dependencies_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ Future<void> main() async {
7777
'build',
7878
'app',
7979
'outputs',
80-
'apk',
81-
'release',
80+
'flutter-apk',
8281
'app-release.apk',
8382
));
8483

@@ -116,8 +115,7 @@ Future<void> main() async {
116115
'build',
117116
'app',
118117
'outputs',
119-
'apk',
120-
'debug',
118+
'flutter-apk',
121119
'app-debug.apk',
122120
));
123121

dev/devicelab/bin/tasks/gradle_plugins_without_annotations_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ Future<void> main() async {
8484
'build',
8585
'app',
8686
'outputs',
87-
'apk',
88-
'release',
87+
'flutter-apk',
8988
'app-release.apk',
9089
));
9190

@@ -118,8 +117,7 @@ Future<void> main() async {
118117
'build',
119118
'app',
120119
'outputs',
121-
'apk',
122-
'debug',
120+
'flutter-apk',
123121
'app-debug.apk',
124122
));
125123

dev/devicelab/lib/framework/apk_utils.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,10 @@ class FlutterPluginProject {
332332
String get rootPath => path.join(parent.path, name);
333333
String get examplePath => path.join(rootPath, 'example');
334334
String get exampleAndroidPath => path.join(examplePath, 'android');
335-
String get debugApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'apk', 'debug', 'app-debug.apk');
336-
String get releaseApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'apk', 'release', 'app-release.apk');
337-
String get releaseArmApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'apk', 'release', 'app-armeabi-v7a-release.apk');
338-
String get releaseArm64ApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'apk', 'release', 'app-arm64-v8a-release.apk');
335+
String get debugApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'flutter-apk', 'app-debug.apk');
336+
String get releaseApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'flutter-apk', 'app-release.apk');
337+
String get releaseArmApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'flutter-apk','app-armeabi-v7a-release.apk');
338+
String get releaseArm64ApkPath => path.join(examplePath, 'build', 'app', 'outputs', 'flutter-apk', 'app-arm64-v8a-release.apk');
339339
String get releaseBundlePath => path.join(examplePath, 'build', 'app', 'outputs', 'bundle', 'release', 'app.aab');
340340

341341
Future<void> runGradleTask(String task, {List<String> options}) async {

packages/flutter_tools/gradle/flutter.gradle

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,49 @@ class FlutterPlugin implements Plugin<Project> {
757757
}
758758
}
759759
if (project.android.hasProperty("applicationVariants")) {
760-
project.android.applicationVariants.all addFlutterDeps
760+
project.android.applicationVariants.all { variant ->
761+
addFlutterDeps(variant)
762+
// Copy the output APKs into a known location, so `flutter run` or `flutter build apk`
763+
// can discover them. By default, this is `<app-dir>/build/app/outputs/flutter-apk/<filename>.apk`.
764+
//
765+
// The filename consists of `app<-abi>?<-flavor-name>?-<build-mode>.apk`.
766+
// Where:
767+
// * `abi` can be `armeabi-v7a|arm64-v8a|x86|x86_64` only if the flag `split-per-abi` is set.
768+
// * `flavor-name` is the flavor used to build the app in lower case if the assemble task is called.
769+
// * `build-mode` can be `release|debug|profile`.
770+
variant.outputs.all { output ->
771+
// `assemble` became `assembleProvider` in AGP 3.3.0.
772+
def assembleTask = variant.hasProperty("assembleProvider")
773+
? variant.assembleProvider.get()
774+
: variant.assemble
775+
assembleTask.doLast {
776+
// `packageApplication` became `packageApplicationProvider` in AGP 3.3.0.
777+
def outputDirectory = variant.hasProperty("packageApplicationProvider")
778+
? variant.packageApplicationProvider.get().outputDirectory
779+
: variant.packageApplication.outputDirectory
780+
// `outputDirectory` is a `DirectoryProperty` in AGP 4.1.
781+
String outputDirectoryStr = outputDirectory.metaClass.respondsTo(outputDirectory, "get")
782+
? outputDirectory.get()
783+
: outputDirectory
784+
String filename = "app"
785+
String abi = output.getFilter(OutputFile.ABI)
786+
if (abi != null && !abi.isEmpty()) {
787+
filename += "-${abi}"
788+
}
789+
if (variant.flavorName != null && !variant.flavorName.isEmpty()) {
790+
filename += "-${variant.flavorName.toLowerCase()}"
791+
}
792+
filename += "-${buildModeFor(variant.buildType)}"
793+
project.copy {
794+
from new File("$outputDirectoryStr/${output.outputFileName}")
795+
into new File("${project.buildDir}/outputs/flutter-apk");
796+
rename {
797+
return "${filename}.apk"
798+
}
799+
}
800+
}
801+
}
802+
}
761803
} else {
762804
project.android.libraryVariants.all addFlutterDeps
763805
}

0 commit comments

Comments
 (0)