Skip to content

Commit 1d9da1f

Browse files
authored
Clean up Gradle build files (#778)
* clean up various Gradle-related things * re-enable ktlint
1 parent cc62a52 commit 1d9da1f

File tree

13 files changed

+56
-72
lines changed

13 files changed

+56
-72
lines changed

.github/workflows/prepare.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ jobs:
5555
run: flutter test
5656

5757
# disabled because always fails for strange reasons
58-
# - name: ktlint check
59-
# working-directory: example/android
60-
# run: ./gradlew :flutter_downloader:ktlintCheck
58+
- name: ktlint check
59+
working-directory: example/android
60+
run: ./gradlew flutter_downloader:ktlintCheck
6161

6262
- name: flutter pub get (example app)
6363
working-directory: ./example

android/build.gradle

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,47 @@
1-
group 'vn.hunghd.flutterdownloader'
2-
version '1.0-SNAPSHOT'
3-
41
buildscript {
5-
ext.kotlin_version = '1.7.10'
2+
ext.kotlin_version = "1.7.22"
63
repositories {
74
google()
85
mavenCentral()
9-
maven {
10-
url "https://plugins.gradle.org/m2/"
11-
}
126
}
137

148
dependencies {
15-
classpath 'com.android.tools.build:gradle:7.2.2'
9+
classpath "com.android.tools.build:gradle:7.2.2"
1610
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
17-
classpath 'org.jlleitschuh.gradle:ktlint-gradle:11.0.0'
1811
}
1912
}
2013

14+
plugins {
15+
id "com.android.library"
16+
id "kotlin-android"
17+
id "org.jlleitschuh.gradle.ktlint" version "11.0.0"
18+
}
19+
20+
group "vn.hunghd.flutterdownloader"
21+
version "1.0-SNAPSHOT"
22+
2123
rootProject.allprojects {
2224
repositories {
2325
google()
2426
mavenCentral()
2527
}
2628
}
2729

28-
apply plugin: 'com.android.library'
29-
apply plugin: 'org.jetbrains.kotlin.android'
30-
apply plugin: "org.jlleitschuh.gradle.ktlint"
31-
3230
android {
33-
compileSdkVersion 32
31+
compileSdk 32
3432

35-
defaultConfig {
36-
minSdkVersion 19
37-
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
38-
}
39-
lintOptions {
40-
disable 'InvalidPackage'
41-
}
42-
compileOptions {
43-
sourceCompatibility JavaVersion.VERSION_1_8
44-
targetCompatibility JavaVersion.VERSION_1_8
45-
}
4633
sourceSets {
47-
main.java.srcDirs += 'src/main/kotlin'
34+
main.java.srcDirs += "src/main/kotlin"
35+
}
36+
37+
defaultConfig {
38+
minSdk 19
39+
targetSdk 32
4840
}
4941
}
5042

5143
dependencies {
52-
implementation 'androidx.work:work-runtime:2.7.1'
53-
implementation 'androidx.annotation:annotation:1.4.0'
54-
implementation 'androidx.core:core:1.9.0'
55-
implementation 'androidx.fragment:fragment:1.5.2'
44+
implementation "androidx.work:work-runtime:2.7.1"
45+
implementation "androidx.annotation:annotation:1.5.0"
46+
implementation "androidx.core:core-ktx:1.9.0"
5647
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
43
zipStoreBase=GRADLE_USER_HOME
54
zipStorePath=wrapper/dists
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip

android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name = 'flutter_downloader'
1+
rootProject.name = "flutter_downloader"

android/src/main/kotlin/vn/hunghd/flutterdownloader/FlutterDownloaderPlugin.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class FlutterDownloaderPlugin : MethodChannel.MethodCallHandler, FlutterPlugin {
8989
openFileFromNotification: Boolean,
9090
isResume: Boolean,
9191
requiresStorageNotLow: Boolean,
92-
saveInPublicStorage: Boolean,
92+
saveInPublicStorage: Boolean,
9393
timeout: Int,
9494
allowCellular: Boolean,
9595
): WorkRequest {

android/src/main/kotlin/vn/hunghd/flutterdownloader/TaskDao.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TaskDao(private val dbHelper: TaskDbHelper) {
5555
values.put(TaskEntry.COLUMN_NAME_RESUMABLE, 0)
5656
values.put(TaskEntry.COLUMN_NAME_TIME_CREATED, System.currentTimeMillis())
5757
values.put(TaskEntry.COLUMN_SAVE_IN_PUBLIC_STORAGE, if (saveInPublicStorage) 1 else 0)
58-
values.put(TaskEntry.COLUMN_ALLOW_CELLULAR, if(allowCellular) 1 else 0)
58+
values.put(TaskEntry.COLUMN_ALLOW_CELLULAR, if (allowCellular) 1 else 0)
5959
db.beginTransaction()
6060
try {
6161
db.insertWithOnConflict(

android/src/main/kotlin/vn/hunghd/flutterdownloader/TaskDbHelper.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ class TaskDbHelper private constructor(context: Context) :
1212
}
1313

1414
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
15-
if(newVersion == 4) {
15+
if (newVersion == 4) {
1616
db.execSQL("ALTER TABLE ${TaskEntry.TABLE_NAME} ADD COLUMN ${TaskEntry.COLUMN_ALLOW_CELLULAR} TINYINT DEFAULT 1")
17-
}
18-
else if (oldVersion == 2 && newVersion == 3) {
17+
} else if (oldVersion == 2 && newVersion == 3) {
1918
db.execSQL("ALTER TABLE " + TaskEntry.TABLE_NAME + " ADD COLUMN " + TaskEntry.COLUMN_SAVE_IN_PUBLIC_STORAGE + " TINYINT DEFAULT 0")
2019
} else {
2120
db.execSQL(SQL_DELETE_ENTRIES)

example/android/app/build.gradle

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,50 @@
11
def localProperties = new Properties()
2-
def localPropertiesFile = rootProject.file('local.properties')
2+
def localPropertiesFile = rootProject.file("local.properties")
33
if (localPropertiesFile.exists()) {
4-
localPropertiesFile.withReader('UTF-8') { reader ->
4+
localPropertiesFile.withReader("UTF-8") { reader ->
55
localProperties.load(reader)
66
}
77
}
88

9-
def flutterRoot = localProperties.getProperty('flutter.sdk')
9+
def flutterRoot = localProperties.getProperty("flutter.sdk")
1010
if (flutterRoot == null) {
1111
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
1212
}
1313

14-
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
14+
def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
1515
if (flutterVersionCode == null) {
16-
flutterVersionCode = '1'
16+
flutterVersionCode = "1"
1717
}
1818

19-
def flutterVersionName = localProperties.getProperty('flutter.versionName')
19+
def flutterVersionName = localProperties.getProperty("flutter.versionName")
2020
if (flutterVersionName == null) {
21-
flutterVersionName = '1.0'
21+
flutterVersionName = "1.0"
2222
}
2323

24-
apply plugin: 'com.android.application'
24+
apply plugin: "com.android.application"
2525
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
2626

2727
android {
28-
compileSdkVersion 33
28+
compileSdk 33
2929

30-
namespace 'vn.hunghd.example'
30+
namespace "vn.hunghd.example"
3131

3232
defaultConfig {
33-
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3433
applicationId "vn.hunghd.example"
35-
minSdkVersion 19
36-
targetSdkVersion 33
34+
minSdk 19
35+
targetSdk 33
3736
versionCode flutterVersionCode.toInteger()
3837
versionName flutterVersionName
3938
}
4039

4140
buildTypes {
4241
release {
43-
// TODO: Add your own signing config for the release build.
4442
// Signing with the debug keys for now, so `flutter run --release` works.
4543
signingConfig signingConfigs.debug
4644
}
4745
}
48-
49-
lint {
50-
disable 'InvalidPackage'
51-
}
5246
}
5347

5448
flutter {
55-
source '../..'
49+
source "../.."
5650
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
android:resource="@drawable/launch_background" />
3030
</activity>
3131
<!-- Don't delete the meta-data below.
32-
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
32+
This is used by the Flutter tool to generate GeneratedPluginRegistrant.kotlin -->
3333
<meta-data
3434
android:name="flutterEmbedding"
3535
android:value="2" />

example/android/app/src/main/java/vn/hunghd/example/MainActivity.java renamed to example/android/app/src/main/kotlin/vn/hunghd/example/MainActivity.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
import io.flutter.embedding.android.FlutterActivity;
44

5-
public class MainActivity extends FlutterActivity {
6-
7-
}
5+
class MainActivity : FlutterActivity()

0 commit comments

Comments
 (0)