Skip to content

Commit

Permalink
Add version name and code to manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
gavv authored and ortex committed Dec 13, 2022
1 parent b8ed422 commit 60edf83
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install SDK
uses: malinskiy/action-android/install-sdk@release/0.1.4
Expand All @@ -44,6 +46,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install SDK
uses: malinskiy/action-android/install-sdk@release/0.1.4
Expand Down
54 changes: 49 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
def getVersionName = { ->
def manifest = new XmlSlurper().parse(file('src/main/AndroidManifest.xml'))
def manifestName = manifest.@'android:versionName'.text()

def gitStdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--tags', '--abbrev=0'
standardOutput = gitStdout
}
def gitTag = gitStdout.toString().trim().replaceAll('v', '')

if (manifestName != gitTag) {
throw new GradleException(
"Mismatched android:versionName in AndroidManifest.xml and git tag: "+
"versionName = $manifestName, "+
"gitTag = $gitTag")
}

return manifestName
}

def getVersionCode = { ->
def manifest = new XmlSlurper().parse(file('src/main/AndroidManifest.xml'))
def manifestName = manifest.@'android:versionName'.text()
def manifestCode = manifest.@'android:versionCode'.text()

def expectedCode = 0
def mult = 1
manifestName.tokenize('.').reverse().each {
expectedCode += it.toInteger() * mult
mult *= 1000
}

if (manifestCode != expectedCode.toString()) {
throw new GradleException(
"Mismatched android:versionName and android:versionCode in AndroidManifest.xml: "+
"versionName = $manifestName, "+
"versionCode = $manifestCode, "+
"expectedCode = $expectedCode")
}

return manifestCode.toInteger()
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Expand All @@ -8,13 +52,13 @@ android {
ndkVersion project.ndkVersion

defaultConfig {
applicationId "org.rocstreaming.rocdroid"
applicationId 'org.rocstreaming.rocdroid'
minSdkVersion project.minSdkVersion.toInteger()
targetSdkVersion project.targetSdkVersion.toInteger()
versionCode 1
versionName "1.0"
versionName getVersionName()
versionCode getVersionCode()

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}

compileOptions {
Expand All @@ -23,7 +67,7 @@ android {
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = '1.8'
}

lintOptions {
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.rocstreaming.rocdroid">
package="org.rocstreaming.rocdroid"
android:versionName="0.0.3"
android:versionCode="3">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down Expand Up @@ -31,4 +33,4 @@
</activity>
</application>

</manifest>
</manifest>

0 comments on commit 60edf83

Please sign in to comment.