Specify Kotlin version in modules and refactor (#101315)
This commit is contained in:
parent
bb300b467e
commit
b528310f58
@ -67,7 +67,8 @@ Future<void> main() async {
|
||||
' plugin_with_android:$platformLineSep'
|
||||
' path: ../plugin_with_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);
|
||||
|
||||
|
@ -71,13 +71,13 @@ final List<GradleHandledError> gradleErrors = <GradleHandledError>[
|
||||
permissionDeniedErrorHandler,
|
||||
flavorUndefinedHandler,
|
||||
r8FailureHandler,
|
||||
minSdkVersion,
|
||||
transformInputIssue,
|
||||
lockFileDepMissing,
|
||||
minSdkVersionHandler,
|
||||
transformInputIssueHandler,
|
||||
lockFileDepMissingHandler,
|
||||
multidexErrorHandler,
|
||||
incompatibleKotlinVersionHandler,
|
||||
minCompileSdkVersionHandler,
|
||||
jvm11Required,
|
||||
jvm11RequiredHandler,
|
||||
];
|
||||
|
||||
const String _boxTitle = 'Flutter Fix';
|
||||
@ -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.
|
||||
@visibleForTesting
|
||||
final GradleHandledError minSdkVersion = GradleHandledError(
|
||||
final GradleHandledError minSdkVersionHandler = GradleHandledError(
|
||||
test: (String line) {
|
||||
return _minSdkVersionPattern.hasMatch(line);
|
||||
},
|
||||
@ -423,7 +423,7 @@ final GradleHandledError minSdkVersion = GradleHandledError(
|
||||
/// Handler when https://issuetracker.google.com/issues/141126614 or
|
||||
/// https://github.com/flutter/flutter/issues/58247 is triggered.
|
||||
@visibleForTesting
|
||||
final GradleHandledError transformInputIssue = GradleHandledError(
|
||||
final GradleHandledError transformInputIssueHandler = GradleHandledError(
|
||||
test: (String line) {
|
||||
return line.contains('https://issuetracker.google.com/issues/158753935');
|
||||
},
|
||||
@ -457,7 +457,7 @@ final GradleHandledError transformInputIssue = GradleHandledError(
|
||||
|
||||
/// Handler when a dependency is missing in the lockfile.
|
||||
@visibleForTesting
|
||||
final GradleHandledError lockFileDepMissing = GradleHandledError(
|
||||
final GradleHandledError lockFileDepMissingHandler = GradleHandledError(
|
||||
test: (String line) {
|
||||
return line.contains('which is not part of the dependency lock state');
|
||||
},
|
||||
@ -541,7 +541,7 @@ final GradleHandledError minCompileSdkVersionHandler = GradleHandledError(
|
||||
);
|
||||
|
||||
@visibleForTesting
|
||||
final GradleHandledError jvm11Required = GradleHandledError(
|
||||
final GradleHandledError jvm11RequiredHandler = GradleHandledError(
|
||||
test: (String line) {
|
||||
return line.contains('Android Gradle plugin requires Java 11 to run');
|
||||
},
|
||||
|
@ -30,9 +30,20 @@ import 'android_sdk.dart';
|
||||
const String templateDefaultGradleVersion = '7.4';
|
||||
const String templateAndroidGradlePluginVersion = '7.1.2';
|
||||
// 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';
|
||||
|
||||
// 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+)');
|
||||
|
||||
/// Provides utilities to run a Gradle task, such as finding the Gradle executable
|
||||
|
@ -425,6 +425,11 @@ abstract class CreateBase extends FlutterCommand {
|
||||
'agpVersion': agpVersion,
|
||||
'kotlinVersion': kotlinVersion,
|
||||
'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 {
|
||||
'androidIdentifier': androidIdentifier,
|
||||
'androidX': usesAndroidX,
|
||||
'agpVersion': gradle.templateAndroidGradlePluginVersion,
|
||||
'agpVersionForModule': gradle.templateAndroidGradlePluginVersionForModule,
|
||||
'kotlinVersion': gradle.templateKotlinGradlePluginVersion,
|
||||
'gradleVersion': gradle.templateDefaultGradleVersion,
|
||||
'gradleVersionForModule': gradle.templateDefaultGradleVersionForModule,
|
||||
'compileSdkVersion': gradle.compileSdkVersion,
|
||||
'minSdkVersion': gradle.minSdkVersion,
|
||||
'ndkVersion': gradle.ndkVersion,
|
||||
'targetSdkVersion': gradle.targetSdkVersion,
|
||||
},
|
||||
printStatusWhenWriting: false,
|
||||
);
|
||||
|
@ -1,13 +1,15 @@
|
||||
// Generated file. Do not edit.
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '{{kotlinVersion}}'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion {{compileSdkVersion}}
|
||||
defaultConfig {
|
||||
minSdkVersion {{minSdkVersion}}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
rootProject.name = '{{projectName}}'
|
@ -0,0 +1,3 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="{{androidIdentifier}}">
|
||||
</manifest>
|
@ -3,7 +3,7 @@ def flutterPluginVersion = 'managed'
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
compileSdkVersion {{compileSdkVersion}}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
@ -12,8 +12,8 @@ android {
|
||||
|
||||
defaultConfig {
|
||||
applicationId "{{androidIdentifier}}.host"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 31
|
||||
minSdkVersion {{minSdkVersion}}
|
||||
targetSdkVersion {{targetSdkVersion}}
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ rootProject.allprojects {
|
||||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 31
|
||||
compileSdkVersion {{compileSdkVersion}}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
@ -30,6 +30,6 @@ android {
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
minSdkVersion {{minSdkVersion}}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.allprojects {
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
@ -41,7 +41,7 @@ android {
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
minSdkVersion {{minSdkVersion}}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,11 +27,11 @@ apply plugin: 'com.android.library'
|
||||
android {
|
||||
// Bumping the plugin compileSdkVersion requires all clients of this plugin
|
||||
// to bump the version in their app.
|
||||
compileSdkVersion 31
|
||||
compileSdkVersion {{compileSdkVersion}}
|
||||
|
||||
// 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.
|
||||
ndkVersion "21.1.6352462"
|
||||
ndkVersion "{{ndkVersion}}"
|
||||
|
||||
// Invoke the shared CMake build with the Android Gradle Plugin.
|
||||
externalNativeBuild {
|
||||
@ -54,6 +54,6 @@ android {
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
minSdkVersion {{minSdkVersion}}
|
||||
}
|
||||
}
|
||||
|
@ -210,6 +210,8 @@
|
||||
"templates/module/android/deferred_component/src/main/AndroidManifest.xml.tmpl",
|
||||
"templates/module/android/gradle/build.gradle.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/src/main/AndroidManifest.xml.tmpl",
|
||||
"templates/module/android/host_app_common/app.tmpl/src/main/java/androidIdentifier/host/MainActivity.java.tmpl",
|
||||
|
@ -29,13 +29,13 @@ void main() {
|
||||
permissionDeniedErrorHandler,
|
||||
flavorUndefinedHandler,
|
||||
r8FailureHandler,
|
||||
minSdkVersion,
|
||||
transformInputIssue,
|
||||
lockFileDepMissing,
|
||||
minSdkVersionHandler,
|
||||
transformInputIssueHandler,
|
||||
lockFileDepMissingHandler,
|
||||
multidexErrorHandler,
|
||||
incompatibleKotlinVersionHandler,
|
||||
minCompileSdkVersionHandler,
|
||||
jvm11Required,
|
||||
jvm11RequiredHandler,
|
||||
])
|
||||
);
|
||||
});
|
||||
@ -754,13 +754,13 @@ assembleProfile
|
||||
|
||||
testWithoutContext('pattern', () {
|
||||
expect(
|
||||
minSdkVersion.test(stdoutLine),
|
||||
minSdkVersionHandler.test(stdoutLine),
|
||||
isTrue,
|
||||
);
|
||||
});
|
||||
|
||||
testUsingContext('suggestion', () async {
|
||||
await minSdkVersion.handler(
|
||||
await minSdkVersionHandler.handler(
|
||||
line: stdoutLine,
|
||||
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
|
||||
);
|
||||
@ -798,7 +798,7 @@ assembleProfile
|
||||
group('transform input issue', () {
|
||||
testWithoutContext('pattern', () {
|
||||
expect(
|
||||
transformInputIssue.test(
|
||||
transformInputIssueHandler.test(
|
||||
'https://issuetracker.google.com/issues/158753935'
|
||||
),
|
||||
isTrue,
|
||||
@ -806,7 +806,7 @@ assembleProfile
|
||||
});
|
||||
|
||||
testUsingContext('suggestion', () async {
|
||||
await transformInputIssue.handler(
|
||||
await transformInputIssueHandler.handler(
|
||||
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
|
||||
);
|
||||
|
||||
@ -836,7 +836,7 @@ assembleProfile
|
||||
group('Dependency mismatch', () {
|
||||
testWithoutContext('pattern', () {
|
||||
expect(
|
||||
lockFileDepMissing.test('''
|
||||
lockFileDepMissingHandler.test('''
|
||||
* What went wrong:
|
||||
Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
|
||||
> Could not resolve all artifacts for configuration ':app:debugRuntimeClasspath'.
|
||||
@ -848,7 +848,7 @@ Execution failed for task ':app:generateDebugFeatureTransitiveDeps'.
|
||||
});
|
||||
|
||||
testUsingContext('suggestion', () async {
|
||||
await lockFileDepMissing.handler(
|
||||
await lockFileDepMissingHandler.handler(
|
||||
project: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
|
||||
);
|
||||
|
||||
@ -960,7 +960,7 @@ Execution failed for task ':app:checkDebugAarMetadata'.
|
||||
group('Java 11 requirement', () {
|
||||
testWithoutContext('pattern', () {
|
||||
expect(
|
||||
jvm11Required.test('''
|
||||
jvm11RequiredHandler.test('''
|
||||
* What went wrong:
|
||||
A problem occurred evaluating project ':flutter'.
|
||||
> Failed to apply plugin 'com.android.internal.library'.
|
||||
@ -975,7 +975,7 @@ A problem occurred evaluating project ':flutter'.
|
||||
});
|
||||
|
||||
testUsingContext('suggestion', () async {
|
||||
await jvm11Required.handler();
|
||||
await jvm11RequiredHandler.handler();
|
||||
|
||||
expect(
|
||||
testLogger.statusText,
|
||||
|
Loading…
x
Reference in New Issue
Block a user