Unverified Commit c4b0322d authored by Bartek Pacia's avatar Bartek Pacia Committed by GitHub

Android Gradle file templates: make it easier to convert them to Kotlin DSL in the future (#142146)

This PR will make it easier for future Flutter-Android apps/plugins/modules etc. to migrate to Gradle Kotlin DSL.

This PR is similar to #140452 but concerns public Gradle templates instead of Flutter's internal Gradle code. It should be a no-op change.

**before**

![before](https://github.com/flutter/flutter/assets/40357511/5d0cb2bb-a693-43bc-aa10-b8f431e0c68c)

**after**

![after](https://github.com/flutter/flutter/assets/40357511/e4a945a5-866f-42f7-813b-b08b26bb89dc)
parent 77c6a86e
...@@ -463,7 +463,7 @@ class AndroidProject extends FlutterProjectPlatform { ...@@ -463,7 +463,7 @@ class AndroidProject extends FlutterProjectPlatform {
/// Pattern used to find the assignment of the "group" property in Gradle. /// Pattern used to find the assignment of the "group" property in Gradle.
/// Expected example: `group "dev.flutter.plugin"` /// Expected example: `group "dev.flutter.plugin"`
/// Regex is used in both Groovy and Kotlin Gradle files. /// Regex is used in both Groovy and Kotlin Gradle files.
static final RegExp _groupPattern = RegExp('^\\s*group\\s+[\'"](.*)[\'"]\\s*\$'); static final RegExp _groupPattern = RegExp('^\\s*group\\s*=?\\s*[\'"](.*)[\'"]\\s*\$');
/// The Gradle root directory of the Android host app. This is the directory /// The Gradle root directory of the Android host app. This is the directory
/// containing the `app/` subdirectory and the `settings.gradle` file that /// containing the `app/` subdirectory and the `settings.gradle` file that
...@@ -538,7 +538,7 @@ class AndroidProject extends FlutterProjectPlatform { ...@@ -538,7 +538,7 @@ class AndroidProject extends FlutterProjectPlatform {
// This case allows for flutter run/build to work for modules. It does // This case allows for flutter run/build to work for modules. It does
// not guarantee the Flutter Gradle Plugin is applied. // not guarantee the Flutter Gradle Plugin is applied.
final bool managed = line.contains("def flutterPluginVersion = 'managed'"); final bool managed = line.contains(RegExp('def flutterPluginVersion = [\'"]managed[\'"]'));
if (fileBasedApply || declarativeApply || managed) { if (fileBasedApply || declarativeApply || managed) {
return true; return true;
} }
......
...@@ -6,53 +6,53 @@ plugins { ...@@ -6,53 +6,53 @@ plugins {
} }
def localProperties = new Properties() def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties') def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) { if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader -> localPropertiesFile.withReader("UTF-8") { reader ->
localProperties.load(reader) localProperties.load(reader)
} }
} }
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) { if (flutterVersionCode == null) {
flutterVersionCode = '1' flutterVersionCode = "1"
} }
def flutterVersionName = localProperties.getProperty('flutter.versionName') def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) { if (flutterVersionName == null) {
flutterVersionName = '1.0' flutterVersionName = "1.0"
} }
android { android {
namespace "{{androidIdentifier}}" namespace = "{{androidIdentifier}}"
compileSdk flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
ndkVersion flutter.ndkVersion ndkVersion = flutter.ndkVersion
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "{{androidIdentifier}}" applicationId = "{{androidIdentifier}}"
// You can update the following values to match your application needs. // You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk flutter.minSdkVersion minSdk = flutter.minSdkVersion
targetSdk flutter.targetSdkVersion targetSdk = flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger() versionCode = flutterVersionCode.toInteger()
versionName flutterVersionName versionName = flutterVersionName
} }
buildTypes { buildTypes {
release { release {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug signingConfig = signingConfigs.debug
} }
} }
} }
flutter { flutter {
source '../..' source = "../.."
} }
...@@ -5,12 +5,12 @@ allprojects { ...@@ -5,12 +5,12 @@ allprojects {
} }
} }
rootProject.buildDir = '../build' rootProject.buildDir = "../build"
subprojects { subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}" project.buildDir = "${rootProject.buildDir}/${project.name}"
} }
subprojects { subprojects {
project.evaluationDependsOn(':app') project.evaluationDependsOn(":app")
} }
tasks.register("clean", Delete) { tasks.register("clean", Delete) {
......
...@@ -6,63 +6,53 @@ plugins { ...@@ -6,63 +6,53 @@ plugins {
} }
def localProperties = new Properties() def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties') def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) { if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader -> localPropertiesFile.withReader("UTF-8") { reader ->
localProperties.load(reader) localProperties.load(reader)
} }
} }
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) { if (flutterVersionCode == null) {
flutterVersionCode = '1' flutterVersionCode = "1"
} }
def flutterVersionName = localProperties.getProperty('flutter.versionName') def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) { if (flutterVersionName == null) {
flutterVersionName = '1.0' flutterVersionName = "1.0"
} }
android { android {
namespace "{{androidIdentifier}}" namespace = "{{androidIdentifier}}"
compileSdk flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
ndkVersion flutter.ndkVersion ndkVersion = flutter.ndkVersion
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
} }
defaultConfig { defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "{{androidIdentifier}}" applicationId = "{{androidIdentifier}}"
// You can update the following values to match your application needs. // You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk flutter.minSdkVersion minSdk = flutter.minSdkVersion
targetSdk flutter.targetSdkVersion targetSdk = flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger() versionCode = flutterVersionCode.toInteger()
versionName flutterVersionName versionName = flutterVersionName
} }
buildTypes { buildTypes {
release { release {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug signingConfig = signingConfigs.debug
} }
} }
} }
flutter { flutter {
source '../..' source = "../.."
} }
dependencies {}
...@@ -5,12 +5,12 @@ allprojects { ...@@ -5,12 +5,12 @@ allprojects {
} }
} }
rootProject.buildDir = '../build' rootProject.buildDir = "../build"
subprojects { subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}" project.buildDir = "${rootProject.buildDir}/${project.name}"
} }
subprojects { subprojects {
project.evaluationDependsOn(':app') project.evaluationDependsOn(":app")
} }
tasks.register("clean", Delete) { tasks.register("clean", Delete) {
......
def localProperties = new Properties() def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties') def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) { if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader -> localPropertiesFile.withReader("UTF-8") { reader ->
localProperties.load(reader) localProperties.load(reader)
} }
} }
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) { if (flutterVersionCode == null) {
flutterVersionCode = '1' flutterVersionCode = "1"
} }
def flutterVersionName = localProperties.getProperty('flutter.versionName') def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) { if (flutterVersionName == null) {
flutterVersionName = '1.0' flutterVersionName = "1.0"
} }
apply plugin: "com.android.dynamic-feature" apply plugin: "com.android.dynamic-feature"
android { android {
compileSdk flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
sourceSets { sourceSets {
...@@ -34,13 +34,13 @@ android { ...@@ -34,13 +34,13 @@ android {
} }
defaultConfig { defaultConfig {
minSdk flutter.minSdkVersion minSdk = flutter.minSdkVersion
targetSdk flutter.targetSdkVersion targetSdk = flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger() versionCode = flutterVersionCode.toInteger()
versionName flutterVersionName versionName = flutterVersionName
} }
} }
dependencies { dependencies {
implementation project(":app") implementation(project(":app"))
} }
// Generated file. Do not edit. // Generated file. Do not edit.
buildscript { buildscript {
ext.kotlin_version = '{{kotlinVersion}}' 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:{{agpVersionForModule}}")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
} }
} }
...@@ -20,21 +20,21 @@ allprojects { ...@@ -20,21 +20,21 @@ allprojects {
} }
} }
apply plugin: 'com.android.library' apply plugin: "com.android.library"
apply plugin: 'kotlin-android' apply plugin: "kotlin-android"
android { android {
// Conditional for compatibility with AGP <4.2. // Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) { if (project.android.hasProperty("namespace")) {
namespace '{{androidIdentifier}}' namespace = "{{androidIdentifier}}"
} }
compileSdk {{compileSdkVersion}} compileSdk = {{compileSdkVersion}}
defaultConfig { defaultConfig {
minSdk {{minSdkVersion}} minSdk = {{minSdkVersion}}
} }
} }
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version")
} }
def flutterPluginVersion = 'managed' def flutterPluginVersion = "managed"
apply plugin: 'com.android.application' apply plugin: "com.android.application"
android { android {
// Conditional for compatibility with AGP <4.2. // Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) { if (project.android.hasProperty("namespace")) {
namespace "{{androidIdentifier}}.host" namespace = "{{androidIdentifier}}.host"
} }
compileSdk {{compileSdkVersion}} compileSdk = {{compileSdkVersion}}
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
defaultConfig { defaultConfig {
applicationId "{{androidIdentifier}}.host" applicationId = "{{androidIdentifier}}.host"
minSdk {{minSdkVersion}} minSdk = {{minSdkVersion}}
targetSdk {{targetSdkVersion}} targetSdk = {{targetSdkVersion}}
versionCode 1 versionCode = 1
versionName "1.0" versionName = "1.0"
} }
buildTypes { buildTypes {
...@@ -30,15 +30,15 @@ android { ...@@ -30,15 +30,15 @@ android {
release { release {
// TODO: Add your own signing config for the release build. // TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works. // Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug signingConfig = signingConfigs.debug
} }
} }
} }
buildDir = new File(rootProject.projectDir, "../build/host") buildDir = new File(rootProject.projectDir, "../build/host")
dependencies { dependencies {
implementation project(':flutter') implementation(project(":flutter"))
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation(fileTree(dir: "libs", include: ["*.jar"]))
implementation 'androidx.appcompat:appcompat:1.0.2' implementation("androidx.appcompat:appcompat:1.0.2")
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation("androidx.constraintlayout:constraintlayout:1.1.3")
} }
// Generated file. Do not edit. // Generated file. Do not edit.
def localProperties = new Properties() def localProperties = new Properties()
def localPropertiesFile = new File(buildscript.sourceFile.parentFile.parentFile, 'local.properties') def localPropertiesFile = new File(buildscript.sourceFile.parentFile.parentFile, "local.properties")
if (localPropertiesFile.exists()) { if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader -> localPropertiesFile.withReader("UTF-8") { reader ->
localProperties.load(reader) localProperties.load(reader)
} }
} }
def flutterRoot = localProperties.getProperty('flutter.sdk') def flutterRoot = localProperties.getProperty("flutter.sdk")
if (flutterRoot == null) { if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
} }
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) { if (flutterVersionCode == null) {
flutterVersionCode = '1' flutterVersionCode = "1"
} }
def flutterVersionName = localProperties.getProperty('flutter.versionName') def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) { if (flutterVersionName == null) {
flutterVersionName = '1.0' flutterVersionName = "1.0"
} }
apply plugin: 'com.android.library' apply plugin: "com.android.library"
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
group '{{androidIdentifier}}' group = "{{androidIdentifier}}"
version '1.0' version = "1.0"
android { android {
// Conditional for compatibility with AGP <4.2. // Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty("namespace")) { if (project.android.hasProperty("namespace")) {
namespace '{{androidIdentifier}}' namespace = "{{androidIdentifier}}"
} }
compileSdk flutter.compileSdkVersion compileSdk = flutter.compileSdkVersion
ndkVersion flutter.ndkVersion ndkVersion = flutter.ndkVersion
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
defaultConfig { defaultConfig {
minSdk flutter.minSdkVersion minSdk = flutter.minSdkVersion
targetSdk flutter.targetSdkVersion targetSdk = flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger() versionCode = flutterVersionCode.toInteger()
versionName flutterVersionName versionName = flutterVersionName
} }
} }
flutter { flutter {
source '../..' source = "../.."
} }
group '{{androidIdentifier}}' group = "{{androidIdentifier}}"
version '1.0' version = "1.0"
buildscript { buildscript {
repositories { repositories {
...@@ -8,7 +8,7 @@ buildscript { ...@@ -8,7 +8,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:{{agpVersion}}' classpath("com.android.tools.build:gradle:{{agpVersion}}")
} }
} }
...@@ -19,27 +19,27 @@ rootProject.allprojects { ...@@ -19,27 +19,27 @@ rootProject.allprojects {
} }
} }
apply plugin: 'com.android.library' apply plugin: "com.android.library"
android { android {
if (project.android.hasProperty("namespace")) { if (project.android.hasProperty("namespace")) {
namespace '{{androidIdentifier}}' namespace = "{{androidIdentifier}}"
} }
compileSdk {{compileSdkVersion}} compileSdk = {{compileSdkVersion}}
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
defaultConfig { defaultConfig {
minSdk {{minSdkVersion}} minSdk = {{minSdkVersion}}
} }
dependencies { dependencies {
testImplementation 'junit:junit:4.13.2' testImplementation("junit:junit:4.13.2")
testImplementation 'org.mockito:mockito-core:5.0.0' testImplementation("org.mockito:mockito-core:5.0.0")
} }
testOptions { testOptions {
......
group '{{androidIdentifier}}' group = "{{androidIdentifier}}"
version '1.0-SNAPSHOT' version = "1.0-SNAPSHOT"
buildscript { buildscript {
ext.kotlin_version = '{{kotlinVersion}}' ext.kotlin_version = "{{kotlinVersion}}"
repositories { repositories {
google() google()
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:{{agpVersion}}' classpath("com.android.tools.build:gradle:{{agpVersion}}")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
} }
} }
...@@ -21,37 +21,37 @@ allprojects { ...@@ -21,37 +21,37 @@ allprojects {
} }
} }
apply plugin: 'com.android.library' apply plugin: "com.android.library"
apply plugin: 'kotlin-android' apply plugin: "kotlin-android"
android { android {
if (project.android.hasProperty("namespace")) { if (project.android.hasProperty("namespace")) {
namespace '{{androidIdentifier}}' namespace = "{{androidIdentifier}}"
} }
compileSdk {{compileSdkVersion}} compileSdk = {{compileSdkVersion}}
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
kotlinOptions { kotlinOptions {
jvmTarget = '1.8' jvmTarget = "1.8"
} }
sourceSets { sourceSets {
main.java.srcDirs += 'src/main/kotlin' main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += 'src/test/kotlin' test.java.srcDirs += "src/test/kotlin"
} }
defaultConfig { defaultConfig {
minSdk {{minSdkVersion}} minSdk = {{minSdkVersion}}
} }
dependencies { dependencies {
testImplementation 'org.jetbrains.kotlin:kotlin-test' testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation 'org.mockito:mockito-core:5.0.0' testImplementation("org.mockito:mockito-core:5.0.0")
} }
testOptions { testOptions {
......
// The Android Gradle Plugin builds the native code with the Android NDK. // The Android Gradle Plugin builds the native code with the Android NDK.
group '{{androidIdentifier}}' group = "{{androidIdentifier}}"
version '1.0' version = "1.0"
buildscript { buildscript {
repositories { repositories {
...@@ -11,7 +11,7 @@ buildscript { ...@@ -11,7 +11,7 @@ buildscript {
dependencies { dependencies {
// The Android Gradle Plugin knows how to build native code with the NDK. // The Android Gradle Plugin knows how to build native code with the NDK.
classpath 'com.android.tools.build:gradle:{{agpVersion}}' classpath("com.android.tools.build:gradle:{{agpVersion}}")
} }
} }
...@@ -22,27 +22,27 @@ rootProject.allprojects { ...@@ -22,27 +22,27 @@ rootProject.allprojects {
} }
} }
apply plugin: 'com.android.library' apply plugin: "com.android.library"
android { android {
if (project.android.hasProperty("namespace")) { if (project.android.hasProperty("namespace")) {
namespace '{{androidIdentifier}}' namespace = "{{androidIdentifier}}"
} }
// Bumping the plugin compileSdk version requires all clients of this plugin // Bumping the plugin compileSdk version requires all clients of this plugin
// to bump the version in their app. // to bump the version in their app.
compileSdk {{compileSdkVersion}} compileSdk = {{compileSdkVersion}}
// Use the NDK version // Use the NDK version
// declared in /android/app/build.gradle file of the Flutter project. // declared in /android/app/build.gradle file of the Flutter project.
// Replace it with a version number if this plugin requires a specific NDK version. // Replace it with a version number if this plugin requires a specific NDK version.
// (e.g. ndkVersion "23.1.7779620") // (e.g. ndkVersion "23.1.7779620")
ndkVersion android.ndkVersion ndkVersion = android.ndkVersion
// Invoke the shared CMake build with the Android Gradle Plugin. // Invoke the shared CMake build with the Android Gradle Plugin.
externalNativeBuild { externalNativeBuild {
cmake { cmake {
path "../src/CMakeLists.txt" path = "../src/CMakeLists.txt"
// The default CMake version for the Android Gradle Plugin is 3.10.2. // The default CMake version for the Android Gradle Plugin is 3.10.2.
// https://developer.android.com/studio/projects/install-ndk#vanilla_cmake // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake
...@@ -55,11 +55,11 @@ android { ...@@ -55,11 +55,11 @@ android {
} }
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
defaultConfig { defaultConfig {
minSdk {{minSdkVersion}} minSdk = {{minSdkVersion}}
} }
} }
...@@ -13,7 +13,7 @@ void main() { ...@@ -13,7 +13,7 @@ void main() {
late String flutterBin; late String flutterBin;
late Directory exampleAppDir; late Directory exampleAppDir;
late Directory pluginDir; late Directory pluginDir;
final RegExp compileSdkVersionMatch = RegExp(r'compileSdk [\w.]+'); final RegExp compileSdkVersionMatch = RegExp(r'compileSdk\s*=?\s*[\w.]+');
final String builtApkPath = <String>['build', 'app', 'outputs', 'flutter-apk', 'app-debug.apk'] final String builtApkPath = <String>['build', 'app', 'outputs', 'flutter-apk', 'app-debug.apk']
.join(platform.pathSeparator); .join(platform.pathSeparator);
...@@ -47,10 +47,10 @@ void main() { ...@@ -47,10 +47,10 @@ void main() {
final File buildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle'); final File buildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle');
// write a build.gradle with compileSdkVersion as `android-UpsideDownCake` which is a string preview version // write a build.gradle with compileSdkVersion as `android-UpsideDownCake` which is a string preview version
buildGradleFile.writeAsStringSync( buildGradleFile.writeAsStringSync(
buildGradleFile.readAsStringSync().replaceFirst(compileSdkVersionMatch, 'compileSdkVersion "android-UpsideDownCake"'), buildGradleFile.readAsStringSync().replaceFirst(compileSdkVersionMatch, 'compileSdkVersion = "android-UpsideDownCake"'),
flush: true flush: true
); );
expect(buildGradleFile.readAsStringSync(), contains('compileSdkVersion "android-UpsideDownCake"')); expect(buildGradleFile.readAsStringSync(), contains('compileSdkVersion = "android-UpsideDownCake"'));
final ProcessResult result = await processManager.run(<String>[ final ProcessResult result = await processManager.run(<String>[
flutterBin, flutterBin,
...@@ -75,10 +75,10 @@ void main() { ...@@ -75,10 +75,10 @@ void main() {
final File buildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle'); final File buildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle');
// write a build.gradle with compileSdkPreview as `UpsideDownCake` which is a string preview version // write a build.gradle with compileSdkPreview as `UpsideDownCake` which is a string preview version
buildGradleFile.writeAsStringSync( buildGradleFile.writeAsStringSync(
buildGradleFile.readAsStringSync().replaceFirst(compileSdkVersionMatch, 'compileSdkPreview "UpsideDownCake"'), buildGradleFile.readAsStringSync().replaceFirst(compileSdkVersionMatch, 'compileSdkPreview = "UpsideDownCake"'),
flush: true flush: true
); );
expect(buildGradleFile.readAsStringSync(), contains('compileSdkPreview "UpsideDownCake"')); expect(buildGradleFile.readAsStringSync(), contains('compileSdkPreview = "UpsideDownCake"'));
final ProcessResult result = await processManager.run(<String>[ final ProcessResult result = await processManager.run(<String>[
flutterBin, flutterBin,
...@@ -103,10 +103,10 @@ void main() { ...@@ -103,10 +103,10 @@ void main() {
final File appBuildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle'); final File appBuildGradleFile = exampleAppDir.childDirectory('android').childDirectory('app').childFile('build.gradle');
// write a build.gradle with compileSdkPreview as `UpsideDownCake` which is a string preview version // write a build.gradle with compileSdkPreview as `UpsideDownCake` which is a string preview version
appBuildGradleFile.writeAsStringSync( appBuildGradleFile.writeAsStringSync(
appBuildGradleFile.readAsStringSync().replaceFirst(compileSdkVersionMatch, 'compileSdkPreview "UpsideDownCake"'), appBuildGradleFile.readAsStringSync().replaceFirst(compileSdkVersionMatch, 'compileSdkPreview = "UpsideDownCake"'),
flush: true flush: true
); );
expect(appBuildGradleFile.readAsStringSync(), contains('compileSdkPreview "UpsideDownCake"')); expect(appBuildGradleFile.readAsStringSync(), contains('compileSdkPreview = "UpsideDownCake"'));
final File pluginBuildGradleFile = pluginDir.childDirectory('android').childFile('build.gradle'); final File pluginBuildGradleFile = pluginDir.childDirectory('android').childFile('build.gradle');
// change the plugin build.gradle to use a preview compile sdk version // change the plugin build.gradle to use a preview compile sdk version
......
...@@ -2907,10 +2907,10 @@ void main() { ...@@ -2907,10 +2907,10 @@ void main() {
final String buildContent = await globals.fs.file('${projectDir.path}/android/app/build.gradle').readAsString(); final String buildContent = await globals.fs.file('${projectDir.path}/android/app/build.gradle').readAsString();
expect(buildContent.contains('compileSdk flutter.compileSdkVersion'), true); expect(buildContent.contains('compileSdk = flutter.compileSdkVersion'), true);
expect(buildContent.contains('ndkVersion flutter.ndkVersion'), true); expect(buildContent.contains('ndkVersion = flutter.ndkVersion'), true);
expect(buildContent.contains('minSdk flutter.minSdkVersion'), true); expect(buildContent.contains('minSdk = flutter.minSdkVersion'), true);
expect(buildContent.contains('targetSdk flutter.targetSdkVersion'), true); expect(buildContent.contains('targetSdk = flutter.targetSdkVersion'), true);
}); });
testUsingContext('Android Java plugin contains namespace', () async { testUsingContext('Android Java plugin contains namespace', () async {
...@@ -2932,7 +2932,7 @@ void main() { ...@@ -2932,7 +2932,7 @@ void main() {
final String buildGradleContent = await buildGradleFile.readAsString(); final String buildGradleContent = await buildGradleFile.readAsString();
expect(buildGradleContent.contains("namespace 'com.bar.foo.flutter_project'"), true); expect(buildGradleContent.contains('namespace = "com.bar.foo.flutter_project"'), true);
// The namespace should be conditionalized for AGP <4.2. // The namespace should be conditionalized for AGP <4.2.
expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true); expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true);
}); });
...@@ -2955,7 +2955,7 @@ void main() { ...@@ -2955,7 +2955,7 @@ void main() {
final String buildGradleContent = await buildGradleFile.readAsString(); final String buildGradleContent = await buildGradleFile.readAsString();
expect(buildGradleContent.contains("namespace 'com.bar.foo.flutter_project'"), true); expect(buildGradleContent.contains('namespace = "com.bar.foo.flutter_project"'), true);
// The namespace should be conditionalized for AGP <4.2. // The namespace should be conditionalized for AGP <4.2.
expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true); expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true);
}); });
...@@ -2979,7 +2979,7 @@ void main() { ...@@ -2979,7 +2979,7 @@ void main() {
final String buildGradleContent = await buildGradleFile.readAsString(); final String buildGradleContent = await buildGradleFile.readAsString();
expect(buildGradleContent.contains("namespace 'com.bar.foo.flutter_project'"), true); expect(buildGradleContent.contains('namespace = "com.bar.foo.flutter_project"'), true);
// The namespace should be conditionalized for AGP <4.2. // The namespace should be conditionalized for AGP <4.2.
expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true); expect(buildGradleContent.contains('if (project.android.hasProperty("namespace")) {'), true);
}); });
...@@ -3002,10 +3002,10 @@ void main() { ...@@ -3002,10 +3002,10 @@ void main() {
final String moduleFlutterBuildGradleFileContent = await globals.fs.file(globals.fs.path.join(projectDir.path, moduleFlutterBuildGradleFilePath)).readAsString(); final String moduleFlutterBuildGradleFileContent = await globals.fs.file(globals.fs.path.join(projectDir.path, moduleFlutterBuildGradleFilePath)).readAsString();
// Each build file should contain the expected namespace. // Each build file should contain the expected namespace.
const String expectedNameSpace = "namespace 'com.bar.foo.flutter_project'"; const String expectedNameSpace = 'namespace = "com.bar.foo.flutter_project"';
expect(moduleBuildGradleFileContent.contains(expectedNameSpace), true); expect(moduleBuildGradleFileContent.contains(expectedNameSpace), true);
expect(moduleFlutterBuildGradleFileContent.contains(expectedNameSpace), true); expect(moduleFlutterBuildGradleFileContent.contains(expectedNameSpace), true);
const String expectedHostNameSpace = 'namespace "com.bar.foo.flutter_project.host"'; const String expectedHostNameSpace = 'namespace = "com.bar.foo.flutter_project.host"';
expect(moduleAppBuildGradleFileContent.contains(expectedHostNameSpace), true); expect(moduleAppBuildGradleFileContent.contains(expectedHostNameSpace), true);
// The namespaces should be conditionalized for AGP <4.2. // The namespaces should be conditionalized for AGP <4.2.
......
...@@ -47,9 +47,9 @@ void main() { ...@@ -47,9 +47,9 @@ void main() {
final String pluginBuildGradle = pluginGradleFile.readAsStringSync(); final String pluginBuildGradle = pluginGradleFile.readAsStringSync();
// Bump up plugin compileSdk version to 31 // Bump up plugin compileSdk version to 31
final RegExp androidCompileSdkVersionRegExp = RegExp(r'compileSdk ([0-9]+|flutter.compileSdkVersion)'); final RegExp androidCompileSdkVersionRegExp = RegExp(r'compileSdk = ([0-9]+|flutter.compileSdkVersion)');
final String newPluginGradleFile = pluginBuildGradle.replaceAll( final String newPluginGradleFile = pluginBuildGradle.replaceAll(
androidCompileSdkVersionRegExp, 'compileSdk 31'); androidCompileSdkVersionRegExp, 'compileSdk = 31');
pluginGradleFile.writeAsStringSync(newPluginGradleFile); pluginGradleFile.writeAsStringSync(newPluginGradleFile);
final Directory pluginExampleAppDir = pluginAppDir.childDirectory('example'); final Directory pluginExampleAppDir = pluginAppDir.childDirectory('example');
...@@ -61,7 +61,7 @@ void main() { ...@@ -61,7 +61,7 @@ void main() {
// Bump down plugin example app compileSdk version to 30 // Bump down plugin example app compileSdk version to 30
final String newProjectGradleFile = projectBuildGradle.replaceAll( final String newProjectGradleFile = projectBuildGradle.replaceAll(
androidCompileSdkVersionRegExp, 'compileSdk 30'); androidCompileSdkVersionRegExp, 'compileSdk = 30');
projectGradleFile.writeAsStringSync(newProjectGradleFile); projectGradleFile.writeAsStringSync(newProjectGradleFile);
// Run flutter build apk to build plugin example project // Run flutter build apk to build plugin example project
......
...@@ -46,8 +46,8 @@ void main() { ...@@ -46,8 +46,8 @@ void main() {
final String pluginBuildGradle = pluginGradleFile.readAsStringSync(); final String pluginBuildGradle = pluginGradleFile.readAsStringSync();
// Bump up plugin ndkVersion to 21.4.7075529. // Bump up plugin ndkVersion to 21.4.7075529.
final RegExp androidNdkVersionRegExp = RegExp(r'ndkVersion (\"[0-9\.]+\"|flutter.ndkVersion|android.ndkVersion)'); final RegExp androidNdkVersionRegExp = RegExp(r'ndkVersion = (\"[0-9\.]+\"|flutter.ndkVersion|android.ndkVersion)');
final String newPluginGradleFile = pluginBuildGradle.replaceAll(androidNdkVersionRegExp, 'ndkVersion "21.4.7075529"'); final String newPluginGradleFile = pluginBuildGradle.replaceAll(androidNdkVersionRegExp, 'ndkVersion = "21.4.7075529"');
expect(newPluginGradleFile, contains('21.4.7075529')); expect(newPluginGradleFile, contains('21.4.7075529'));
pluginGradleFile.writeAsStringSync(newPluginGradleFile); pluginGradleFile.writeAsStringSync(newPluginGradleFile);
...@@ -59,7 +59,7 @@ void main() { ...@@ -59,7 +59,7 @@ void main() {
final String projectBuildGradle = projectGradleFile.readAsStringSync(); final String projectBuildGradle = projectGradleFile.readAsStringSync();
// Bump down plugin example app ndkVersion to 21.1.6352462. // Bump down plugin example app ndkVersion to 21.1.6352462.
final String newProjectGradleFile = projectBuildGradle.replaceAll(androidNdkVersionRegExp, 'ndkVersion "21.1.6352462"'); final String newProjectGradleFile = projectBuildGradle.replaceAll(androidNdkVersionRegExp, 'ndkVersion = "21.1.6352462"');
expect(newProjectGradleFile, contains('21.1.6352462')); expect(newProjectGradleFile, contains('21.1.6352462'));
projectGradleFile.writeAsStringSync(newProjectGradleFile); projectGradleFile.writeAsStringSync(newProjectGradleFile);
......
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