Unverified Commit 5dabe102 authored by Gary Qian's avatar Gary Qian Committed by GitHub

Fix path name to discover debug apk on add2app builds (#117999)

parent d20dd9e4
......@@ -115,7 +115,13 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
}
if (androidProject.isUsingGradle && androidProject.isSupportedVersion) {
apkFile = getApkDirectory(androidProject.parent).childFile(filename);
Directory apkDirectory = getApkDirectory(androidProject.parent);
if (androidProject.parent.isModule) {
// Module builds output the apk in a subdirectory that corresponds
// to the buildmode of the apk.
apkDirectory = apkDirectory.childDirectory(buildInfo!.mode.name);
}
apkFile = apkDirectory.childFile(filename);
if (apkFile.existsSync()) {
// Grab information from the .apk. The gradle build script might alter
// the application Id, so we need to look at what was actually built.
......
......@@ -55,6 +55,73 @@ void main() {
).path).createSync(recursive: true);
});
testUsingContext('correct debug filename in module projects', () async {
const String aaptPath = 'aaptPath';
final File apkFile = globals.fs.file('app-debug.apk');
final FakeAndroidSdkVersion sdkVersion = FakeAndroidSdkVersion();
sdkVersion.aaptPath = aaptPath;
sdk.latestVersion = sdkVersion;
sdk.platformToolsAvailable = true;
sdk.licensesAvailable = false;
fakeProcessManager.addCommand(
FakeCommand(
command: <String>[
aaptPath,
'dump',
'xmltree',
apkFile.path,
'AndroidManifest.xml',
],
stdout: _aaptDataWithDefaultEnabledAndMainLauncherActivity
)
);
fakeProcessManager.addCommand(
FakeCommand(
command: <String>[
aaptPath,
'dump',
'xmltree',
fs.path.join('module_project', 'build', 'host', 'outputs', 'apk', 'debug', 'app-debug.apk'),
'AndroidManifest.xml',
],
stdout: _aaptDataWithDefaultEnabledAndMainLauncherActivity
)
);
await ApplicationPackageFactory.instance!.getPackageForPlatform(
TargetPlatform.android_arm,
applicationBinary: apkFile,
);
final BufferLogger logger = BufferLogger.test();
final FlutterProject project = await aModuleProject();
project.android.hostAppGradleRoot.childFile('build.gradle').createSync(recursive: true);
final File appGradle = project.android.hostAppGradleRoot.childFile(
fs.path.join('app', 'build.gradle'));
appGradle.createSync(recursive: true);
appGradle.writeAsStringSync("def flutterPluginVersion = 'managed'");
final File apkDebugFile = project.directory
.childDirectory('build')
.childDirectory('host')
.childDirectory('outputs')
.childDirectory('apk')
.childDirectory('debug')
.childFile('app-debug.apk');
apkDebugFile.createSync(recursive: true);
final AndroidApk? androidApk = await AndroidApk.fromAndroidProject(
project.android,
androidSdk: sdk,
processManager: fakeProcessManager,
userMessages: UserMessages(),
processUtils: ProcessUtils(processManager: fakeProcessManager, logger: logger),
logger: logger,
fileSystem: fs,
buildInfo: const BuildInfo(BuildMode.debug, null, treeShakeIcons: false),
);
expect(androidApk, isNotNull);
}, overrides: overrides);
testUsingContext('Licenses not available, platform and buildtools available, apk exists', () async {
const String aaptPath = 'aaptPath';
final File apkFile = globals.fs.file('app-debug.apk');
......@@ -895,3 +962,19 @@ class FakeAndroidSdkVersion extends Fake implements AndroidSdkVersion {
@override
late String aaptPath;
}
Future<FlutterProject> aModuleProject() async {
final Directory directory = globals.fs.directory('module_project');
directory
.childDirectory('.dart_tool')
.childFile('package_config.json')
..createSync(recursive: true)
..writeAsStringSync('{"configVersion":2,"packages":[]}');
directory.childFile('pubspec.yaml').writeAsStringSync('''
name: my_module
flutter:
module:
androidPackage: com.example
''');
return FlutterProject.fromDirectory(directory);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment