Android-Build
view release on metacpan or search on metacpan
lib/Android/Build.pm view on Meta::CPAN
#!/usr/bin/perl
#-------------------------------------------------------------------------------
# Command line build of an Android apk without resorting to ant or gradle
# Philip R Brenan at gmail dot com, Appa Apps Ltd, 2017
#-------------------------------------------------------------------------------
# perl Build.PL && perl Build test && sudo perl Build install
package Android::Build;
require v5.16.0;
use warnings FATAL => qw(all);
use strict;
use Carp qw(confess);
use Data::Dump qw(dump);
use Data::Table::Text qw(:all);
use File::Copy;
use POSIX qw(strftime); # http://www.cplusplus.com/reference/ctime/strftime/
our $VERSION = '20201115';
#-------------------------------------------------------------------------------
# Constants
#-------------------------------------------------------------------------------
my $home = currentDirectory(); # Home directory
my $permissions = # Default permissions
[qw(INTERNET ACCESS_WIFI_STATE ACCESS_NETWORK_STATE WRITE_EXTERNAL_STORAGE),
qw(READ_EXTERNAL_STORAGE RECEIVE_BOOT_COMPLETED)];
my $version = strftime('%Y%m%d', localtime); # Version number without dots
my $javaTarget = 7; # Java release level to target
#-------------------------------------------------------------------------------
# Private methods
#-------------------------------------------------------------------------------
sub getSDKLevels($) # File name of Android jar for linting
{my ($android) = @_; # Android build
my $l = $android->sdkLevels;
return @$l if $l and @$l;
(15,25)
}
sub getInstructions # How to get the build tools
{<<END
Download the Linux tools as specified at the end of page:
https://developer.android.com/studio/index.html
last set to:
https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
Unzip the retrieved file to get the sdkmanager. Use the sdkmanager to get the
version of the SDK that you need, for example:
sdkmanager 'platforms;android-25' 'build-tools;25.0.3
END
}
sub getPlatform # Get and validate the SDK Platform folder
{my ($a) = @_;
my $f = $a->platformX;
$f or confess <<END.getInstructions;
"platform" parameter required - it should be the name of the folder containing
the android.jar file that you wish to use. You can get this jar file from:
END
-d $f or confess <<END;
Cannot find platformTools folder:
$f
END
$f
}
sub getBuildTools # Get and validate the SDK Platform build-tools folder
{my ($a) = @_;
my $f = $a->buildToolsX;
$f or confess <<END.getInstructions;
"buildTools" parameter required - it should be the name of the folder
containing the Android SDK build tools. You can get these tools from:
END
-d $f or confess <<END;
Cannot find buildTools folder:
$f
END
$f
}
sub getPlatformTools # Get and validate the SDK Platform tools folder
{my ($a) = @_;
my $f = $a->platformToolsX;
$f or confess <<END.getInstructions;
"platformTools" parameter required - it should be the name of the folder
containing the Android SDK platform tools. You can get these tools from:
END
-d $f or confess <<END;
Cannot find platformTools folder:
$f
END
$f
}
sub getDevice($) # Device to be used
{my ($android) = @_;
my $d = $android->device;
return '-e' unless $d;
return $d if $d =~ m(\A-)s;
"-s $d"
}
sub getAndroidJar($) # File name of Android jar for linting
{my ($android) = @_;
my $p = $android->getPlatform;
my $a = filePath($p, qw(android.jar));
-e $a or confess "Cannot find android.jar via file:\n$a\n";
$a
}
sub getPackage # Get and validate the package name for this app
{my ($a) = @_;
my $d = $a->package;
$d or confess <<END =~ s/\n/ /gsr;
"package" parameter required - it should be the value used on the package
statement in the Activity for this app
END
$d =~ /\./ or confess <<END =~ s/\n/ /gsr;
package "$d" should contain at least one '.'
END
$d
}
sub getLintFile # Name of the file to be linted
{my ($a) = @_;
my $f = $a->lintFileX;
$f or confess <<END;
"lintFile" parameter required to lint a file
END
-e $f or confess <<END;
File to be linted does not exist:
$f
END
$f
}
sub getActivity # Activity for app
{my ($a) = @_;
$a->activity // 'Activity';
}
sub getAppName # Single word name of app used to construct file names
{my ($a) = @_;
my $d = $a->getPackage;
(split /\./, $d)[-1];
}
sub getTitle # Title of app
{my ($a) = @_;
$a->title // $a->getAppName;
}
sub apkFileName # Apk name - shorn of path
{my ($a) = @_;
$a->getAppName.'.apk';
}
sub apk # Apk name - with full path
{my ($a) = @_;
$a->getBinFolder.$a->apkFileName;
}
sub getVersion # Version of the app or default to today's date
{my ($a) = @_;
$a->version // $version;
}
sub buildArea($) # Build folder name
{my ($a) = @_;
$a->buildFolder // '/tmp/app/' # Either the user supplied build folder name or the default
}
( run in 2.129 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )