Skip to content

Build and publish a custom app locally (without travis)

Matthieu Gautier edited this page Jul 19, 2018 · 6 revisions

The simpler way to build and publish a custom app is to use build-custom-app script that uses travis to launch all the jobs. This page describes how to use it.

However, if you want to compile a custom app on your computer and publish it yourselves, this documentation is for you.

This documentation will assume you want to build a wikimed custom app.

First of all, we assume you have a kiwix-build repository checkout out. All command will be launched with this directory as current working directory. You also need to have all dependencies of kiwix-build installed.

Get zim file

To build the apks, you need to know the size of the zim file. As we will also need the zim file itself at the end to upload it to the play store, let's download it first. You can download it wherever you want, but you will need the zim file at the end of the process to upload it. We assume here that we just download it in the current directory.

The exact zim file to use is up to you but you will probably want to get the default zim file associated to the customapp. (As build-custom-app does). The default zim is specified in the info.json file in the custom-android-app repository. For wikimed (), the url is https://download.kiwix.org/zim/wikipedia_en_medicine_novid.zim.

So let's download it : wget https://download.kiwix.org/zim/wikipedia_en_medicine_novid.zim

Then we will need its size : stat -c %s wikipedia_en_medicine_novid.zim For me, the size is 1177575831, but it may change depending of the actual version of the zim version you have downloaded.

You can set the ZIM_SIZE variable with ZIM_SIZE=$(stat -c %s wikipedia_en_medicine_novid.zim)

Be sure, that the zim size is lesser than 2Go.

Build custom app apk.

We will need to build a apk per android architecture. So we need to launch kiwix-build six times.

Each apk need a specific VERSION_CODE and this version code depends on the actual date and the architecture of the apk. Its format is "AYYDDDX" where:

  • A is the index of the platform.
  • YY is the current year (17 for 2017)
  • DDD is the current day of the year (number of days since start of the year)
  • X is a extra number (starts at 0 and you must increment it you build and publish several times in the day)

The index of the platform is given with this table :

Architecture index
arm 0
arm64 1
x86 2
x86_64 3
mips 4
mips_64 5

The YYDD can be found with : date +%y%j

So a VERSION_CODE for a arm build the Juillet 17th of 2017 with extra code of 0 will be 171980 For an arm64 build it will be 1171980, for a x86 it will be 2171980 and so forth.

Now we have the VERSION_CODEs to use, we can launch kiwix-build.

We will also need a CONTENT_VERSION_CODE to version the companion file (the zim file). The default CONTENT_VERSION_CODE is the same of the VERSION_CODE for arm (so 171980) As it is common to all apks we can set it as environment variable : export CONTENT_VERSION_CODE=171980

Last, we also need a VERSION_NAME. The version name is the version seen by the user. For wikimed, we use to have a version using the format "YYYY-MM", so, it should be something like "2017-07" : export VERSION_NAME="2017-07"

For android-arm :
VERSION_CODE=171980 kiwix-build --target-platform android --android-arch arm --android-custom-app wikimed --zim-file-size $ZIM_SIZE kiwix-android-custom

For android-arm64 :
VERSION_CODE=1171980 kiwix-build --target-platform android --android-arch arm64 --android-custom-app wikimed --zim-file-size $ZIM_SIZE kiwix-android-custom

For x86 :
VERSION_CODE=2171980 kiwix-build --target-platform android --android-arch x86 --android-custom-app wikimed --zim-file-size $ZIM_SIZE kiwix-android-custom

For x86_64 :
VERSION_CODE=3171980 kiwix-build --target-platform android --android-arch x86_64 --android-custom-app wikimed --zim-file-size $ZIM_SIZE kiwix-android-custom

For mips :
VERSION_CODE=4171980 kiwix-build --target-platform android --android-arch mips --android-custom-app wikimed --zim-file-size $ZIM_SIZE kiwix-android-custom

For mips_64 :
VERSION_CODE=5171980 kiwix-build --target-platform android --android-arch mips64 --android-custom-app wikimed --zim-file-size $ZIM_SIZE kiwix-android-custom

Now, we have all apks in directories BUILD_android/kiwix-android-custom_wikimed/app/build/outputs/apk/wikimed/release/app-wikimed-release-unsigned.apk

Sign release apks.

Now that all apks have been generated, we need to sign them before uploading them to google play console.

You should have a valid keystore to sign kiwix-custom apps. If you don't, contact us. We will assume that the environment variable KEYSTORE_FILE points to the keystore.

We will store signed apk in signed_apks direrectory : mkdir signed_apks

And now, lets sign all apks:

  • ./TOOLCHAINS/android-sdk-r25.2.3/build-tools/25.0.2/apksigner sign -ks $KEYSTORE_FILE --out signed_apks/app-wikimed_171980-release-signed.apk BUILD_android_arm/kiwix-android-custom_wikimed/app/build/outputs/apk/app-wikimed-release-unsigned.apk
  • ./TOOLCHAINS/android-sdk-r25.2.3/build-tools/25.0.2/apksigner sign -ks $KEYSTORE_FILE --out signed_apks/app-wikimed_1171980-release-signed.apk BUILD_android_arm64/kiwix-android-custom_wikimed/app/build/outputs/apk/app-wikimed-release-unsigned.apk
  • ./TOOLCHAINS/android-sdk-r25.2.3/build-tools/25.0.2/apksigner sign -ks $KEYSTORE_FILE --out signed_apks/app-wikimed_2171980-release-signed.apk BUILD_android_x86/kiwix-android-custom_wikimed/app/build/outputs/apk/app-wikimed-release-unsigned.apk
  • ./TOOLCHAINS/android-sdk-r25.2.3/build-tools/25.0.2/apksigner sign -ks $KEYSTORE_FILE --out signed_apks/app-wikimed_3171980-release-signed.apk BUILD_android_x86_64/kiwix-android-custom_wikimed/app/build/outputs/apk/app-wikimed-release-unsigned.apk
  • ./TOOLCHAINS/android-sdk-r25.2.3/build-tools/25.0.2/apksigner sign -ks $KEYSTORE_FILE --out signed_apks/app-wikimed_4171980-release-signed.apk BUILD_android_mips/kiwix-android-custom_wikimed/app/build/outputs/apk/app-wikimed-release-unsigned.apk
  • ./TOOLCHAINS/android-sdk-r25.2.3/build-tools/25.0.2/apksigner sign -ks $KEYSTORE_FILE --out signed_apks/app-wikimed_5171980-release-signed.apk BUILD_android_mips64/kiwix-android-custom_wikimed/app/build/outputs/apk/app-wikimed-release-unsigned.apk

Upload apks

Now, we can upload the apks to google play console.

You should have a valid google-api key to publish apk on kiwix account. If you don't, contact us. We will assume that the environment variable GOOGLE_API_KEY points to the key. The wikipedia_en_medicine_novid.zim is the path to the zim file we've downloaded at the beginning.

./build_custom_app.py --step publish --custom-app wikimed --google-api-key $GOOGLE_API_KEY --zim-path wikipedia_en_medicine_novid.zim --apks-dir signed_apks --content-version-code $CONTENT_VERSION_CODE