Name

Android::Build - Lint, compile, install, start an Android App using the command line tools minus ant and gradle.

Prerequisites

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

And a version of the Android Software Development Kit.

Synopsis

This file which can be found in the tar.gz file containing this module:

SampleApp/perl/makeWithperl.pl

contains:

use Android::Build;

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

$a->sdk          = qq(/home/phil/Android/sdk/);            # Android SDK on the local machine
$a->buildTools   = $a->sdk."build-tools/25.0.2/";          # Build tools folder
$a->name         = qq(Genapp);                             # Name of the app, this value will be lower cased and appended to the domain name to form the package name
$a->title        = qq(Generic App);                        # Title of the app as seen under the icon
$a->domain       = qq(com.appaapps);                       # Domain name in reverse order
$a->icon         = "$home/images/Jets/EEL.jpg";            # English Electric Lightning: image that will be scaled to make an icon using Imagemagick
$a->keyAlias     = qq(xxx);                                # Alias of key to be used to sign this app
$a->keyStoreFile = "$home/keystore/release-key.keystore";  # Key store file
$a->keyStorePwd  = qq(xxx);                                # Password for key store file

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

Modify the values above to reflect your local environment, then start an emulator and run:

cd SampleApp/perl/ && perl makeWithPerl.pl

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

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

SampleApp/perl/generateAKey.pl

File layout

A sample file layout is included in folder:

SampleApp/

If your Android build description is in file:

/somewhere/$folder/perl/makeWithPerl.pl

then the Java source and libs for your app should be in:

/somewhere/$folder/src/*.java
/somewhere/$folder/libs/*.jar

and the java package name for your app should be:

package $domain.$folder

where:

$domain

is your reversed domain name written in lowercase. Executing:

use Android::Build;

my $a = &Android::Build::new();
...
$a->build(qw(run));

from folder:

SampleApp/perl/

will copy the files in the 𝘀𝗿𝗰 and 𝗹𝗶𝗯𝘀 folders to the 𝗯𝘂𝗶𝗹𝗱𝗙𝗼𝗹𝗱𝗲𝗿 before starting the build of your app.

If this does not meet your requirements, then provide a 𝘀𝘂𝗯

$a->copyFiles = sub ...

which will be called just before the build begins to allow you to copy into the 𝗯𝘂𝗶𝗹𝗱𝗙𝗼𝗹𝗱𝗲𝗿 any other files needed to build your app.

Parameters

You can customize your build by assigning to or reading from the following methods:

activity

Optional: Activity name, default is 'Activity'. The name of the class to start on the emulator is the concatenation of:

$domain. lc($name). '/.'. $activity

buildTools

REQUIRED: Name of the folder containing the build tools to be used to build the app

buildFolder

Optional: Name of a folder in which to build the app. The default is ../tmp

This folder will be cleared (without warning) before the app is built.

copyFiles

Optional: Sub to copy additional files into the app before it is complied

debug

Optional: Make the app debuggable if specified and true

device

Optional: Device to run on, default is the only emulator

domain

REQUIRED: Domain name for app. The name of the class to start on the emulator is the concatenation of:

$domain. lc($name). '/.'. $activity

icon

Optional: Jpg file containing a picture that will be scaled using Imagemagick to make an icon for the app, default is 'icon.jpg'

keyAlias

REQUIRED: alias used in keytool to name the key to be used to sign this app

keyStoreFile

REQUIRED: name of key store file

keyStorePwd

REQUIRED: password of key store file

log

Output: message log

libs

Optional: extra libraries

name

Optional: One word name for the app, default is the name of the folder containing the current folder. This name will be lower cased and added to the domain name to form the name of the package to be started to run the app. If the package name so constructed does not match any package statement in any of your java files then your app will not start as expected.

The name of the class to start on the emulator is the concatenation of:

$domain. lc($name). '/.'. $activity

The apk for the generated app will be:

$name.'.apk'

parameters

Optional: Parameter string to be placed in folder: 𝗿𝗲𝘀 as a string accessible via:

R.string.parameters

permissions

Optional: Permissions for the app. A standard useful set is supplied by default if none are provided.

sdk

REQUIRED: Folder containing Android sdk. This information is used in conjunction with parameter: 𝘀𝗱𝗸𝗟𝗲𝘃𝗲𝗹𝘀 to find the right Android.jar and to access the platform tools folder.

sdkLevels

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

src

Optional: Source of app, default is everything in the '../src' folder.

The source files do not have to be positioned within the domain name hierarchy, you can for instance have all your source files at the root of source directory or anywhere below it if that is more convenient. This module compiles all java files found under the source directory plus any others that have been copied into the app 𝗯𝘂𝗶𝗹𝗱𝗙𝗼𝗹𝗱𝗲𝗿 by the 𝗰𝗼𝗽𝘆𝗳𝗶𝗹𝗲 option. The only requirements is that each java file use a package statement to declare its final position in the domain name hierarchy.

title

Optional: Title of app, default is the name of app, This title will appear below the app icon on the Android device display.

version

Optional: Version of app, default is today's date

Installation

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) 2017 Philip R Brenan.

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