Skip to content

Commit 999e172

Browse files
committed
Move from gradle to kts
Migrate BuildConfig to Gradle Build Files
1 parent 872b323 commit 999e172

3 files changed

Lines changed: 100 additions & 89 deletions

File tree

README.md

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,50 @@ This library provides an easy way to update app with provided apk in release.
2828
)
2929
```
3030

31-
3. And you need repository info eg in `build.config`
32-
33-
```groovy
31+
3. And you need repository info eg in `build.gradle.kts`
32+
33+
In kts you can use submodule buildSrc
34+
35+
```kotlin
36+
import info.git.versionHelper.getGitCommitCount
37+
import info.git.versionHelper.getGitOriginRemote
38+
39+
android {
3440
defaultConfig {
35-
...
36-
versionCode getGitCommitCount()
37-
38-
buildConfigField "String", 'GIT_REPOSITORY', "\"" + getGitRepository() + "\""
39-
}
40-
41-
static def getGitCommitCount() {
42-
def process = "git rev-list HEAD --count".execute()
43-
return process.text.toInteger()
41+
versionCode = getGitCommitCount()
42+
buildConfigField("String", "GIT_REPOSITORY", "\"" + getGitOriginRemote() + "\"")
4443
}
45-
46-
static def getGitOriginRemote() {
47-
def process = "git remote -v".execute()
48-
def values = process.text.toString().trim().split("\\r\\n|\\n|\\r")
49-
50-
def found = values.find { it.startsWith("origin") && it.endsWith("(push)") }
51-
return found.replace("origin", "").replace("(push)", "").replace(".git", "").trim()
52-
}
53-
54-
static def getGitRepository() {
55-
def token = getGitOriginRemote().split("/")
56-
return token[4]
44+
}
45+
```
46+
eg groovy in `build.gradle`
47+
```groovy
48+
android {
49+
defaultConfig {
50+
...
51+
versionCode getGitCommitCount()
52+
53+
buildConfigField "String", 'GIT_REPOSITORY', "\"" + getGitRepository() + "\""
5754
}
58-
```
55+
}
56+
57+
static def getGitCommitCount() {
58+
def process = "git rev-list HEAD --count".execute()
59+
return process.text.toInteger()
60+
}
61+
62+
static def getGitOriginRemote() {
63+
def process = "git remote -v".execute()
64+
def values = process.text.toString().trim().split("\\r\\n|\\n|\\r")
65+
66+
def found = values.find { it.startsWith("origin") && it.endsWith("(push)") }
67+
return found.replace("origin", "").replace("(push)", "").replace(".git", "").trim()
68+
}
5969
70+
static def getGitRepository() {
71+
def token = getGitOriginRemote().split("/")
72+
return token[4]
73+
}
74+
```
6075
## Include the library
6176

6277
The easiest way to add `githubAppUpdate` to your project is via Gradle. Just add the following lines to your `build.gradle`:
@@ -83,7 +98,7 @@ You can specify now an optional personal access token for github. Then it works
8398

8499
## License
85100

86-
Copyright (C) 2025 hannesa2
101+
Copyright (C) 2026 hannesa2
87102

88103
Licensed under the Apache License, Version 2.0 (the "License");
89104
you may not use this file except in compliance with the License.

app/build.gradle

Lines changed: 0 additions & 63 deletions
This file was deleted.

app/build.gradle.kts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import info.git.versionHelper.getGitCommitCount
2+
import info.git.versionHelper.getGitOriginRemote
3+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
4+
5+
plugins {
6+
id("com.android.application")
7+
id("kotlin-android")
8+
}
9+
10+
android {
11+
namespace = "info.hannes.github.sample"
12+
compileSdk = 36
13+
defaultConfig {
14+
versionCode = getGitCommitCount()
15+
versionName = "1.0"
16+
17+
minSdk = 23
18+
19+
buildConfigField("String", "GIT_REPOSITORY", "\"" + getGitOriginRemote() + "\"")
20+
21+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
22+
testInstrumentationRunnerArguments.putAll(
23+
mapOf(
24+
"useTestStorageService" to "true",
25+
),
26+
)
27+
}
28+
packaging {
29+
resources {
30+
pickFirsts += setOf("META-INF/atomicfu.kotlin_module")
31+
}
32+
}
33+
compileOptions {
34+
sourceCompatibility = JavaVersion.VERSION_17
35+
targetCompatibility = JavaVersion.VERSION_17
36+
}
37+
kotlin {
38+
compilerOptions {
39+
jvmTarget = JvmTarget.JVM_17
40+
}
41+
}
42+
43+
buildFeatures {
44+
viewBinding = true
45+
buildConfig = true
46+
}
47+
}
48+
49+
dependencies {
50+
implementation(project(":githubAppUpdate"))
51+
implementation("androidx.legacy:legacy-support-v4:1.0.0")
52+
implementation("androidx.appcompat:appcompat:1.7.1")
53+
implementation("com.google.android.material:material:1.13.0")
54+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.3.10")
55+
56+
androidTestImplementation("androidx.test.ext:junit-ktx:1.2.1")
57+
androidTestUtil("androidx.test.services:test-services:1.6.0")
58+
androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
59+
}

0 commit comments

Comments
 (0)