Update AGP version validation code to support KGP and kotlin build files. (#142357)

Addresses: https://github.com/flutter/flutter/issues/141410
This commit is contained in:
Ann Marie Mossman
2024-02-05 13:47:39 -08:00
committed by GitHub
parent f3ee371285
commit e5a922fed4
2 changed files with 181 additions and 74 deletions

View File

@@ -387,7 +387,9 @@ OS: Mac OS X 13.2.1 aarch64
);
});
testWithoutContext('returns the AGP version when set in Groovy', () async {
testWithoutContext(
'returns the AGP version when set in Groovy build file as classpath with single quotes and commented line',
() async {
const String expectedVersion = '7.3.0';
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
@@ -399,6 +401,8 @@ buildscript {
}
dependencies {
// Decoy value to ensure we ignore commented out lines.
// classpath 'com.android.application' version '6.1.0' apply false
classpath 'com.android.tools.build:gradle:$expectedVersion'
}
}
@@ -417,7 +421,9 @@ allprojects {
);
});
testWithoutContext('returns the AGP version when set in Kotlin', () async {
testWithoutContext(
'returns the AGP version when set in Kotlin build file as classpath',
() async {
const String expectedVersion = '7.3.0';
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
@@ -447,7 +453,77 @@ allprojects {
);
});
testWithoutContext('prefers the AGP version when set in Groovy, ignores Kotlin', () async {
testWithoutContext(
'returns the AGP version when set in Groovy build file as compileOnly with double quotes',
() async {
const String expectedVersion = '7.1.0';
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
androidDirectory.childFile('build.gradle.kts').writeAsStringSync('''
dependencies {
compileOnly "com.android.tools.build:gradle:$expectedVersion"
}
''');
expect(
getAgpVersion(androidDirectory, BufferLogger.test()),
expectedVersion,
);
});
testWithoutContext(
'returns the AGP version when set in Kotlin build file as compileOnly',
() async {
const String expectedVersion = '7.1.0';
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
androidDirectory.childFile('build.gradle.kts').writeAsStringSync('''
dependencies {
compileOnly("com.android.tools.build:gradle:$expectedVersion")
}
''');
expect(
getAgpVersion(androidDirectory, BufferLogger.test()),
expectedVersion,
);
});
testWithoutContext(
'returns the AGP version when set in Groovy build file as plugin',
() async {
const String expectedVersion = '6.8';
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
androidDirectory.childFile('build.gradle').writeAsStringSync('''
plugins {
id 'com.android.application' version '$expectedVersion' apply false
}
''');
expect(
getAgpVersion(androidDirectory, BufferLogger.test()),
expectedVersion,
);
});
testWithoutContext(
'returns the AGP version when set in Kotlin build file as plugin',
() async {
const String expectedVersion = '7.2.0';
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
androidDirectory.childFile('build.gradle.kts').writeAsStringSync('''
plugins {
id("com.android.application") version "$expectedVersion" apply false
}
''');
expect(
getAgpVersion(androidDirectory, BufferLogger.test()),
expectedVersion,
);
});
testWithoutContext(
'prefers the AGP version when set in Groovy, ignores Kotlin', () async {
const String versionInGroovy = '7.3.0';
const String versionInKotlin = '7.4.2';
final Directory androidDirectory = fileSystem.directory('/android')
@@ -554,48 +630,73 @@ allprojects {
);
});
testWithoutContext('returns the AGP version when in settings', () async {
testWithoutContext('returns the AGP version when in Groovy settings as plugin',
() async {
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
// File must exist and can not have agp defined.
androidDirectory.childFile('build.gradle').writeAsStringSync(r'');
androidDirectory.childFile('settings.gradle').writeAsStringSync(r'''
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("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
plugins {
id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
id 'dev.flutter.flutter-gradle-plugin' version '1.0.0' apply false
id 'dev.flutter.flutter-plugin-loader' version '1.0.0'
// Decoy value to ensure we ignore commented out lines.
// id 'com.android.application' version '6.1.0' apply false
id 'com.android.application' version '8.1.0' apply false
}
}
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
// Decoy value to ensure we ignore commented out lines.
// id "com.android.application" version "6.1.0" apply false
id "com.android.application" version "7.3.0" apply false
}
include ":app"
''');
expect(
getAgpVersion(androidDirectory, BufferLogger.test()),
'7.3.0',
'8.1.0',
);
});
testWithoutContext(
'returns the AGP version when in Kotlin settings as plugin', () async {
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
// File must exist and cannot have agp defined.
androidDirectory.childFile('build.gradle.kts').writeAsStringSync(r'');
androidDirectory.childFile('settings.gradle.kts').writeAsStringSync(r'''
pluginManagement {
plugins {
id("dev.flutter.flutter-plugin-loader") version "1.0.0"
// Decoy value to ensure we ignore commented out lines.
// id("com.android.application") version "6.1.0" apply false
id("com.android.application") version "7.5.0" apply false
}
}
''');
expect(
getAgpVersion(androidDirectory, BufferLogger.test()),
'7.5.0',
);
});
testWithoutContext(
'returns null when agp version is misconfigured',
() async {
final Directory androidDirectory = fileSystem.directory('/android')
..createSync();
androidDirectory.childFile('build.gradle.kts').writeAsStringSync('''
plugins {
`java-gradle-plugin`
`groovy`
}
dependencies {
// intentional typo
compileOnl("com.android.tools.build:gradle:7.3.0")
}
''');
expect(
getAgpVersion(androidDirectory, BufferLogger.test()),
null,
);
});