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;
You will need a version of the 𝗔𝗻𝗱𝗿𝗼𝗶𝗱 build tools. You can get these tools by first downloading:
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
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->buildTools = qq(/home/phil/Android/sdk/build-tools/25.0.2/); # Android SDK Build tools folder
$a->icon = qq(/home/phil/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(/home/phil/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(/home/phil/Android/sdk/platforms/android-25/); # Android SDK platform folder
$a->platformTools = qq(/home/phil/Android/sdk/platform-tools/); # Android SDK platform tools folder
$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 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 𝗔𝗻𝗱𝗿𝗼𝗶𝗱 build description is in file:
/somewhere/$folder/perl/makeWithPerl.pl
then by default the Java source and libraries (jar files) for your app should be in:
/somewhere/$folder/src/*.java
/somewhere/$folder/libs/*.jar
These files will be copied into 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 any other files into the 𝗯𝘂𝗶𝗹𝗱𝗙𝗼𝗹𝗱𝗲𝗿.
Actions
The following actions are available:
compile
To compile your app:
$android->compile
lint
To lint a file in your app:
$android->lintFile = ...
$android->lint
Set the file to be linted with "lintFile". You can add a folder of precompiled classes to the lint with "classes". 𝗮𝗻𝗱𝗿𝗼𝗶𝗱.𝗷𝗮𝗿 will also be added to the lint class path.
install
To install and already compiled app on the selected "device":
$android->install
run
As described in "Synopsis"
$android->run
will compile your app and if the compile is successful, install it on the selected "device" and run it.
Parameters
You can customise your build by assigning to or reading from the following methods:
activity
Activity name, default is '
Activity
The name of the class to start on the "device" is the concatenation of:
package . '/.'. activity
buildTools
Name of the folder containing the build tools to be used to build the app. See "Prerequisites"
buildFolder
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.
classes
A folder containing precompiled java classes that you wish to "lint" against.
copyFiles
𝘀𝘂𝗯 {} to copy additional files into the app before it is complied
debug
Make the app debuggable if specified and true.
device
Device to run on, default is the only emulator.
icon
A file containing a picture that will be converted and scaled using 𝗜𝗺𝗮𝗴𝗲𝗺𝗮𝗴𝗶𝗰𝗸 to make an icon for the app, default is:
icon.jpg
keyAlias
Alias used in the java keytool to name the key to be used to sign this app. See "Synopsis" for how to generate a key.
keyStoreFile
Name of key store file. See "Synopsis" for how to generate a key.
keyStorePwd
Password of key store file. See "Synopsis" for how to generate a key.
log
Output: message log showing all the none fatal errors produced by this running this build. To catch fatal error enclose with 𝗲𝘃𝗮𝗹 {}
libs
Extra libraries (jar files) to be copied into the app build. See also: "CopyFiles"
lintFile
A file to be linted with the "lint" action using the 𝗮𝗻𝗱𝗿𝗼𝗶𝗱.𝗷𝗮𝗿 and "classes" specified.
package
The value of the package statement in the java file containing the 𝗔𝗰𝘁𝗶𝘃𝗶𝘁𝘆 class for this app. This is the 𝗔𝗰𝘁𝗶𝘃𝗶𝘁𝘆 that will be started to run the app
platform
The name of the folder containing the 𝗮𝗻𝗱𝗿𝗼𝗶𝗱.𝗷𝗮𝗿 you wish to use. See the notes in "Prerequisites"
platformTools
The name of the folder containing the 𝗔𝗻𝗱𝗿𝗼𝗶𝗱.𝗷𝗮𝗿 you wish to use. See the notes in "Prerequisites"
parameters
Optional: Parameter string to be placed in folder: 𝗿𝗲𝘀 as a string accessible via:
R.string.parameters
from within the app.
permissions
Permissions for the app. A standard useful set is supplied by default if none are provided.
sdkLevels
The sdk levels to be declared for the app in the form:
[minSdkVersion,targetSdkVersion],
The 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
Title of app, default is the last word of the package name. This title will appear below the app icon on the 𝗔𝗻𝗱𝗿𝗼𝗶𝗱 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.