Unverified Commit b528310f authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Specify Kotlin version in modules and refactor (#101315)

parent bb300b46
...@@ -67,7 +67,8 @@ Future<void> main() async { ...@@ -67,7 +67,8 @@ Future<void> main() async {
' plugin_with_android:$platformLineSep' ' plugin_with_android:$platformLineSep'
' path: ../plugin_with_android$platformLineSep' ' path: ../plugin_with_android$platformLineSep'
' plugin_without_android:$platformLineSep' ' plugin_without_android:$platformLineSep'
' path: ../plugin_without_android$platformLineSep', ' path: ../plugin_without_android$platformLineSep'
' webcrypto: 0.5.2$platformLineSep', // Plugin that uses NDK.
); );
modulePubspec.writeAsStringSync(content, flush: true); modulePubspec.writeAsStringSync(content, flush: true);
......
...@@ -71,13 +71,13 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[ ...@@ -71,13 +71,13 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[
permissionDeniedErrorHandler, permissionDeniedErrorHandler,
flavorUndefinedHandler, flavorUndefinedHandler,
r8FailureHandler, r8FailureHandler,
minSdkVersion, minSdkVersionHandler,
transformInputIssue, transformInputIssueHandler,
lockFileDepMissing, lockFileDepMissingHandler,
multidexErrorHandler, multidexErrorHandler,
incompatibleKotlinVersionHandler, incompatibleKotlinVersionHandler,
minCompileSdkVersionHandler, minCompileSdkVersionHandler,
jvm11Required, jvm11RequiredHandler,
]; ];
const String _boxTitle = 'Flutter Fix'; const String _boxTitle = 'Flutter Fix';
...@@ -381,7 +381,7 @@ final RegExp _minSdkVersionPattern = RegExp(r'uses-sdk:minSdkVersion ([0-9]+) ca ...@@ -381,7 +381,7 @@ final RegExp _minSdkVersionPattern = RegExp(r'uses-sdk:minSdkVersion ([0-9]+) ca
/// Handler when a plugin requires a higher Android API level. /// Handler when a plugin requires a higher Android API level.
@visibleForTesting @visibleForTesting
final GradleHandledError minSdkVersion = GradleHandledError( final GradleHandledError minSdkVersionHandler = GradleHandledError(
test: (String line) { test: (String line) {
return _minSdkVersionPattern.hasMatch(line); return _minSdkVersionPattern.hasMatch(line);
}, },
...@@ -423,7 +423,7 @@ final GradleHandledError minSdkVersion = GradleHandledError( ...@@ -423,7 +423,7 @@ final GradleHandledError minSdkVersion = GradleHandledError(
/// Handler when https://issuetracker.google.com/issues/141126614 or /// Handler when https://issuetracker.google.com/issues/141126614 or
/// https://github.com/flutter/flutter/issues/58247 is triggered. /// https://github.com/flutter/flutter/issues/58247 is triggered.
@visibleForTesting @visibleForTesting
final GradleHandledError transformInputIssue = GradleHandledError( final GradleHandledError transformInputIssueHandler = GradleHandledError(
test: (String line) { test: (String line) {
return line.contains('https://issuetracker.google.com/issues/158753935'); return line.contains('https://issuetracker.google.com/issues/158753935');
}, },
...@@ -457,7 +457,7 @@ final GradleHandledError transformInputIssue = GradleHandledError( ...@@ -457,7 +457,7 @@ final GradleHandledError transformInputIssue = GradleHandledError(
/// Handler when a dependency is missing in the lockfile. /// Handler when a dependency is missing in the lockfile.
@visibleForTesting @visibleForTesting
final GradleHandledError lockFileDepMissing = GradleHandledError( final GradleHandledError lockFileDepMissingHandler = GradleHandledError(
test: (String line) { test: (String line) {
return line.contains('which is not part of the dependency lock state'); return line.contains('which is not part of the dependency lock state');
}, },
...@@ -541,7 +541,7 @@ final GradleHandledError minCompileSdkVersionHandler = GradleHandledError( ...@@ -541,7 +541,7 @@ final GradleHandledError minCompileSdkVersionHandler = GradleHandledError(
); );
@visibleForTesting @visibleForTesting
final GradleHandledError jvm11Required = GradleHandledError( final GradleHandledError jvm11RequiredHandler = GradleHandledError(
test: (String line) { test: (String line) {
return line.contains('Android Gradle plugin requires Java 11 to run'); return line.contains('Android Gradle plugin requires Java 11 to run');
}, },
......
...@@ -30,9 +30,20 @@ import 'android_sdk.dart'; ...@@ -30,9 +30,20 @@ import 'android_sdk.dart';
const String templateDefaultGradleVersion = '7.4'; const String templateDefaultGradleVersion = '7.4';
const String templateAndroidGradlePluginVersion = '7.1.2'; const String templateAndroidGradlePluginVersion = '7.1.2';
// TODO(egarciad): Gradle 7 breaks AARs builds: https://github.com/flutter/flutter/issues/101083 // TODO(egarciad): Gradle 7 breaks AARs builds: https://github.com/flutter/flutter/issues/101083
const String templateAndroidGradlePluginVersionForModule = '4.1.0'; const String templateDefaultGradleVersionForModule = '4.1.0';
const String templateKotlinGradlePluginVersion = '1.6.10'; const String templateKotlinGradlePluginVersion = '1.6.10';
// These versions should match the values in flutter.gradle (FlutterExtension).
// The Flutter Gradle plugin is only applied to app projects, and modules that are built from source
// using (include_flutter.groovy).
// The remaining projects are: plugins, and modules compiled as AARs. In modules, the ephemeral directory
// `.android` is always regenerated after flutter pub get, so new versions are picked up after a
// Flutter upgrade.
const String compileSdkVersion = '31';
const String minSdkVersion = '16';
const String targetSdkVersion = '31';
const String ndkVersion = '21.1.6352462';
final RegExp _androidPluginRegExp = RegExp(r'com\.android\.tools\.build:gradle:(\d+\.\d+\.\d+)'); final RegExp _androidPluginRegExp = RegExp(r'com\.android\.tools\.build:gradle:(\d+\.\d+\.\d+)');
/// Provides utilities to run a Gradle task, such as finding the Gradle executable /// Provides utilities to run a Gradle task, such as finding the Gradle executable
......
...@@ -425,6 +425,11 @@ abstract class CreateBase extends FlutterCommand { ...@@ -425,6 +425,11 @@ abstract class CreateBase extends FlutterCommand {
'agpVersion': agpVersion, 'agpVersion': agpVersion,
'kotlinVersion': kotlinVersion, 'kotlinVersion': kotlinVersion,
'gradleVersion': gradleVersion, 'gradleVersion': gradleVersion,
'gradleVersionForModule': gradle.templateDefaultGradleVersionForModule,
'compileSdkVersion': gradle.compileSdkVersion,
'minSdkVersion': gradle.minSdkVersion,
'ndkVersion': gradle.ndkVersion,
'targetSdkVersion': gradle.targetSdkVersion,
}; };
} }
......
...@@ -587,9 +587,13 @@ class AndroidProject extends FlutterProjectPlatform { ...@@ -587,9 +587,13 @@ class AndroidProject extends FlutterProjectPlatform {
'androidIdentifier': androidIdentifier, 'androidIdentifier': androidIdentifier,
'androidX': usesAndroidX, 'androidX': usesAndroidX,
'agpVersion': gradle.templateAndroidGradlePluginVersion, 'agpVersion': gradle.templateAndroidGradlePluginVersion,
'agpVersionForModule': gradle.templateAndroidGradlePluginVersionForModule,
'kotlinVersion': gradle.templateKotlinGradlePluginVersion, 'kotlinVersion': gradle.templateKotlinGradlePluginVersion,
'gradleVersion': gradle.templateDefaultGradleVersion, 'gradleVersion': gradle.templateDefaultGradleVersion,
'gradleVersionForModule': gradle.templateDefaultGradleVersionForModule,
'compileSdkVersion': gradle.compileSdkVersion,
'minSdkVersion': gradle.minSdkVersion,
'ndkVersion': gradle.ndkVersion,
'targetSdkVersion': gradle.targetSdkVersion,
}, },
printStatusWhenWriting: false, printStatusWhenWriting: false,
); );
......
// Generated file. Do not edit. // Generated file. Do not edit.
buildscript { buildscript {
ext.kotlin_version = '{{kotlinVersion}}'
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:{{agpVersionForModule}}' classpath 'com.android.tools.build:gradle:{{gradleVersionForModule}}'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
} }
...@@ -18,6 +20,16 @@ allprojects { ...@@ -18,6 +20,16 @@ allprojects {
} }
} }
task clean(type: Delete) { apply plugin: 'com.android.library'
delete rootProject.buildDir apply plugin: 'kotlin-android'
android {
compileSdkVersion {{compileSdkVersion}}
defaultConfig {
minSdkVersion {{minSdkVersion}}
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
} }
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="{{androidIdentifier}}">
</manifest>
...@@ -3,7 +3,7 @@ def flutterPluginVersion = 'managed' ...@@ -3,7 +3,7 @@ def flutterPluginVersion = 'managed'
apply plugin: 'com.android.application' apply plugin: 'com.android.application'
android { android {
compileSdkVersion 31 compileSdkVersion {{compileSdkVersion}}
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
...@@ -12,8 +12,8 @@ android { ...@@ -12,8 +12,8 @@ android {
defaultConfig { defaultConfig {
applicationId "{{androidIdentifier}}.host" applicationId "{{androidIdentifier}}.host"
minSdkVersion 16 minSdkVersion {{minSdkVersion}}
targetSdkVersion 31 targetSdkVersion {{targetSdkVersion}}
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }
......
...@@ -22,7 +22,7 @@ rootProject.allprojects { ...@@ -22,7 +22,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
android { android {
compileSdkVersion 31 compileSdkVersion {{compileSdkVersion}}
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
...@@ -30,6 +30,6 @@ android { ...@@ -30,6 +30,6 @@ android {
} }
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion {{minSdkVersion}}
} }
} }
...@@ -14,7 +14,7 @@ buildscript { ...@@ -14,7 +14,7 @@ buildscript {
} }
} }
rootProject.allprojects { allprojects {
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
...@@ -41,7 +41,7 @@ android { ...@@ -41,7 +41,7 @@ android {
} }
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion {{minSdkVersion}}
} }
} }
......
...@@ -27,11 +27,11 @@ apply plugin: 'com.android.library' ...@@ -27,11 +27,11 @@ apply plugin: 'com.android.library'
android { android {
// Bumping the plugin compileSdkVersion requires all clients of this plugin // Bumping the plugin compileSdkVersion requires all clients of this plugin
// to bump the version in their app. // to bump the version in their app.
compileSdkVersion 31 compileSdkVersion {{compileSdkVersion}}
// Bumping the plugin ndkVersion requires all clients of this plugin to bump // Bumping the plugin ndkVersion requires all clients of this plugin to bump
// the version in their app and to download a newer version of the NDK. // the version in their app and to download a newer version of the NDK.
ndkVersion "21.1.6352462" ndkVersion "{{ndkVersion}}"
// Invoke the shared CMake build with the Android Gradle Plugin. // Invoke the shared CMake build with the Android Gradle Plugin.
externalNativeBuild { externalNativeBuild {
...@@ -54,6 +54,6 @@ android { ...@@ -54,6 +54,6 @@ android {
} }
defaultConfig { defaultConfig {
minSdkVersion 16 minSdkVersion {{minSdkVersion}}
} }
} }
...@@ -210,6 +210,8 @@ ...@@ -210,6 +210,8 @@
"templates/module/android/deferred_component/src/main/AndroidManifest.xml.tmpl", "templates/module/android/deferred_component/src/main/AndroidManifest.xml.tmpl",
"templates/module/android/gradle/build.gradle.tmpl", "templates/module/android/gradle/build.gradle.tmpl",
"templates/module/android/gradle/gradle.properties.tmpl", "templates/module/android/gradle/gradle.properties.tmpl",
"templates/module/android/gradle/settings.gradle.tmpl",
"templates/module/android/gradle/src/main/AndroidManifest.xml.tmpl",
"templates/module/android/host_app_common/app.tmpl/build.gradle.tmpl", "templates/module/android/host_app_common/app.tmpl/build.gradle.tmpl",
"templates/module/android/host_app_common/app.tmpl/src/main/AndroidManifest.xml.tmpl", "templates/module/android/host_app_common/app.tmpl/src/main/AndroidManifest.xml.tmpl",
"templates/module/android/host_app_common/app.tmpl/src/main/java/androidIdentifier/host/MainActivity.java.tmpl", "templates/module/android/host_app_common/app.tmpl/src/main/java/androidIdentifier/host/MainActivity.java.tmpl",
......
...@@ -29,13 +29,13 @@ void main() { ...@@ -29,13 +29,13 @@ void main() {
permissionDeniedErrorHandler, permissionDeniedErrorHandler,
flavorUndefinedHandler, flavorUndefinedHandler,
r8FailureHandler, r8FailureHandler,
minSdkVersion, minSdkVersionHandler,
transformInputIssue, transformInputIssueHandler,
lockFileDepMissing, lockFileDepMissingHandler,
multidexErrorHandler, multidexErrorHandler,
incompatibleKotlinVersionHandler, incompatibleKotlinVersionHandler,
minCompileSdkVersionHandler, minCompileSdkVersionHandler,
jvm11Required, jvm11RequiredHandler,
]) ])
); );
}); });
...@@ -754,13 +754,13 @@ assembleProfile ...@@ -754,13 +754,13 @@ assembleProfile
testWithoutContext('pattern', () { testWithoutContext('pattern', () {
expect( expect(
minSdkVersion.test(stdoutLine), minSdkVersionHandler.test(stdoutLine),
isTrue, isTrue,
); );
}); });
testUsingContext('suggestion', () async { testUsingContext('suggestion', () async {
await minSdkVersion.handler( await minSdkVersionHandler.handler(
line: stdoutLine, line: stdoutLine,
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory), project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
); );
...@@ -798,7 +798,7 @@ assembleProfile ...@@ -798,7 +798,7 @@ assembleProfile
group('transform input issue', () { group('transform input issue', () {
testWithoutContext('pattern', () { testWithoutContext('pattern', () {
expect( expect(
transformInputIssue.test( transformInputIssueHandler.test(
'https://issuetracker.google.com/issues/158753935' 'https://issuetracker.google.com/issues/158753935'
), ),
isTrue, isTrue,
...@@ -806,7 +806,7 @@ assembleProfile ...@@ -806,7 +806,7 @@ assembleProfile
}); });
testUsingContext('suggestion', () async { testUsingContext('suggestion', () async {
await transformInputIssue.handler( await transformInputIssueHandler.handler(
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory), project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
); );
...@@ -836,7 +836,7 @@ assembleProfile ...@@ -836,7 +836,7 @@ assembleProfile
group('Dependency mismatch', () { group('Dependency mismatch', () {
testWithoutContext('pattern', () { testWithoutContext('pattern', () {
expect( expect(
lockFileDepMissing.test(''' lockFileDepMissingHandler.test('''
* What went wrong: * What went wrong:
Execution failed for task ':app:generateDebugFeatureTransitiveDeps'. Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
> Could not resolve all artifacts for configuration ':app:debugRuntimeClasspath'. > Could not resolve all artifacts for configuration ':app:debugRuntimeClasspath'.
...@@ -848,7 +848,7 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'. ...@@ -848,7 +848,7 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
}); });
testUsingContext('suggestion', () async { testUsingContext('suggestion', () async {
await lockFileDepMissing.handler( await lockFileDepMissingHandler.handler(
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory), project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
); );
...@@ -960,7 +960,7 @@ Execution failed for task ':app:checkDebugAarMetadata'. ...@@ -960,7 +960,7 @@ Execution failed for task ':app:checkDebugAarMetadata'.
group('Java 11 requirement', () { group('Java 11 requirement', () {
testWithoutContext('pattern', () { testWithoutContext('pattern', () {
expect( expect(
jvm11Required.test(''' jvm11RequiredHandler.test('''
* What went wrong: * What went wrong:
A problem occurred evaluating project ':flutter'. A problem occurred evaluating project ':flutter'.
> Failed to apply plugin 'com.android.internal.library'. > Failed to apply plugin 'com.android.internal.library'.
...@@ -975,7 +975,7 @@ A problem occurred evaluating project ':flutter'. ...@@ -975,7 +975,7 @@ A problem occurred evaluating project ':flutter'.
}); });
testUsingContext('suggestion', () async { testUsingContext('suggestion', () async {
await jvm11Required.handler(); await jvm11RequiredHandler.handler();
expect( expect(
testLogger.statusText, testLogger.statusText,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment