Community Health Toolkit

Issues generating apks from cht-android code base

Describe the Bug
Based on the steps detailed here: Building CHT Android Flavors | Community Health Toolkit, I have not been able to successfully generate an apk.

One of the resources required there is base16 which is a command line tool.
I have installed this GitHub - base16-manager/base16-manager: A command line tool to install base16 templates and set themes globally., but my hunch is it’s not the right tool as it is mainly for templating and not encoding. I have not come across any other base16 tool for the platform I am using.

Thus, I don’t have the actual tool required as this is the error I get;

Makefile:167: *** "No command 'base16' in $PATH". Stop.

See the screenshot below.

How To Reproduce The Issue
Run: make org=new_brand keygen

Environment

  • Client platform: MacOS, BigSur v11.4, M1 Chip
  • IDE: Android Studio
  • Version: 2020.3, build AI-203.7717.56.2031.7678000
  • Device: Redmi Note 9 Pro
  • Version: Android 11

Additional Context
Running make alone, I was able to build and deploy cht-android to my device.

1 Like

Hi @Kymoraa !

Yes, that isn’t the right base16 tool. The right one is part of a package called BaseZ , and in Debian / Ubuntu based Linux distributions you can install it with:

$ sudo apt-get install basez
1 Like

Hello @mrsarm
Thank you for your response.
Can I get BaseZ on OSX or in order to have this running I would need Debian / Ubuntu based Linux distributions?

I am coming across base64, base91

brew install base64
brew install base91

I don’t have OSX, but yes all the tools we use are supported on OSX. For BaseZ, apparently you have to download the source code (http://www.quarkline.net/basez/download/basez-1.6.2.tar.gz), and then follow the instructions at download/README, section COMPILE AND INSTALL GUIDE.

You will need the gcc and the make commands in order to compile the code, but these tools are easily installable with brew.

Okay great. Let me do just that. I will update in case of anything.
Thanks!

Yes please do, we want to be sure all our tools work across different development environments.

Also if you want more details about the sigining process, please take a look to Branding section of the app repo.

Hello @mrsarm
An update on the process so far. I was able to download the source code and install it as per the instructions in the guide you shared.
Running the command again make org=echis_production_go_ke keygen, the BASE16 error is cleared but now I have another error. See the screenshot

Not sure about this first one: head: can't combine line and byte counts

And for the second one,
keytool error: java.lang.Exception: Keystore password must be at least 6 characters

I don’t know why we are getting this error. The password I used to generate my keystore file is 10 characters long. It is the same one set in my environment $ANDROID_KEYSTORE_PASSWORD

Any suggestion on what I could be going wrong?
Thank you

Hey @Kymoraa, your password that you specify with -storepass is indeed < 6 characters (blank in this case). I doubt your ANDROID_KEYSTORE_PASSWORD is set.
Try run the following, just to experiment to check if you get the same error.

keytool -genkey -storepass some_random_password -v -keystore new_brand.keystore -alias medicmobile -keyalg RSA -keysize 2048 -validity 9125

Note the ...-storepass some_random_password....

The issue stems from the head error above, which should set your password, see L168.
For a quick check, running base16 /dev/urandom | head -n 1 -c 16 should get you a 16-character random string that gets passed as the password.

Running base16 /dev/urandom | head -n 1 -c 16 doesn’t generate the 16-character random string which is the expected behaviour.
Instead we still get the error head: can't combine line and byte counts

Which leads me to think the issue with base16 might still be existing… Not sure though

@Kymoraa confirmed that base16 was successfully installed, but stuck with head: can't combine line and byte counts. Unfortunately, I don’t have a Mac. It works smoothly on Ubuntu 20.04.

Thanks @Kymoraa , your feedback is very valuable, we found that one of the command arguments in the Makefile was redundant and incompatible with OSX. The fix was merged, so please pull the latest changes from master and try again.

Thank you @mrsarm and @kitsao
I can confirm that the merged fix done was just what we needed to get past the errors generated from running make org=new_brand keygen

Coming across another error though while executing make keyprint-aab

The *-release.aab file has already been generated and I can find it in the folder build/outputs/bundle -name as required.

Any info on this will be highly appreciated.
Thanks

Is there any deviation between your Makefile and upstream?

The only error i’d expect is this

make keyprint-apk          
Makefile:107: *** "No command 'apksigner' in $PATH".  Stop.

which is fixed by adding apksigner to your path.

Hey @derick
Thanks for your response
There is no deviation between my Makefile and upstream. We rebased against the cht-core master just today in order to pick the merged fixes. It’s actually at par…

I’m able to run make keyprint-apk command after checking out from master… Slightly different command

`

1 Like

@Kymoraa , sorry, that is because the name of the task is wrong here , the right name ends with -bundle, not -aab:

$ make keyprint-bundle

We have created an issue in the cht-android repo to fix and merge the documentation of both the repo and the docs (in the cht-android guides the name of the task is the right one).

1 Like

@derick Yes, make keyprint-apk command works well, it was the last command make keyprint-aab which was failing

@mrsarm This command works make keyprint-bundle
Great. Looking forward to the update on the docs. :grinning:

1 Like