Update template/test compileSdk, targetSdk, ndk versions (#152487)
Updates `compileSdk`, `targetSdk`, and `ndk` versions (former 2 to latest, latter to the version of the ndk we are hosting on CIPD). Summary of changes: - Updates mentioned template values - `compileSdk` 35 requires AGP 8.0+, so updated to 8.1 in many places. - This also necessitated Gradle upgrades in most places - This also necessitated moving the `package` xml attribute to the AGP `namespace` field in a couple places (test + template). - Some tests use the output of `flutter create` but then use intentionally lower AGP versions. [I downgraded the `compileSdk` in these tests.](fee34fd61a) - [Stopped lockfile generation](82324a2570) script from hitting the `hello_world` example because it uses `.kts` gradle files. - One test needed [some Gradle options we had already added to templates](6aa187b4b6).
This commit is contained in:
@@ -42,7 +42,7 @@ import org.gradle.internal.os.OperatingSystem
|
||||
class FlutterExtension {
|
||||
|
||||
/** Sets the compileSdkVersion used by default in Flutter app projects. */
|
||||
public final int compileSdkVersion = 34
|
||||
public final int compileSdkVersion = 35
|
||||
|
||||
/** Sets the minSdkVersion used by default in Flutter app projects. */
|
||||
public final int minSdkVersion = 21
|
||||
@@ -53,14 +53,14 @@ class FlutterExtension {
|
||||
*
|
||||
* See https://developer.android.com/guide/topics/manifest/uses-sdk-element.
|
||||
*/
|
||||
public final int targetSdkVersion = 34
|
||||
public final int targetSdkVersion = 35
|
||||
|
||||
/**
|
||||
* Sets the ndkVersion used by default in Flutter app projects.
|
||||
* Chosen as default version of the AGP version below as found in
|
||||
* https://developer.android.com/studio/projects/install-ndk#default-ndk-per-agp.
|
||||
*/
|
||||
public final String ndkVersion = "23.1.7779620"
|
||||
public final String ndkVersion = "26.1.10909125"
|
||||
|
||||
/**
|
||||
* Specifies the relative directory to the Flutter project directory.
|
||||
|
||||
@@ -80,6 +80,7 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[
|
||||
incompatibleJavaAndGradleVersionsHandler,
|
||||
remoteTerminatedHandshakeHandler,
|
||||
couldNotOpenCacheDirectoryHandler,
|
||||
incompatibleCompileSdk35AndAgpVersionHandler,
|
||||
];
|
||||
|
||||
const String _boxTitle = 'Flutter Fix';
|
||||
@@ -640,3 +641,26 @@ final GradleHandledError couldNotOpenCacheDirectoryHandler = GradleHandledError(
|
||||
},
|
||||
eventLabel: 'could-not-open-cache-directory',
|
||||
);
|
||||
|
||||
@visibleForTesting
|
||||
final GradleHandledError incompatibleCompileSdk35AndAgpVersionHandler = GradleHandledError(
|
||||
test: (String line) => line.contains('RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data'),
|
||||
handler: ({
|
||||
required String line,
|
||||
required FlutterProject project,
|
||||
required bool usesAndroidX,
|
||||
}) async {
|
||||
globals.printBox(
|
||||
'${globals.logger.terminal.warningMark} Using compileSdk 35 requires Android Gradle Plugin (AGP) 8.1.0 or higher.'
|
||||
' \n Please upgrade to a newer AGP version. The version of AGP that your project uses is likely'
|
||||
" defined in:\n${project.android.settingsGradleFile.path},\nin the 'plugins' closure. \n Alternatively, if your "
|
||||
'project was created with an older version of the templates, it is likely \nin the buildscript.dependencies '
|
||||
'closure of the top-level build.gradle:\n${project.android.hostAppGradleFile.path}.\n\n Finally, if you have a'
|
||||
' strong reason to avoid upgrading AGP, you can temporarily lower the compileSdk version in the following file:\n${project.android.appGradleFile.path}',
|
||||
title: _boxTitle,
|
||||
);
|
||||
|
||||
return GradleBuildStatus.exit;
|
||||
},
|
||||
eventLabel: 'incompatible-compile-sdk-and-agp',
|
||||
);
|
||||
|
||||
@@ -38,10 +38,10 @@ const String templateKotlinGradlePluginVersion = '1.8.22';
|
||||
// so new versions are picked up after a Flutter upgrade.
|
||||
//
|
||||
// Please see the README before changing any of these values.
|
||||
const String compileSdkVersion = '34';
|
||||
const String compileSdkVersion = '35';
|
||||
const String minSdkVersion = '21';
|
||||
const String targetSdkVersion = '34';
|
||||
const String ndkVersion = '23.1.7779620';
|
||||
const String targetSdkVersion = '35';
|
||||
const String ndkVersion = '26.1.10909125';
|
||||
|
||||
|
||||
// Update these when new major versions of Java are supported by new Gradle
|
||||
|
||||
@@ -568,22 +568,33 @@ class AndroidProject extends FlutterProjectPlatform {
|
||||
/// The file must exist and it must be written in either Groovy (build.gradle)
|
||||
/// or Kotlin (build.gradle.kts).
|
||||
File get hostAppGradleFile {
|
||||
final File buildGroovy = hostAppGradleRoot.childFile('build.gradle');
|
||||
final File buildKotlin = hostAppGradleRoot.childFile('build.gradle.kts');
|
||||
return getGroovyOrKotlin(hostAppGradleRoot, 'build.gradle');
|
||||
}
|
||||
|
||||
if (buildGroovy.existsSync() && buildKotlin.existsSync()) {
|
||||
/// Gets the project root level Gradle settings file.
|
||||
///
|
||||
/// The file must exist and it must be written in either Groovy (build.gradle)
|
||||
/// or Kotlin (build.gradle.kts).
|
||||
File get settingsGradleFile {
|
||||
return getGroovyOrKotlin(hostAppGradleRoot, 'settings.gradle');
|
||||
}
|
||||
|
||||
File getGroovyOrKotlin(Directory directory, String baseFilename) {
|
||||
final File groovyFile = directory.childFile(baseFilename);
|
||||
final File kotlinFile = directory.childFile('$baseFilename.kts');
|
||||
|
||||
if (groovyFile.existsSync()) {
|
||||
// We mimic Gradle's behavior of preferring Groovy over Kotlin when both files exist.
|
||||
return buildGroovy;
|
||||
return groovyFile;
|
||||
}
|
||||
|
||||
if (buildKotlin.existsSync()) {
|
||||
return buildKotlin;
|
||||
if (kotlinFile.existsSync()) {
|
||||
return kotlinFile;
|
||||
}
|
||||
|
||||
// TODO(bartekpacia): An exception should be thrown when neither
|
||||
// build.gradle nor build.gradle.kts exist, instead of falling back to the
|
||||
// the Groovy or Kotlin file exists, instead of falling back to the
|
||||
// Groovy file. See #141180.
|
||||
return buildGroovy;
|
||||
return groovyFile;
|
||||
}
|
||||
|
||||
/// Gets the module-level build.gradle file.
|
||||
@@ -593,22 +604,7 @@ class AndroidProject extends FlutterProjectPlatform {
|
||||
/// or Kotlin (build.gradle.kts).
|
||||
File get appGradleFile {
|
||||
final Directory appDir = hostAppGradleRoot.childDirectory('app');
|
||||
final File buildGroovy = appDir.childFile('build.gradle');
|
||||
final File buildKotlin = appDir.childFile('build.gradle.kts');
|
||||
|
||||
if (buildGroovy.existsSync() && buildKotlin.existsSync()) {
|
||||
// We mimic Gradle's behavior of preferring Groovy over Kotlin when both files exist.
|
||||
return buildGroovy;
|
||||
}
|
||||
|
||||
if (buildKotlin.existsSync()) {
|
||||
return buildKotlin;
|
||||
}
|
||||
|
||||
// TODO(bartekpacia): An exception should be thrown when neither
|
||||
// build.gradle nor build.gradle.kts exist, instead of falling back to the
|
||||
// Groovy file. See #141180.
|
||||
return buildGroovy;
|
||||
return getGroovyOrKotlin(appDir, 'build.gradle');
|
||||
}
|
||||
|
||||
File get appManifestFile {
|
||||
|
||||
@@ -19,6 +19,7 @@ if (flutterVersionName == null) {
|
||||
apply plugin: "com.android.dynamic-feature"
|
||||
|
||||
android {
|
||||
namespace = "{{androidIdentifier}}.{{componentName}}"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
|
||||
compileOptions {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
package="{{androidIdentifier}}.{{componentName}}">
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution">
|
||||
|
||||
<dist:module
|
||||
dist:instant="false"
|
||||
|
||||
@@ -14,6 +14,8 @@ import '../src/context.dart';
|
||||
|
||||
|
||||
// This test requires Java 11 due to the intentionally low version of Gradle.
|
||||
// It also overrides the template compile sdk version to 34, because using 35
|
||||
// requires AGP 8.0+.
|
||||
void main() {
|
||||
late Directory tempDir;
|
||||
|
||||
@@ -31,6 +33,7 @@ void main() {
|
||||
final VersionTuple versionTuple = VersionTuple(agpVersion: '7.0.0', gradleVersion: '7.5', kotlinVersion: '1.7.10');
|
||||
final ProcessResult result = await buildFlutterApkWithSpecifiedDependencyVersions(
|
||||
versions: versionTuple,
|
||||
compileSdkOverride: '34',
|
||||
tempDir: tempDir
|
||||
);
|
||||
expect(result, const ProcessResultMatcher());
|
||||
@@ -44,6 +47,7 @@ void main() {
|
||||
final VersionTuple versionTuple = VersionTuple(agpVersion: '7.0.0', gradleVersion: '7.0.2', kotlinVersion: '1.7.10');
|
||||
final ProcessResult result = await buildFlutterApkWithSpecifiedDependencyVersions(
|
||||
versions: versionTuple,
|
||||
compileSdkOverride: '34',
|
||||
tempDir: tempDir
|
||||
);
|
||||
expect(result, const ProcessResultMatcher());
|
||||
@@ -56,6 +60,7 @@ void main() {
|
||||
final VersionTuple versionTuple = VersionTuple(agpVersion: '7.4.0', gradleVersion: '7.5', kotlinVersion: '1.7.0');
|
||||
final ProcessResult result = await buildFlutterApkWithSpecifiedDependencyVersions(
|
||||
versions: versionTuple,
|
||||
compileSdkOverride: '34',
|
||||
tempDir: tempDir
|
||||
);
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ void main() {
|
||||
incompatibleJavaAndGradleVersionsHandler,
|
||||
remoteTerminatedHandshakeHandler,
|
||||
couldNotOpenCacheDirectoryHandler,
|
||||
incompatibleCompileSdk35AndAgpVersionHandler,
|
||||
])
|
||||
);
|
||||
});
|
||||
@@ -1291,6 +1292,51 @@ A problem occurred evaluating script.
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
});
|
||||
|
||||
testUsingContext('compileSdk 35 and AGP < 8.1', () async {
|
||||
const String errorExample = r'''
|
||||
Execution failed for task ':app:bundleReleaseResources'.
|
||||
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2ProcessResourcesRunnable
|
||||
> Android resource linking failed
|
||||
aapt2 E 08-19 15:06:26 76078 5921862 LoadedArsc.cpp:94] RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data.
|
||||
aapt2 E 08-19 15:06:26 76078 5921862 ApkAssets.cpp:152] Failed to load resources table in APK '/Users/mackall/Library/Android/sdk/platforms/android-35/android.jar'.
|
||||
error: failed to load include path /Users/mackall/Library/Android/sdk/platforms/android-35/android.jar.
|
||||
''';
|
||||
|
||||
await incompatibleCompileSdk35AndAgpVersionHandler.handler(
|
||||
line: errorExample,
|
||||
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
|
||||
usesAndroidX: true,
|
||||
);
|
||||
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
contains(
|
||||
'\n'
|
||||
'┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────────┐\n'
|
||||
'│ [!] Using compileSdk 35 requires Android Gradle Plugin (AGP) 8.1.0 or higher. │\n'
|
||||
'│ Please upgrade to a newer AGP version. The version of AGP that your project uses is likely │\n'
|
||||
'│ defined in: │\n'
|
||||
'│ /android/settings.gradle, │\n'
|
||||
"│ in the 'plugins' closure. │\n"
|
||||
'│ Alternatively, if your project was created with an older version of the templates, it is likely │\n'
|
||||
'│ │\n'
|
||||
'│ in the buildscript.dependencies closure of the top-level build.gradle: │\n'
|
||||
'│ /android/build.gradle. │\n'
|
||||
'│ │\n'
|
||||
'│ Finally, if you have a strong reason to avoid upgrading AGP, you can temporarily lower the │\n'
|
||||
'│ compileSdk version in the following file: │\n'
|
||||
'│ /android/app/build.gradle │\n'
|
||||
'└──────────────────────────────────────────────────────────────────────────────────────────────────┘\n'
|
||||
''
|
||||
)
|
||||
);
|
||||
}, overrides: <Type, Generator>{
|
||||
GradleUtils: () => FakeGradleUtils(),
|
||||
Platform: () => fakePlatform('android'),
|
||||
FileSystem: () => fileSystem,
|
||||
ProcessManager: () => processManager,
|
||||
});
|
||||
}
|
||||
|
||||
bool formatTestErrorMessage(String errorMessage, GradleHandledError error) {
|
||||
|
||||
@@ -63,14 +63,14 @@ apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gra
|
||||
);
|
||||
buildGradle.writeAsStringSync(r'''
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.7.10'
|
||||
ext.kotlin_version = '1.8.22'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.3.0'
|
||||
classpath 'com.android.tools.build:gradle:8.1.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,9 @@ class DeferredComponentModule {
|
||||
apply plugin: "com.android.dynamic-feature"
|
||||
|
||||
android {
|
||||
compileSdk 34
|
||||
namespace = "com.example.''' + name + r'''
|
||||
"
|
||||
compileSdk 35
|
||||
|
||||
sourceSets {
|
||||
applicationVariants.all { variant ->
|
||||
@@ -88,7 +90,7 @@ class DeferredComponentModule {
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 33
|
||||
targetSdkVersion 35
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
}
|
||||
@@ -105,8 +107,7 @@ class DeferredComponentModule {
|
||||
|
||||
writeFile(fileSystem.path.join(dir.path, 'android', name, 'src', 'main', 'AndroidManifest.xml'), '''
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution"
|
||||
package="com.example.$name">
|
||||
xmlns:dist="http://schemas.android.com/apk/distribution">
|
||||
|
||||
<dist:module
|
||||
dist:instant="false"
|
||||
|
||||
@@ -107,14 +107,14 @@ class BasicDeferredComponentsConfig extends DeferredComponentsConfig {
|
||||
@override
|
||||
String get androidBuild => r'''
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.7.10'
|
||||
ext.kotlin_version = '1.8.22'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.3.0'
|
||||
classpath 'com.android.tools.build:gradle:8.1.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
@@ -175,9 +175,19 @@ class BasicDeferredComponentsConfig extends DeferredComponentsConfig {
|
||||
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
||||
|
||||
android {
|
||||
namespace = "com.example.splitaot"
|
||||
compileSdk flutter.compileSdkVersion
|
||||
ndkVersion flutter.ndkVersion
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
@@ -482,8 +492,7 @@ class BasicDeferredComponentsConfig extends DeferredComponentsConfig {
|
||||
|
||||
@override
|
||||
String get appManifest => r'''
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.splitaot">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
|
||||
calls FlutterMain.startInitialization(this); in its onCreate method.
|
||||
In most cases you can leave this as-is, but you if you want to provide
|
||||
|
||||
@@ -17,13 +17,13 @@ class PluginDeferredComponentsConfig extends BasicDeferredComponentsConfig {
|
||||
@override
|
||||
String get androidBuild => r'''
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.7.10'
|
||||
ext.kotlin_version = '1.8.22'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.3.0'
|
||||
classpath 'com.android.tools.build:gradle:8.1.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
configurations.classpath {
|
||||
@@ -72,8 +72,7 @@ apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gra
|
||||
|
||||
@override
|
||||
String get appManifest => r'''
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.yourcompany.flavors">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<application
|
||||
android:name="${applicationName}"
|
||||
|
||||
@@ -117,6 +117,7 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-GRADLE_REPLACE
|
||||
''';
|
||||
|
||||
const String gradleReplacementString = 'GRADLE_REPLACE_ME';
|
||||
const String flutterCompileSdkString = 'flutter.compileSdkVersion';
|
||||
|
||||
class VersionTuple {
|
||||
|
||||
@@ -141,6 +142,7 @@ class VersionTuple {
|
||||
/// ProcessResult.
|
||||
Future<ProcessResult> buildFlutterApkWithSpecifiedDependencyVersions({
|
||||
required VersionTuple versions,
|
||||
String? compileSdkOverride,
|
||||
required Directory tempDir,}) async {
|
||||
// Create a new flutter project.
|
||||
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
|
||||
@@ -154,6 +156,14 @@ Future<ProcessResult> buildFlutterApkWithSpecifiedDependencyVersions({
|
||||
|
||||
final Directory app = Directory(fileSystem.path.join(tempDir.path, 'dependency_checker_app'));
|
||||
|
||||
if (compileSdkOverride != null) {
|
||||
final File appGradleBuild = File(fileSystem.path.join(
|
||||
app.path, 'android', 'app', 'build.gradle'));
|
||||
final String appBuildContent = appGradleBuild.readAsStringSync()
|
||||
.replaceFirst(flutterCompileSdkString, compileSdkOverride);
|
||||
appGradleBuild.writeAsStringSync(appBuildContent);
|
||||
}
|
||||
|
||||
// Modify gradle version to passed in version.
|
||||
final File gradleWrapperProperties = File(fileSystem.path.join(
|
||||
app.path, 'android', 'gradle', 'wrapper', 'gradle-wrapper.properties'));
|
||||
|
||||
Reference in New Issue
Block a user