Support string compileSdkVersion for preview android SDKs (#104662)
This commit is contained in:
@@ -458,7 +458,10 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
/** Prints error message and fix for any plugin compileSdkVersion or ndkVersion that are higher than the project. */
|
||||
private void detectLowCompileSdkVersionOrNdkVersion() {
|
||||
project.afterEvaluate {
|
||||
int projectCompileSdkVersion = project.android.compileSdkVersion.substring(8) as int
|
||||
int projectCompileSdkVersion = Integer.MAX_VALUE // Default to int max if using a preview version to skip the sdk check.
|
||||
if (project.android.compileSdkVersion.substring(8).isInteger()) { // Stable versions use ints, legacy preview uses string.
|
||||
projectCompileSdkVersion = project.android.compileSdkVersion.substring(8) as int
|
||||
}
|
||||
int maxPluginCompileSdkVersion = projectCompileSdkVersion
|
||||
String ndkVersionIfUnspecified = "21.1.6352462" /* The default for AGP 4.1.0 used in old templates. */
|
||||
String projectNdkVersion = project.android.ndkVersion ?: ndkVersionIfUnspecified
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
late Directory tempDir;
|
||||
late String flutterBin;
|
||||
late Directory exampleAppDir;
|
||||
|
||||
setUp(() async {
|
||||
tempDir = createResolvedTempDirectorySync('flutter_plugin_test.');
|
||||
flutterBin = fileSystem.path.join(
|
||||
getFlutterRoot(),
|
||||
'bin',
|
||||
'flutter',
|
||||
);
|
||||
exampleAppDir = tempDir.childDirectory('aaa').childDirectory('example');
|
||||
|
||||
processManager.runSync(<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'create',
|
||||
'--template=plugin',
|
||||
'--platforms=android',
|
||||
'aaa',
|
||||
], workingDirectory: tempDir.path);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
test(
|
||||
'build succeeds targeting string compileSdkVersion',
|
||||
() async {
|
||||
final File buildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle');
|
||||
// write a build.gradle with compileSdkVersion as `android-Tiramisu` which is a string preview version
|
||||
buildGradleFile.writeAsStringSync(
|
||||
buildGradleFile.readAsStringSync().replaceFirst('compileSdkVersion flutter.compileSdkVersion', 'compileSdkVersion "android-Tiramisu"'),
|
||||
flush: true
|
||||
);
|
||||
expect(buildGradleFile.readAsStringSync(), contains('compileSdkVersion "android-Tiramisu"'));
|
||||
|
||||
final ProcessResult result = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'build',
|
||||
'apk',
|
||||
'--debug',
|
||||
], workingDirectory: exampleAppDir.path);
|
||||
expect(result.stdout, contains('Built build/app/outputs/flutter-apk/app-debug.apk.'));
|
||||
expect(exampleAppDir.childDirectory('build')
|
||||
.childDirectory('app')
|
||||
.childDirectory('outputs')
|
||||
.childDirectory('apk')
|
||||
.childDirectory('debug')
|
||||
.childFile('app-debug.apk').existsSync(), true);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'build succeeds targeting string compileSdkPreview',
|
||||
() async {
|
||||
final File buildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle');
|
||||
// write a build.gradle with compileSdkPreview as `Tiramisu` which is a string preview version
|
||||
buildGradleFile.writeAsStringSync(
|
||||
buildGradleFile.readAsStringSync().replaceFirst('compileSdkVersion flutter.compileSdkVersion', 'compileSdkPreview "Tiramisu"'),
|
||||
flush: true
|
||||
);
|
||||
expect(buildGradleFile.readAsStringSync(), contains('compileSdkPreview "Tiramisu"'));
|
||||
|
||||
final ProcessResult result = await processManager.run(<String>[
|
||||
flutterBin,
|
||||
...getLocalEngineArguments(),
|
||||
'build',
|
||||
'apk',
|
||||
'--debug',
|
||||
], workingDirectory: exampleAppDir.path);
|
||||
expect(result.stdout, contains('Built build/app/outputs/flutter-apk/app-debug.apk.'));
|
||||
expect(exampleAppDir.childDirectory('build')
|
||||
.childDirectory('app')
|
||||
.childDirectory('outputs')
|
||||
.childDirectory('apk')
|
||||
.childDirectory('debug')
|
||||
.childFile('app-debug.apk').existsSync(), true);
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user