Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 5dabe10

Browse files
authored
Fix path name to discover debug apk on add2app builds (#117999)
1 parent d20dd9e commit 5dabe10

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

packages/flutter_tools/lib/src/android/application_package.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
115115
}
116116

117117
if (androidProject.isUsingGradle && androidProject.isSupportedVersion) {
118-
apkFile = getApkDirectory(androidProject.parent).childFile(filename);
118+
Directory apkDirectory = getApkDirectory(androidProject.parent);
119+
if (androidProject.parent.isModule) {
120+
// Module builds output the apk in a subdirectory that corresponds
121+
// to the buildmode of the apk.
122+
apkDirectory = apkDirectory.childDirectory(buildInfo!.mode.name);
123+
}
124+
apkFile = apkDirectory.childFile(filename);
119125
if (apkFile.existsSync()) {
120126
// Grab information from the .apk. The gradle build script might alter
121127
// the application Id, so we need to look at what was actually built.

packages/flutter_tools/test/general.shard/application_package_test.dart

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,73 @@ void main() {
5555
).path).createSync(recursive: true);
5656
});
5757

58+
testUsingContext('correct debug filename in module projects', () async {
59+
const String aaptPath = 'aaptPath';
60+
final File apkFile = globals.fs.file('app-debug.apk');
61+
final FakeAndroidSdkVersion sdkVersion = FakeAndroidSdkVersion();
62+
sdkVersion.aaptPath = aaptPath;
63+
sdk.latestVersion = sdkVersion;
64+
sdk.platformToolsAvailable = true;
65+
sdk.licensesAvailable = false;
66+
67+
fakeProcessManager.addCommand(
68+
FakeCommand(
69+
command: <String>[
70+
aaptPath,
71+
'dump',
72+
'xmltree',
73+
apkFile.path,
74+
'AndroidManifest.xml',
75+
],
76+
stdout: _aaptDataWithDefaultEnabledAndMainLauncherActivity
77+
)
78+
);
79+
80+
fakeProcessManager.addCommand(
81+
FakeCommand(
82+
command: <String>[
83+
aaptPath,
84+
'dump',
85+
'xmltree',
86+
fs.path.join('module_project', 'build', 'host', 'outputs', 'apk', 'debug', 'app-debug.apk'),
87+
'AndroidManifest.xml',
88+
],
89+
stdout: _aaptDataWithDefaultEnabledAndMainLauncherActivity
90+
)
91+
);
92+
93+
await ApplicationPackageFactory.instance!.getPackageForPlatform(
94+
TargetPlatform.android_arm,
95+
applicationBinary: apkFile,
96+
);
97+
final BufferLogger logger = BufferLogger.test();
98+
final FlutterProject project = await aModuleProject();
99+
project.android.hostAppGradleRoot.childFile('build.gradle').createSync(recursive: true);
100+
final File appGradle = project.android.hostAppGradleRoot.childFile(
101+
fs.path.join('app', 'build.gradle'));
102+
appGradle.createSync(recursive: true);
103+
appGradle.writeAsStringSync("def flutterPluginVersion = 'managed'");
104+
final File apkDebugFile = project.directory
105+
.childDirectory('build')
106+
.childDirectory('host')
107+
.childDirectory('outputs')
108+
.childDirectory('apk')
109+
.childDirectory('debug')
110+
.childFile('app-debug.apk');
111+
apkDebugFile.createSync(recursive: true);
112+
final AndroidApk? androidApk = await AndroidApk.fromAndroidProject(
113+
project.android,
114+
androidSdk: sdk,
115+
processManager: fakeProcessManager,
116+
userMessages: UserMessages(),
117+
processUtils: ProcessUtils(processManager: fakeProcessManager, logger: logger),
118+
logger: logger,
119+
fileSystem: fs,
120+
buildInfo: const BuildInfo(BuildMode.debug, null, treeShakeIcons: false),
121+
);
122+
expect(androidApk, isNotNull);
123+
}, overrides: overrides);
124+
58125
testUsingContext('Licenses not available, platform and buildtools available, apk exists', () async {
59126
const String aaptPath = 'aaptPath';
60127
final File apkFile = globals.fs.file('app-debug.apk');
@@ -895,3 +962,19 @@ class FakeAndroidSdkVersion extends Fake implements AndroidSdkVersion {
895962
@override
896963
late String aaptPath;
897964
}
965+
966+
Future<FlutterProject> aModuleProject() async {
967+
final Directory directory = globals.fs.directory('module_project');
968+
directory
969+
.childDirectory('.dart_tool')
970+
.childFile('package_config.json')
971+
..createSync(recursive: true)
972+
..writeAsStringSync('{"configVersion":2,"packages":[]}');
973+
directory.childFile('pubspec.yaml').writeAsStringSync('''
974+
name: my_module
975+
flutter:
976+
module:
977+
androidPackage: com.example
978+
''');
979+
return FlutterProject.fromDirectory(directory);
980+
}

0 commit comments

Comments
 (0)