Skip to content

Commit f0146d7

Browse files
committed
example: upgrade to declarative Gradle buildfiles
1 parent 6b38184 commit f0146d7

File tree

3 files changed

+34
-47
lines changed

3 files changed

+34
-47
lines changed

example/android/app/build.gradle

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
plugins {
2+
id "com.android.application"
3+
id "org.jetbrains.kotlin.android"
4+
id "dev.flutter.flutter-gradle-plugin"
5+
}
6+
17
def localProperties = new Properties()
28
def localPropertiesFile = rootProject.file("local.properties")
39
if (localPropertiesFile.exists()) {
@@ -6,11 +12,6 @@ if (localPropertiesFile.exists()) {
612
}
713
}
814

9-
def flutterRoot = localProperties.getProperty("flutter.sdk")
10-
if (flutterRoot == null) {
11-
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12-
}
13-
1415
def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
1516
if (flutterVersionCode == null) {
1617
flutterVersionCode = "1"
@@ -21,21 +22,17 @@ if (flutterVersionName == null) {
2122
flutterVersionName = "1.0"
2223
}
2324

24-
apply plugin: "com.android.application"
25-
apply plugin: 'kotlin-android'
26-
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27-
2825
android {
29-
compileSdk 34
30-
31-
namespace "vn.hunghd.example"
26+
namespace = "vn.hunghd.example"
27+
compileSdk = 34
28+
ndkVersion = flutter.ndkVersion
3229

3330
defaultConfig {
3431
applicationId "vn.hunghd.example"
35-
minSdk 19
36-
targetSdk 33
37-
versionCode flutterVersionCode.toInteger()
38-
versionName flutterVersionName
32+
minSdk = 21
33+
targetSdk = 34
34+
versionCode = flutterVersionCode.toInteger()
35+
versionName = flutterVersionName
3936
}
4037

4138
buildTypes {

example/android/build.gradle

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
buildscript {
2-
ext.kotlin_version = "1.7.22"
3-
repositories {
4-
google()
5-
mavenCentral()
6-
}
7-
8-
dependencies {
9-
classpath "com.android.tools.build:gradle:7.4.2"
10-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11-
}
12-
}
13-
14-
allprojects {
15-
repositories {
16-
google()
17-
mavenCentral()
18-
}
19-
}
20-
211
rootProject.buildDir = "../build"
222
subprojects {
233
project.buildDir = "${rootProject.buildDir}/${project.name}"
@@ -27,5 +7,5 @@ subprojects {
277
}
288

299
tasks.register("clean", Delete) {
30-
delete rootProject.buildDir
10+
delete(rootProject.buildDir)
3111
}

example/android/settings.gradle

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1-
include ":app"
1+
pluginManagement {
2+
def flutterSdkPath = {
3+
def properties = new Properties()
4+
file("local.properties").withInputStream { properties.load(it) }
5+
def flutterSdkPath = properties.getProperty("flutter.sdk")
6+
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7+
return flutterSdkPath
8+
}()
29

3-
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
10+
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
411

5-
def plugins = new Properties()
6-
def pluginsFile = new File(flutterProjectRoot.toFile(), ".flutter-plugins")
7-
if (pluginsFile.exists()) {
8-
pluginsFile.withReader("UTF-8") { reader -> plugins.load(reader) }
12+
repositories {
13+
google()
14+
mavenCentral()
15+
gradlePluginPortal()
16+
}
917
}
1018

11-
plugins.each { name, path ->
12-
def pluginDirectory = flutterProjectRoot.resolve(path).resolve("android").toFile()
13-
include ":$name"
14-
project(":$name").projectDir = pluginDirectory
19+
plugins {
20+
id("dev.flutter.flutter-plugin-loader")
21+
id("com.android.application") version ("8.3.1") apply false
22+
id("org.jetbrains.kotlin.android") version ("1.9.23") apply false
1523
}
24+
25+
include(":app")

0 commit comments

Comments
 (0)