Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you updating to these versions of Gradle and AGP (8.4, 8.1.0) in the tests because of https://docs.gradle.org/current/userguide/compatibility.html#android?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm updating them because of b/342522139 - basically compileSdk 35 seems to require AGP 8.1.0+. The specific choice of Gradle 8.4 was arbitrary though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also realized that because this changes the FlutterExtension, it would also impact existing apps, so I added a gradle error handler for this case and also added a test for it.

Example of the error message:

Execution failed for task ':app:processReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
   > Android resource linking failed
     aapt2 E 08-19 15:13:02 78026 5943581 LoadedArsc.cpp:94] RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data.
     aapt2 E 08-19 15:13:02 78026 5943581 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.

And example of the handled version:

┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Using compileSdk 35 requires Android Gradle Plugin (AGP) 8.1.0 or higher.                                                              │
│ Please upgrade to a newer AGP version. The version of AGP that your project uses is likely defined in:                                     │
│ /Users/mackall/development/BugTesting/testFlutterPluginGradlePlugin/foobarfoo/android/settings.gradle,                                     │
│ in the 'plugins' closure.                                                                                                                  │
│ Alternatively, if you have a strong reason to avoid upgrading AGP, you can temporarily lower the compileSdk version in the following file: │
│ /Users/mackall/development/BugTesting/testFlutterPluginGradlePlugin/foobarfoo/android/app/build.gradle                                     │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not the right file for most users. This is only the right file since we started using the plugin way of importing FGP.
/Users/mackall/development/BugTesting/testFlutterPluginGradlePlugin/foobarfoo/android/settings.gradle
prior to that it would have been /Users/mackall/development/BugTesting/testFlutterPluginGradlePlugin/foobarfoo/android/build.gradle
See this example from flutter vlc https://github.com/solid-software/flutter_vlc_player/blob/master/flutter_vlc_player/android/build.gradle

Copy link
Member Author

@gmackall gmackall Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I agree it is the less likely one (hopefully not by much now?), but it is definitely the one we support the most. I can keep telling people both locations for now I suppose, though I feel that three file paths in the message makes it a bit lengthy/gross.

Do you have any sense of when we would stop providing both links in situations like these? A year from now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of how it looks now:

┌─ Flutter Fix ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Using compileSdk 35 requires Android Gradle Plugin (AGP) 8.1.0 or higher.                                                         │
│  Please upgrade to a newer AGP version. The version of AGP that your project uses is likely defined in:                               │
│ /Users/mackall/development/BugTesting/testFlutterPluginGradlePlugin/foobarfoo/android/settings.gradle,                                │
│ in the 'plugins' closure.                                                                                                             │
│  Alternatively, if your project was created with an older version of the templates, it is likely                                      │
│ in the buildscript.dependencies closure of the top-level build.gradle:                                                                │
│ /Users/mackall/development/BugTesting/testFlutterPluginGradlePlugin/foobarfoo/android/build.gradle.                                   │
│                                                                                                                                       │
│  Finally, if you have a strong reason to avoid upgrading AGP, you can temporarily lower the compileSdk version in the following file: │
│ /Users/mackall/development/BugTesting/testFlutterPluginGradlePlugin/foobarfoo/android/app/build.gradle                                │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

I added the new link, and also added spaces to the start of each separate item which hopefully makes it more readable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I agree it is the less likely one (hopefully not by much now?), but it is definitely the one we support the most. I can keep telling people both locations for now I suppose, though I feel that three file paths in the message makes it a bit lengthy/gross.

Do you have any sense of when we would stop providing both links in situations like these? A year from now?

We would stop telling people about both when we have removed the ability to import FGP as a script. Maybe a year from now. Most people have not migrated, my gut say 90+ percent of people. I could do a pub example check if we wanted.

4 changes: 2 additions & 2 deletions dev/benchmarks/microbenchmarks/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
id "com.android.application" version "8.1.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

include ":app"
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ List<VersionTuple> versionTuples = <VersionTuple>[

// This test requires a Java version less than 17 due to the intentionally low
// version of Gradle. We choose 11 because this was the primary version used in
// CI before 17, and hence it is also hosted on CIPD.
// CI before 17, and hence it is also hosted on CIPD. It also overrides to
// compileSdkVersion 34 because compileSdk 35 requires AGP 8.0+.
// https://docs.gradle.org/current/userguide/compatibility.html
Future<void> main() async {
/// The [FileSystem] for the integration test environment.
const LocalFileSystem fileSystem = LocalFileSystem();

final Directory tempDir = fileSystem.systemTempDirectory.createTempSync('flutter_android_dependency_version_tests');
final Directory tempDir = fileSystem
.systemTempDirectory
.createTempSync('flutter_android_dependency_version_tests');
await task(() {
return buildFlutterApkWithSpecifiedDependencyVersions(versionTuples: versionTuples, tempDir: tempDir, localFileSystem: fileSystem);
return buildFlutterApkWithSpecifiedDependencyVersions(
versionTuples: versionTuples,
compileSdkOverride: '34',
tempDir: tempDir,
localFileSystem: fileSystem
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-GRADLE_REPLACE
''';

const String gradleReplacementString = 'GRADLE_REPLACE_ME';
const String flutterCompileSdkString = 'flutter.compileSdkVersion';

/// A simple class containing a Kotlin, Gradle, and AGP version.
class VersionTuple {
Expand Down Expand Up @@ -87,6 +88,7 @@ class VersionTuple {
/// fails, returns a successful result otherwise. Cleans up in either case.
Future<TaskResult> buildFlutterApkWithSpecifiedDependencyVersions({
required List<VersionTuple> versionTuples,
String? compileSdkOverride,
required Directory tempDir,
required LocalFileSystem localFileSystem,}) async {
for (final VersionTuple versions in versionTuples) {
Expand All @@ -105,6 +107,14 @@ Future<TaskResult> buildFlutterApkWithSpecifiedDependencyVersions({

final String appPath = '${innerTempDir.absolute.path}/dependency_checker_app';

if (compileSdkOverride != null) {
final File appGradleBuild = localFileSystem.file(localFileSystem.path.join(
appPath, '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 = localFileSystem.file(localFileSystem.path.join(
appPath, 'android', 'gradle', 'wrapper', 'gradle-wrapper.properties'));
Expand Down
16 changes: 14 additions & 2 deletions dev/integration_tests/android_driver_test/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file is auto generated.
// To update all the build.gradle files in the Flutter repo,
// See dev/tools/bin/generate_gradle_lockfiles.dart.

allprojects {
repositories {
google()
mavenCentral()
}
}

rootProject.buildDir = "../build"
rootProject.buildDir = '../build'

subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(":app")
project.evaluationDependsOn(':app')
dependencyLocking {
ignoredDependencies.add('io.flutter:*')
lockFile = file("${rootProject.projectDir}/project-${project.name}.lockfile")
if (!project.hasProperty('local-engine-repo')) {
lockAllConfigurations()
}
}
}

tasks.register("clean", Delete) {
Expand Down
18 changes: 15 additions & 3 deletions dev/integration_tests/android_driver_test/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This file is auto generated.
// To update all the settings.gradle files in the Flutter repo,
// See dev/tools/bin/generate_gradle_lockfiles.dart.

pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()
}
settings.ext.flutterSdkPath = flutterSdkPath()

includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")

repositories {
google()
Expand All @@ -20,10 +25,17 @@ pluginManagement {
}
}

buildscript {
dependencyLocking {
lockFile = file("${rootProject.projectDir}/buildscript-gradle.lockfile")
lockAllConfigurations()
}
}

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
}

include ":app"
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
// See dev/tools/bin/generate_gradle_lockfiles.dart.

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ apply plugin: "com.android.dynamic-feature"

android {
namespace "io.flutter.integration.deferred_components_test.component1"
compileSdk 34
compileSdk 35

sourceSets {
applicationVariants.all { variant ->
Expand All @@ -35,7 +35,7 @@ android {

defaultConfig {
minSdkVersion 21
targetSdkVersion 33
targetSdkVersion 35
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ buildscript {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
id "com.android.application" version "8.1.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

include ":app"
Loading