Skip to content

Commit f2ae49c

Browse files
authored
Merge pull request #343 from hannesa2/AndroidGradle-9.0.0
Android gradle 9.0.0
2 parents 872b323 + a131cd6 commit f2ae49c

6 files changed

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

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
}
88

99
dependencies {
10-
classpath("com.android.tools.build:gradle:8.13.0")
10+
classpath("com.android.tools.build:gradle:9.0.0")
1111
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.10")
1212
}
1313
}

githubAppUpdate/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget
22

33
plugins {
44
id("com.android.library")
5-
id("kotlin-android")
65
id("maven-publish")
76
}
87

githubAppUpdate/proguard-rules.pro

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Keep Kotlin metadata for coroutines
2+
-keep class kotlin.Metadata { *; }
3+
-keepattributes RuntimeVisibleAnnotations
4+
-keepattributes *Annotation*
5+
6+
# Keep coroutine related classes
7+
-keepclassmembernames class kotlinx.** {
8+
volatile <fields>;
9+
}
10+
11+
# Preserve Kotlin coroutine internal structures
12+
-keep class kotlin.coroutines.** { *; }
13+
-keep class kotlinx.coroutines.** { *; }
14+
15+
# Don't obfuscate Kotlin metadata
16+
-keepattributes SourceFile,LineNumberTable
17+
-renamesourcefileattribute SourceFile
18+
19+
# Keep synthetic methods for Kotlin coroutines
20+
-keepclassmembers class ** {
21+
synthetic <methods>;
22+
}
23+
24+
# Preserve function types
25+
-keep class kotlin.jvm.functions.** { *; }
26+
27+
# Don't warn about R8 issues with Kotlin metadata
28+
-dontwarn kotlin.Metadata
29+
-dontwarn kotlinx.coroutines.**
30+
31+
# Keep lifecycle coroutine scope
32+
-keep class androidx.lifecycle.** { *; }
33+
-keepclassmembers class androidx.lifecycle.** { *; }

0 commit comments

Comments
 (0)