Skip to content

Commit e0660cf

Browse files
mboetgerreidbaker
andauthored
Fix null value reference in flutter logs path (#173437)
The `flutter logs` path for a module does not pass the buildInfo to the `fromAndroidProject` function. This will cause an exception to be thrown when `buildInfo!` is invoked. Instead, just allow the buildInfo to be null and check for the manifest with the code that already exists. Fixes: #172884 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [X] I signed the [CLA]. - [X] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [X] I added new tests to check the change I am making, or this PR is [test-exempt]. - [X] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [X] All existing and new tests are passing. --------- Co-authored-by: Reid Baker <reidbaker@google.com>
1 parent fde479c commit e0660cf

2 files changed

Lines changed: 64 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ class AndroidApk extends ApplicationPackage implements PrebuiltApplicationPackag
116116

117117
if (androidProject.isUsingGradle && androidProject.isSupportedVersion) {
118118
Directory apkDirectory = getApkDirectory(androidProject.parent);
119-
if (androidProject.parent.isModule) {
119+
if (androidProject.parent.isModule && buildInfo != null) {
120120
// Module builds output the apk in a subdirectory that corresponds
121121
// to the buildmode of the apk.
122-
apkDirectory = apkDirectory.childDirectory(buildInfo!.mode.cliName);
122+
apkDirectory = apkDirectory.childDirectory(buildInfo.mode.cliName);
123123
}
124124
apkFile = apkDirectory.childFile(filename);
125125
if (apkFile.existsSync()) {

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,68 @@ void main() {
5757
.createSync(recursive: true);
5858
});
5959

60+
testUsingContext('does not throw and exception when build info is null', () async {
61+
const aaptPath = 'aaptPath';
62+
final File apkFile = globals.fs.file('app.apk');
63+
final sdkVersion = FakeAndroidSdkVersion();
64+
sdkVersion.aaptPath = aaptPath;
65+
sdk.latestVersion = sdkVersion;
66+
sdk.platformToolsAvailable = true;
67+
sdk.licensesAvailable = false;
68+
69+
fakeProcessManager.addCommand(
70+
FakeCommand(
71+
command: <String>[aaptPath, 'dump', 'xmltree', apkFile.path, 'AndroidManifest.xml'],
72+
stdout: _aaptDataWithDefaultEnabledAndMainLauncherActivity,
73+
),
74+
);
75+
76+
fakeProcessManager.addCommand(
77+
FakeCommand(
78+
command: <String>[
79+
aaptPath,
80+
'dump',
81+
'xmltree',
82+
fs.path.join('module_project', 'build', 'host', 'outputs', 'apk', 'app.apk'),
83+
'AndroidManifest.xml',
84+
],
85+
stdout: _aaptDataWithDefaultEnabledAndMainLauncherActivity,
86+
),
87+
);
88+
89+
await ApplicationPackageFactory.instance!.getPackageForPlatform(
90+
TargetPlatform.android_arm,
91+
applicationBinary: apkFile,
92+
);
93+
final logger = BufferLogger.test();
94+
final FlutterProject project = await aModuleProject();
95+
project.android.hostAppGradleRoot.childFile('build.gradle').createSync(recursive: true);
96+
final File appGradle = project.android.hostAppGradleRoot.childFile(
97+
fs.path.join('app', 'build.gradle'),
98+
);
99+
appGradle.createSync(recursive: true);
100+
appGradle.writeAsStringSync("def flutterPluginVersion = 'managed'");
101+
final File apkDebugFile = project.directory
102+
.childDirectory('build')
103+
.childDirectory('host')
104+
.childDirectory('outputs')
105+
.childDirectory('apk')
106+
.childFile('app.apk');
107+
apkDebugFile.createSync(recursive: true);
108+
final AndroidApk? androidApk = await AndroidApk.fromAndroidProject(
109+
project.android,
110+
androidSdk: sdk,
111+
processManager: fakeProcessManager,
112+
userMessages: UserMessages(),
113+
processUtils: ProcessUtils(processManager: fakeProcessManager, logger: logger),
114+
logger: logger,
115+
fileSystem: fs,
116+
// ignore: avoid_redundant_argument_values
117+
buildInfo: null,
118+
);
119+
expect(androidApk, isNotNull);
120+
}, overrides: overrides);
121+
60122
testUsingContext('correct debug filename in module projects', () async {
61123
const aaptPath = 'aaptPath';
62124
final File apkFile = globals.fs.file('app-debug.apk');

0 commit comments

Comments
 (0)