Skip to content

Commit

Permalink
[chore] Set android versionCode and android versionName at buildtime (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pazos authored and Frenzie committed Feb 3, 2019
1 parent c7371bc commit 8fd3ee7
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
5 changes: 3 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.koreader.launcher"
android:versionCode="4"
android:versionName="1.4">
android:versionCode="5"
android:versionName="1.5"
>
<uses-sdk android:minSdkVersion="14" />
<uses-sdk android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Expand Down
41 changes: 33 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Supported Android ABIs: armeabi-v7a, x86 and x86_64

ifdef ANDROID_ARCH
ifeq ($(ANDROID_ARCH), arm)
ANDROID_FULL_ARCH?=armeabi-v7a
Expand All @@ -11,13 +10,35 @@ endif
# Default is build for arm
ANDROID_FULL_ARCH?=armeabi-v7a

# Minimum SDK API is 19, required to use View.VERSION_CODES.KITKAT
SDKAPI_MIN=$(shell [ ${NDKABI} -ge 19 ] && echo -n ${NDKABI} || echo -n 19)
# API19 is used by the docker build image.
# It's also required to use View.VERSION_CODES.KITKAT.
TARGET_API=19

ifdef NDKABI
# Update target API if is higher than current target
SDKAPI=$(shell [ ${NDKABI} -gt ${TARGET_API} ] && echo -n ${NDKABI} || echo -n ${TARGET_API})
endif

SDKAPI?=$(TARGET_API)

# override android:versionName="string"
ifdef ANDROID_NAME
NAME?=$(ANDROID_NAME)
endif

# override android:versionCode="integer"
ifdef ANDROID_VERSION
VERSION?=$(ANDROID_VERSION)
endif

# Defaults
NAME?=1.5
VERSION?=5

update:
# update local.properties and project.properties with sdk/ndk paths for current user
# this works with sdk tools <= 25.3.0
android update project --path . -t android-$(SDKAPI_MIN)
android update project --path . -t android-$(SDKAPI)

# update sources
git submodule init
Expand All @@ -30,16 +51,20 @@ build-native:
ndk-build ANDROID_FULL_ARCH=$(ANDROID_FULL_ARCH)

debug: update build-native
ant debug
# build signed debug apk, with version code and version name
ant -Dname=$(NAME) -Dcode=$(VERSION) debug
cp -pv bin/NativeActivity-debug.apk bin/NativeActivity.apk
@echo "application was built, type: debug (signed)"

release: update build-native
ant release
# build unsigned release apk, with version code and version name
@echo "Building release APK, Version $(NAME), release $(VERSION)"
ant -Dname=$(NAME) -Dcode=$(VERSION) release
cp -pv bin/NativeActivity-release-unsigned.apk bin/NativeActivity.apk
@echo "application was built, type: release (unsigned)"
@echo "You'll need to sign this application to be able to install it"
@echo "application was built, type: release (unsigned), version: $(NAME), release $(VERSION), api $(SDKAPI)"
@echo "WARNING: You'll need to sign this application to be able to install it"

clean:
ndk-build ANDROID_FULL_ARCH=$(ANDROID_FULL_ARCH) clean
./mk-luajit.sh clean
rm -rf bin obj libs gen jni/luajit-build local.properties assets/module
24 changes: 24 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@
It contains the project target. It should *NOT* be checked into Version Control Systems. -->
<loadproperties srcFile="project.properties" />

<!-- Override android:versionName and android:versionCode with commandline arguments -->
<target name="-pre-build">
<echo message="Creating a backup of AndroidManifest.xml"/>
<copy file="AndroidManifest.xml" tofile="AndroidManifest.backup" preservelastmodified="false" />
<echo message="Overriding version code from AndroidManifest.xml"/>
<replaceregexp
file="AndroidManifest.xml"
match="android:versionCode(.*)"
replace='android:versionCode="${code}"'/>
<echo message="Overriding version name from AndroidManifest.xml"/>
<replaceregexp
file="AndroidManifest.xml"
match="android:versionName(.*)"
replace='android:versionName="${name}"'/>
</target>

<!-- Restore AndroidManifest.xml to its original state -->
<target name="-post-build">
<echo message="Restoring the AndroidManifest.xml backup"/>
<copy file="AndroidManifest.backup" tofile="AndroidManifest.xml" preservelastmodified="false" />
<delete file="AndroidManifest.backup" />
</target>

<!-- Disable png crunching, because it's incompatible with reproducible builds -->
<target name="-crunch">
<echo message="Skipping png optimization"/>
</target>
Expand Down

0 comments on commit 8fd3ee7

Please sign in to comment.