fbpx

แก้ไขไฟล์ Gradle เพื่อรองรับ Android API 34

แก้ไขไฟล์ Gradle เพื่อรองรับ Android API 34

 

Update 27/04.2567

ไปที่ project/android/settings.gradle

เปลี่ยน

org.jetbrains.kotlin.android เป็น version

1.9.23
******************************************
บทความเก่า
******************************************

1.  ขั้นตอนที่ 1 ไปที่ android/settings.gradle

เพิ่มข้อมูล

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-plugin-loader” version “1.0.0”
id “com.android.application” version “{agpVersion}” apply false
id “org.jetbrains.kotlin.android” version “{kgpVersion}” apply false
}

include “:app”

แก้ไขส่วนของ plugins  เป็น

plugins {
id “dev.flutter.flutter-plugin-loader” version “1.0.0”
id “com.android.application” version “8.2.1” apply false // AGP – https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
id “org.jetbrains.kotlin.android” version “1.9.22” apply false // KGP – https://kotlinlang.org/docs/gradle-configure-project.html#apply-the-plugin
}

 

ขั้นตอนที่ 2. android/gradle/wrapper/gradle-wrapper.properties

เปลี่ยนข้อมูลเป็นดังต่อไปนี้

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip

 

หากไม่สามารถใช้งาน code เดิมได้ให้อัพเดท android studio และสร้างโปรเจคใหม่

 

 

เข้าสู่ระบบ