API Development

How to Use Modules from GitHub

Guest poster, Michael Gangolf, has been using Titanium since 2010, been a Titan since 2017 and Android lover since the beginning. You can follow him at @michaelgangolf or on Github at https://github.com/m1ga.

Every now and then, you need to use an external module in your app to access things that don’t exist in the native Appcelerator SDK, e.g. a barcode scanner like Ti.Barcode. Many of these plug-ins are open source and can be found at GitHub or on gitTio (https://gitt.io/).

gitTio is a CLI tool to install modules, originally developed by Fokke Zandbergen (https://fokkezb.nl/). Have a look at https://gitt.io/cli on how to use this tool to install modules.

This tutorial will focus on the manual install using the GitHub repository. Depending on the author of the module there are different places you will find the binary you need to include in your app.

Release tab

The first place to look is at the “Release” tab:

If you see a number next to “releases,” there are multiple binaries uploaded in the repository.

For Ti.Barcode, you can see all the releases for iOS and Android:
https://github.com/appcelerator-modules/ti.barcode/releases

You just search for the latest for your OS and download the binary ZIP (not the source!). This binary can be placed in your app folder or your global module folder.

Dist folder

If you can’t find anything in the release tab, the next place to look is the distribution folder of the module. When you compile a module, it will be placed in a folder called “dist/”. You can find this under “module/android/dist” or “module/ios/dist”. For example, the push module Ti.Goosh by Caffeina (https://github.com/caffeinalab/ti.goosh) is using that folder:
https://github.com/caffeinalab/ti.goosh/tree/master/android/dist

Again, you download the ZIP file and place it into your project.

Pull requests or fork

The last place to look is the “Pull request (PR)” menu or the module forks. During the update from Titanium SDK 6 to 7, you needed to update your Android modules. Some module owners aren’t active anymore or don’t have time to update these modules themselves. Luckily, some Appcelerator users fork those modules and create compatible versions or even add new features. When the repository is not active anymore, those updates won’t be included in the official page, but you still can use those new modules.

A module for Android called Ti-Android-CameraView by Michael Browne (https://github.com/brownemint/Ti-Android-CameraView) is currently not available for Titanium SDK 7. But, there is a PR that adds compatibility and some bug fixes inside the PR section:
https://github.com/brownemint/Ti-Android-CameraView/pulls

If you click on this PR, you will see a list of the changes and a tab with “Files changed”. There you will get a whole list of files, and you search for a new file in the dist folder. In this PR, it is called  “dist/pw.custom.androidcamera-android-1.0.1.zip”. You can click the “View” button on the right side and download the ZIP from there.

Another way to get to the file is to have a look at the forks. To do this, you need to click on “Insights – Network” and you will get a graph with all forks. Most of the time, it is the latest in the graph and you can click on that dot to go to the repository:

Compile it

If you can’t find any binary inside the repository, you have to compile the module yourself or ask in TiSlack if someone can help out. To compile the module, you can clone the repository with

     git clone https://github…./module-name

 

and then look at the official guides at https://docs.axway.com/bundle/Titanium_SDK_allOS_en/page/extending_titanium_mobile.html for how to compile modules. If you have everything setup correctly, it is most of the time just a simple

     appc run -p ios --build-only

 

or

     appc run -p android --build-only

 

The binary will be inside the “dist/” folder.