From ef13a7b5492d87774921f60eb020e3ed14e80948 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Tran Date: Fri, 21 Nov 2025 18:13:11 +0700 Subject: [PATCH] update android build follow guide: https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply --- example/android/app/build.gradle | 33 +++++++++++-------- .../android/app/src/main/AndroidManifest.xml | 4 +-- example/android/build.gradle | 14 +------- .../gradle/wrapper/gradle-wrapper.properties | 4 +-- example/android/settings.gradle | 30 ++++++++++++----- 5 files changed, 47 insertions(+), 38 deletions(-) diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 3927e33..c7a2c3c 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' @@ -21,12 +22,10 @@ if (flutterVersionName == null) { flutterVersionName = '1.0' } -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { - compileSdkVersion 31 + namespace "com.example.example" + + compileSdkVersion 36 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -36,7 +35,7 @@ android { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.example" minSdkVersion flutter.minSdkVersion - targetSdkVersion 30 + targetSdkVersion 36 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } @@ -48,6 +47,15 @@ android { signingConfig signingConfigs.debug } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_21 + targetCompatibility JavaVersion.VERSION_21 + } + + kotlinOptions { + jvmTarget = "21" + } } flutter { @@ -55,5 +63,4 @@ flutter { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" -} +} \ No newline at end of file diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 34dd77e..3ff9f2a 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,10 +1,10 @@ - + properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" // apply true + id "com.android.application" version '8.13.1' apply false + id "org.jetbrains.kotlin.android" version "2.2.21" apply false +} + +include ":app" \ No newline at end of file