The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Name

Android::Build - Lint, compile, install, run an Android app using the command line tools minus Ant and Gradle thus freeing development effort from the strictures imposed by Android Studio.

Prerequisites

 sudo apt-get install imagemagick zip openjdk-8-jdk
 sudo cpan install Data::Table::Text Data::Dump Carp POSIX File::Copy;

You will need a version of the Android Build Tools as specified right at the end of the page below all the inappropriate advertising for Android Studio.

Download:

  wget https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip

then using the sdkmanager to get the version of the SDK that you want to use, for example:

  sdkmanager --list --verbose

  sdkmanager 'platforms;android-25'  'build-tools;25.0.3' emulator \
   'system-images;android-25;google_apis;x86_64'

Synopsis

 use Android::Build;

 my $a = &Android::Build::new();                                                # Create new builder

 $a->buildTools    = qq(~/Android/sdk/build-tools/25.0.2/);                     # Android SDK Build tools folder
 $a->icon          = qq(~/images/Jets/EEL.jpg);                                 # Image that will be scaled to make an icon using Imagemagick - the English Electric Lightening
 $a->keyAlias      = qq(xxx);                                                   # Alias of key to be used to sign this app
 $a->keyStoreFile  = qq(~/keystore/release-key.keystore);                       # Key store file
 $a->keyStorePwd   = qq(xxx);                                                   # Password for key store file
 $a->package       = qq(com.appaapps.genapp);                                   # Package name containing the activity for this app
 $a->platform      = qq(~/Android/sdk/platforms/android-25/);                   # Android SDK platform folder
 $a->platformTools = qq(~/Android/sdk/platform-tools/);                         # Android SDK platform tools folder
 $a->src           = [q(~/AndroidBuild/SampleApp/src/Activity.java)];           # Source code for the app
 $a->title         = qq(Generic App);                                           # Title of the app as seen under the icon

 $a->run;                                                                       # Build, install and run the app on the only emulator

Modify the code above to reflect your local environment, then start an emulator and run the modified code to compile your app and load it into the emulator.

Sample App

A sample app is included in folder:

 ./SampleApp

Modify the values in

 ./SampleApp/perl/makeWithPerl.pl

to reflect your local environment, then start an emulator and run:

 perl ./SampleApp/perl/makeWithPerl.pl

to compile the sample app and load it into the running emulator.

Signing key

If you do not already have a signing key, you can create one with the supplied script:

 ./SampleApp/perl/generateAKey.pl

Description

Lint, compile, install, run an Android app using the command line tools minus Ant and Gradle thus freeing development effort from the strictures imposed by Android Studio.

The following sections describe the methods in each functional area of this module. For an alphabetic listing of all methods by name see Index.

Methods and attributes

new()

Create a new build.

This is a static method and so should be invoked as:

  Android::Build::new

activity :lvalue

Activity name: default is Activity. The name of the activity to start on your android device: device is package/Activity

assets :lvalue

A hash containing your assets folder (if any). Each key is the file name in the assets folder, each corresponding value is the data for that file. The keys of this hash may contain / to create sub folders.

buildTools :lvalue

Name of the folder containing the build tools to be used to build the app, see prerequisites

buildFolder :lvalue

Name of a folder in which to build the app, The default is /tmp/app/

classes :lvalue

A folder containing precompiled java classes and jar files that you wish to lint against.

debug :lvalue

The app will be debuggable if this option is true.

device :lvalue

Device to run on, default is the only emulator or specify '-d', '-e', or '-s SERIAL' per adb

fastIcons :lvalue

Create icons in parallel if true - the default is to create them serially which takes more elapsed time.

icon :lvalue

Jpg file containing a picture that will be converted and scaled by ImageMagick to make an icon for the app, default is icon.jpg in the current directory.

keyAlias :lvalue

Alias of the key in your key store file which will be used to sign this app. See Signing key for how to generate a key.

keyStoreFile :lvalue

Name of your key store file. See Signing key for how to generate a key.

keyStorePwd :lvalue

Password of your key store file. See Signing key for how to generate a key.

libs :lvalue

A reference to an array of jar files to be copied into the app build to be used as libraries.

lintFile :lvalue

A file to be linted with the lint action using the android platform and the classes specified.

log :lvalue

Output: a reference to an array of messages showing all the non fatal errors produced by this running this build. To catch fatal error enclose build with eval{}

package :lvalue

The package name used in the manifest file to identify the app. The java file containing the activity for this app should use this package name on its package statement.

parameters :lvalue

Optional parameter string to be placed in folder: res as a string accessible via: R.string.parameters from within the app. Alternatively, if this is a reference to a hash, strings are created for each hash key=value

permissions :lvalue

A reference to an array of permissions, a standard useful set is applied by default if none are specified.

platform :lvalue

Folder containing android.jar. For example ~/Android/sdk/platforms/25.0.2

platformTools :lvalue

Folder containing adb

sdkLevels :lvalue

[minSdkVersion, targetSdkVersion], default is [15, 25]

src :lvalue

A reference to an array of java source files to be compiled to create this app.

title :lvalue

Title of app, the default is the package name of the app.

titles :lvalue

A hash of translated titles: {ISO::639 2 digit language code=>title in that language}* for this app.

verifyApk :lvalue

Verify the signed apk if this is true.

version :lvalue

The version number of the app. Default is today's date, formatted as YYYYMMDD

compile($)

Compile the app.

     Parameter  Description    
  1  $android   Android build  

cloneApk($$)

Clone an apk file: copy the existing apk, replace the assets, re-sign, zipalign, return the name of the newly created apk file.

     Parameter  Description                            
  1  $android   Android build                          
  2  $oldApk    The file name of the apk to be cloned  

lint($)

Lint all the Java source code files for the app.

     Parameter  Description    
  1  $android   Android build  

install($)

Install an already compiled app on to the selected device

     Parameter  Description    
  1  $android   Android build  

run($)

Compile the app, install and then run it on the selected device

     Parameter  Description    
  1  $android   Android build  

Index

1 activity

2 assets

3 buildFolder

4 buildTools

5 classes

6 cloneApk

7 compile

8 debug

9 device

10 fastIcons

11 icon

12 install

13 keyAlias

14 keyStoreFile

15 keyStorePwd

16 libs

17 lint

18 lintFile

19 log

20 new

21 package

22 parameters

23 permissions

24 platform

25 platformTools

26 run

27 sdkLevels

28 src

29 title

30 titles

31 verifyApk

32 version

Installation

This module is written in 100% Pure Perl and, thus, it is easy to read, comprehend, use, modify and install via cpan:

  sudo cpan install Android::Build

Author

philiprbrenan@gmail.com

http://www.appaapps.com

Copyright

Copyright (c) 2016-2018 Philip R Brenan.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself.