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:
Gray Mackall
2024-08-20 14:33:12 -07:00
committed by GitHub
parent 5a87890277
commit ef9cd32f5a
51 changed files with 403 additions and 280 deletions

View File

@@ -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
);

View File

@@ -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) {

View File

@@ -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"
}
}

View File

@@ -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"

View File

@@ -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

View File

@@ -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}"

View File

@@ -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'));