Bahmni Connect: How to build the APK?

Hi guys!

As I am encountering memory issues with Bahmni Connect as a Chrome App, I would like to try it when shipped as APK.

So I was wondering what are steps to package Bahmni Connect as APK for Android.

Do these steps https://bahmni.atlassian.net/wiki/spaces/BAH/pages/46432277/Bahmni+Connect+Development are for building the APK?

Or should I follow the readme file from here: https://github.com/Bahmni/bahmni-offline

I don’t really want develop on the Android app yet, but simply want to build the APK to give it a try, so if I could avoid having to install the Andoird SDK and all, that would be the best.

Hi @mksrom , you would actually need to follow both the links to compile the android app and I’m afraid you would need the SDK tools for it. To compile the app I followed these steps:

  1. Follow these steps as it is : https://bahmni.atlassian.net/wiki/spaces/BAH/pages/46432277/Bahmni+Connect+Development

  2. From this https://github.com/Bahmni/bahmni-offline , first follow the Steps 1-5. I am using Cordova version 6.4.0 where I havent encountered any problems.Also download Android Studio instead of the Intellij plugin.

  3. Copy dist folder of bahmni-connect/ui folder to bahmni-offline/android/www/ and rename the dist folder as app.

  4. cd bahmni-offline/android

  5. cordova platform remove android

  6. cordova platform add android

  7. git checkout .

  8. cordova build android or cordova run android --device to build and deploy to an android device

3 Likes

Thanks a lot for the steps.

About this:

Do we have to connect the device in order to install the app, or can it be shipped, downloaded and installed separately on each tablet (I have no physical access the our devices)

You can run the build command and it will the generate the .apk file in bahmni-offline/android/platforms/android

Or just add the project to Android Studio and generate the .apk file. For the run command you would need a device connected to your machine

@krishnanspace, which one is the build command? cordova build android ?

1 Like

Thats the one

1 Like

OK that works. Thanks!

I have encounterd few issues though.

1/

When running

cordova build android

I got the following error:

Error: ENOENT: no such file or directory, open '/home/romain/repos/bahmni-offline/android/platforms/android/res/xml/config.xml

Full error log:

cp: copyFileSync: could not write to dest file (code=ENOENT):/home/romain/repos/bahmni-offline/android/platforms/android/res/xml/config.xml

Parsing /home/romain/repos/bahmni-offline/android/platforms/android/res/xml/config.xml failed
(node:20851) UnhandledPromiseRejectionWarning: ``Error: ENOENT: no such file or directory, open '/home/romain/repos/bahmni-offline/android/platforms/android/res/xml/config.xml`'`
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:348:35)
    at Object.parseElementtreeSync (/home/romain/repos/bahmni-offline/android/platforms/android/cordova/node_modules/cordova-common/src/util/xml-helpers.js:180:27)
    at new ConfigParser (/home/romain/repos/bahmni-offline/android/platforms/android/cordova/node_modules/cordova-common/src/ConfigParser/ConfigParser.js:30:24)
    at updateConfigFilesFrom (/home/romain/repos/bahmni-offline/android/platforms/android/cordova/lib/prepare.js:106:18)
    at Api.module.exports.prepare (/home/romain/repos/bahmni-offline/android/platforms/android/cordova/lib/prepare.js:42:20)
    at Api.prepare (/home/romain/repos/bahmni-offline/android/platforms/android/cordova/Api.js:192:45)
    at /usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/prepare.js:106:36
    at _fulfilled (/usr/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:787:54)
    at /usr/lib/node_modules/cordova/node_modules/cordova-lib/node_modules/q/q.js:816:30
(node:20851) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:20851) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

This was solved by building the adding the platform android 6.4.0

# remove the previous one
cordova platform remove android

# add it with a specified version
cordova platform add android@6.4.0

2/

Another error came up when building with Cordova related to accepting the Andoird SDK licences:

License for package Android SDK Platform 26 not accepted

Full error log:

Running command: /home/romain/repos/bahmni-offline/android/hooks/after_prepare/010_add_platform_class.js /home/romain/repos/bahmni-offline/android
add to body class: platform-android
ANDROID_HOME=/home/romain/Android/Sdk/
JAVA_HOME=/usr/lib/jvm/java-8-oracle
Subproject Path: CordovaLib
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
	at build_21k9ntgdmxn3yddljog91eh80.run(/home/romain/repos/bahmni-offline/android/platforms/android/build.gradle:141)
Checking the license for package Android SDK Platform 26 in /home/romain/Android/Sdk/licenses
Warning: License for package Android SDK Platform 26 not accepted.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Platform 26].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
(node:21783) UnhandledPromiseRejectionWarning: Error: /home/romain/repos/bahmni-offline/android/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Platform 26].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html

Solved by following this:

Accept licences with this command:

$ANDROID_HOME/tools/bin/sdkmanager --licenses
1 Like

@krishnanspace, one more thing! :slight_smile:

The APK file is named android-debug.apk

Why is this a debug APK?

Any idea how I could get a non-debug one?

Add the Gradle project to Android Studio and Generate a Signed Apk