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:

  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 'platforms;android-25'  'build-tools;25.0.3

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

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 default build

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

  Android::Build::new

activity :lvalue

Activity name, default is Activity this the name of the activity to start on the device is package/activity

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

classes :lvalue

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

debug :lvalue

Make the app 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 qx(man adb)

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

keyAlias :lvalue

Alias used in the java keytool to name the key to be used to sign this app. See Signing key for how to generate a key.

keyStoreFile :lvalue

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

keyStorePwd :lvalue

Password of 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 buildwith 𝗲𝘃𝗮𝗹 {}

package :lvalue

The package name to be used in the manifest and to start the app - the file containing the activity for the app should be in this package

parameters :lvalue

Optional parameter string to be placed in folder: res as a string accessible via: R.string.parameters from within the app.

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 name of app

version :lvalue

Version of app, default is today's date

compile($)

Compile the app

  1  $android  Android build

lint($)

Lint all the source code java files for the app

  1  $android  Android build

install($)

Install an already compiled app on the selected device:

  1  $android  Android build

run($)

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

  1  $android  Android build

Index

1 activity

2 buildFolder

3 buildTools

4 classes

5 compile

6 debug

7 device

8 icon

9 install

10 keyAlias

11 keyStoreFile

12 keyStorePwd

13 libs

14 lint

15 lintFile

16 log

17 new

18 package

19 parameters

20 permissions

21 platform

22 platformTools

23 run

24 sdkLevels

25 src

26 title

27 version

Installation

This module is written in 100% Pure Perl and, thus, it is easy to read, use, modify and install.

Standard Module::Build process for building and installing modules:

  perl Build.PL
  ./Build
  ./Build test
  ./Build install

Author

philiprbrenan@gmail.com

http://www.appaapps.com

Copyright

Copyright (c) 2016-2017 Philip R Brenan.

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