gulp-android
v1.0.0
Published
Android build tools for Gulp.
Downloads
19
Maintainers
Readme
gulp-android
Various tools to enable android compilation from gulp.
Notice: Source is being migrated to a new repository and is temporarily unavailable.
Install
$ npm install --save-dev gulp-android
Usage
const android = require('gulp-android');
const manifest = 'AndroidManifest.xml';
const resources = ['res'];
const libraries = ['lib/**/*.jar'];
gulp.task('resources', function() {
return gulp.src(resources)
.pipe(android.generateResources(manifest))
.pipe(gulp.dest('gen/res'));
});
gulp.task('aidl', function() {
return gulp.src('src/**/*.aidl')
.pipe(android.aidl())
.pipe(gulp.dest('gen/aidl'));
});
gulp.task('jar', ['aidl', 'resources'], function() {
return gulp.src([
'src/**/*.java',
'gen/{res,aidl}/**/*'])
.pipe(android.javac('example.jar')
.addLibrary(libraries)
.addLibrary(android.androidJar))
.pipe(gulp.dest('out/jar'));
});
gulp.task('compile', ['jar'], function() {
return gulp.src(['out/jar/example.jar'].concat(libraries))
.pipe(android.dex())
.pipe(android.package('example.apk', manifest)
.addResources(resources))
.pipe(android.sign())
.pipe(android.zipalign())
.pipe(gulp.dest('out'));
});
gulp.task('continuous', function() {
gulp.watch(resources, 'resources');
gulp.watch('src/**/*.aidl', 'aidl');
});
API
android.aidl([options])
Generates .java files from .aidl files. Input files are expected to be aidl files; directories are ignored. Produces a stream of generated .java files.
options
traceEnabled
Type: boolean
Default: undefined
(Uses module settings)
Sets tracing for this particular step. This overrides the module-level setting.
android.resources(manifest, [options])
Generates an R.java file for resource references. Input files are expected
to be res
folders; files are ignored. Produces a stream of generated .java
files.
Note: This task expects folders, not files. Multiple folders can be specified, but files are ignored. Resource files can not be cherry-picked. If you want to do that, copy the resources you want to a separate directory structure and use that as your source.
manifest
Required
Type: string
Path to the AndroidManifest.xml
file for the project.
options
traceEnabled
Type: boolean
Default: undefined
(Uses module settings)
Sets tracing for this particular step. This overrides the module-level setting.
android.dex([options])
Generates a dex file with supplied code. Expects a stream of .jar
, .zip
, .apk
,
or .class
files. Provides a stream of the resulting .dex
file.
Note: This task will fail if you compile your java files against the wrong version of the JDK. If you see an error like
unsupported class file version 52.0
you will need to modify your java compilation to target a valid version of Java for
Android ("1.7" as of the time of writing). If you are using gulp-javac
, you can
add {javaVersion: '1.7'}
to your javac
task.
options
dexFileName
Type: string
Default: classes.dex
Basename of the generated dex file.
verbose
Type: boolean
Default: false
Provides verbose output from the underlying dx
tool.
traceEnabled
Type: boolean
Default: undefined
(Uses module settings)
Sets tracing for this particular step. This overrides the module-level setting.
android.package(apkName, manifest, [options])
Packages dex files, manifest and resources into an apk file. Expects a stream of
.dex
files. Produces a stream of the resulting .apk
file.
apkName
Required
Type: string
Basename of the apk file to generate.
manifest
Required
Type: string
Path to the AndroidManifest.xml
file for the project.
options
traceEnabled
Type: boolean
Default: undefined
(Uses module settings)
Sets tracing for this particular step. This overrides the module-level setting.
addResources(source)
Adds resource folders to the generated apk.
source
Required
Type: string
or string[]
or readable stream of vinyl files
Libraries to add. If this is a string
or string[]
it is treated as a
glob spec and all files are added. Otherwise all files on the stream are
added. Like in the android.resources
task, these must be folders; individual
files are ignored.
android.sign([options])
Signs the apk. Note that the default options supply the standard debug keystore and debug key.
options
signingToolPath
Type: string
Default: jarsigner on $PATH
If the jarsigner
binary isn't on your $PATH variable, set this to its location.
keystorePath
Type: string
Default: '$HOME/.android/debug.keystore'
The path to the keystore.
keystorePassword
Type: string
Default: 'android'
The password to the keystore.
keyName
Type: string
Default: 'androiddebugkey'
The key to use for signing.
traceEnabled
Type: boolean
Default: undefined
(Uses module settings)
Sets tracing for this particular step. This overrides the module-level setting.
android.zipalign([options])
Zipaligns the apk.
options
traceEnabled
Type: boolean
Default: undefined
(Uses module settings)
Sets tracing for this particular step. This overrides the module-level setting.
android.home
Type: string
Default: $ANDROID_HOME
Sets the android sdk directory location. If tracing is on, this will list the location of the various tool folders it will be using.
android.home.reload()
Reloads the sdk directory folders. This is useful if a new version of the android tools was added during compilation, so that the build picks up this change. Also useful for tracing the tool locations.
android.trace
Type: boolean
Default: false
Module-level flag for tracing. Set to true
to enable trace output. This is useful
when trying to diagnose a problem with compilation, or when developing the library.
When set to true
, this will automatically run android.home.reload()
so that the
sdk directories are reloaded and traced.
License
The MIT License (MIT)
Copyright (c) 2016 Paul Hounshell [email protected]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.