Ensure android.enableR8 is appended to a new line (#43187)

This commit is contained in:
Emmanuel Garcia
2019-10-21 16:52:30 -07:00
committed by GitHub
parent 27105cba2f
commit e82ddc4c7a
2 changed files with 29 additions and 2 deletions

View File

@@ -387,8 +387,14 @@ void migrateToR8(Directory directory) {
}
printTrace('set `android.enableR8=true` in gradle.properties');
try {
gradleProperties
.writeAsStringSync('android.enableR8=true\n', mode: FileMode.append);
// Add `android.enableR8=true` to the next line in gradle.properties.
if (propertiesContent.isNotEmpty && !propertiesContent.endsWith('\n')) {
gradleProperties
.writeAsStringSync('\nandroid.enableR8=true\n', mode: FileMode.append);
} else {
gradleProperties
.writeAsStringSync('android.enableR8=true\n', mode: FileMode.append);
}
} on FileSystemException {
throwToolExit(
'The tool failed to add `android.enableR8=true` to ${gradleProperties.path}. '

View File

@@ -1410,6 +1410,27 @@ Exception in thread "main" java.lang.NullPointerException
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
});
testUsingContext('appends android.enableR8=true to the new line', () {
final Directory sampleAppAndroid = fs.directory('/sample-app/android');
sampleAppAndroid.createSync(recursive: true);
sampleAppAndroid.childFile('gradle.properties')
.writeAsStringSync('org.gradle.jvmargs=-Xmx1536M');
migrateToR8(sampleAppAndroid);
expect(testLogger.traceText, contains('set `android.enableR8=true` in gradle.properties'));
expect(
sampleAppAndroid.childFile('gradle.properties').readAsStringSync(),
equals(
'org.gradle.jvmargs=-Xmx1536M\n'
'android.enableR8=true\n'
),
);
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager(<FakeCommand>[]),
});
});
group('isAppUsingAndroidX', () {