[android] update

This commit is contained in:
2018-05-10 17:56:39 +03:00
parent 4ed7fb3a02
commit 25913a8f42
3 changed files with 43 additions and 29 deletions

View File

@@ -1,4 +1,5 @@
const fs = require('fs');
const path = require('path');
const exec = require('./exec');
const through = require('through2');
const Sdk = require('./sdk');
@@ -22,24 +23,27 @@ class Android extends Sdk {
get link() {
const system = Sdk.System.isWindows ? 'windows' : Sdk.System.isLinux ? 'linux' : null;
if (!system) throw 'Unsupported system';
//return `https://dl.google.com/android/repository/sdk-tools-${system}-${this.version}.zip`;
return `https://dl.google.com/android/repository/tools_r${this.version}-${system}.zip`;
if (this.version.indexOf('.') === -1) {
return `https://dl.google.com/android/repository/tools_r${this.version}-${system}.zip`;
} else {
return `https://dl.google.com/android/repository/sdk-tools-${system}-${this.version}.zip`;
}
}
get android_home() {
return this.path;
}
get ndk_home() {
return path.join(this.path, 'ndk-bundle')
}
prepare() {
return this.prepared ? Promise.resolve() : super.prepare(0).then(() => {
return this.sdkmanager([
'ndk-bundle',
'tools',
'platform-tools',
'build-tools;27.0.3',
'platforms;android-27',
]);
});
return super.prepare(0);
}
sdkmanager(packages) {
const androidBin = `${this.path}/tools/bin/sdkmanager`;
const androidBin = path.join(this.path, 'tools/bin/sdkmanager');
if (fs.existsSync(androidBin)) {
fs.chmodSync(androidBin, 0o755);
}
@@ -48,11 +52,13 @@ class Android extends Sdk {
}
activate() {
Env.set('ANDROID_HOME', this.path);
Env.set('ANDROID_HOME', this.android_home);
Env.set('ANDROID_NDK_HOME', this.ndk_home);
Env.set('NDK_HOME', this.ndk_home);
}
adb(args) {
const adbBin = `${this.path}/platform-tools/adb`;
const adbBin = path.join(this.path, 'platform-tools/adb');
return exec('.', [adbBin].concat(args).join(' ')).then(data => {
for (let line of data.stderr.split('\n')) {
if (line.indexOf('Error') > -1) {
@@ -64,10 +70,10 @@ class Android extends Sdk {
aapt(args) {
let buildToolsVersion = null;
fs.readdirSync(`${this.path}/build-tools`).forEach(file => {
fs.readdirSync(path.join(this.path, 'build-tools')).forEach(file => {
buildToolsVersion = file;
});
const aaptBin = `${this.path}/build-tools/${buildToolsVersion}/aapt`;
const aaptBin = path.join(this.path, 'build-tools', buildToolsVersion, 'aapt');
return exec('.', [aaptBin].concat(args).join(' '));
}
@@ -122,6 +128,6 @@ Android.ID = 'android';
Android.VERSION_25_2_3 = '25.2.3';
Android.VERSION_3859397 = '3859397';
Android.VERSION = Android.VERSION_25_2_3;
Android.VERSION = Android.VERSION_3859397;
module.exports = Android;