Skip to content

Commit

Permalink
Fix path name to discover debug apk on add2app builds (#117999)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaryQian committed Jan 24, 2023
1 parent d20dd9e commit 5dabe10
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
Expand Up @@ -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.
Expand Down
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}

0 comments on commit 5dabe10

Please sign in to comment.