mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-23 00:00:09 +08:00
refactor!: drop support for android SDK tool (#1083)
* refactor(emulator)!: remove support for legacy `android` binary `emulator.list_images` now always uses the `avdmanager` binary. * refactor(android_sdk)!: remove support for legacy `android` binary `android_sdk.list_targets` now always uses the `avdmanager` binary. * refactor(check_reqs)!: do not look for legacy `android` binary * refactor: replace installation instructions involving `android` binary
This commit is contained in:
committed by
GitHub
parent
2a92c77772
commit
9c3195c1ee
@@ -66,33 +66,6 @@ describe('android_sdk', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('list_targets_with_android', () => {
|
||||
it('should invoke `android` with the `list target` command and _not_ the `list targets` command, as the plural form is not supported in some Android SDK Tools versions', () => {
|
||||
execaSpy.and.returnValue(Promise.resolve({ stdout: '' }));
|
||||
android_sdk.list_targets_with_android();
|
||||
expect(execaSpy).toHaveBeenCalledWith('android', ['list', 'target']);
|
||||
});
|
||||
|
||||
it('should parse and return results from `android list targets` command', () => {
|
||||
const testTargets = fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.2-android_list_targets.txt'), 'utf-8');
|
||||
execaSpy.and.returnValue(Promise.resolve({ stdout: testTargets }));
|
||||
|
||||
return android_sdk.list_targets_with_android().then(list => {
|
||||
['Google Inc.:Google APIs:23',
|
||||
'Google Inc.:Google APIs:22',
|
||||
'Google Inc.:Google APIs:21',
|
||||
'android-25',
|
||||
'android-24',
|
||||
'android-N',
|
||||
'android-23',
|
||||
'android-MNC',
|
||||
'android-22',
|
||||
'android-21',
|
||||
'android-20'].forEach((target) => expect(list).toContain(target));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('list_targets_with_avdmanager', () => {
|
||||
it('should parse and return results from `avdmanager list target` command', () => {
|
||||
const testTargets = fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.3-avdmanager_list_target.txt'), 'utf-8');
|
||||
@@ -111,29 +84,6 @@ describe('android_sdk', () => {
|
||||
expect(avdmanager_spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should parse Android SDK installed target information with `android` command if list_targets_with_avdmanager fails with ENOENT', () => {
|
||||
spyOn(android_sdk, 'list_targets_with_avdmanager').and.returnValue(Promise.reject({ code: 'ENOENT' }));
|
||||
const avdmanager_spy = spyOn(android_sdk, 'list_targets_with_android').and.returnValue(Promise.resolve(['target1']));
|
||||
|
||||
return android_sdk.list_targets().then(targets => {
|
||||
expect(avdmanager_spy).toHaveBeenCalled();
|
||||
expect(targets[0]).toEqual('target1');
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse Android SDK installed target information with `android` command if list_targets_with_avdmanager fails with not-recognized error (Windows)', () => {
|
||||
spyOn(android_sdk, 'list_targets_with_avdmanager').and.returnValue(Promise.reject({
|
||||
code: 1,
|
||||
stderr: "'avdmanager' is not recognized as an internal or external commmand,\r\noperable program or batch file.\r\n"
|
||||
}));
|
||||
|
||||
const avdmanager_spy = spyOn(android_sdk, 'list_targets_with_android').and.returnValue(Promise.resolve(['target1']));
|
||||
return android_sdk.list_targets().then(targets => {
|
||||
expect(avdmanager_spy).toHaveBeenCalled();
|
||||
expect(targets[0]).toEqual('target1');
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw an error if `avdmanager` command fails with an unknown error', () => {
|
||||
const errorMsg = 'Some random error';
|
||||
spyOn(android_sdk, 'list_targets_with_avdmanager').and.returnValue(Promise.reject(errorMsg));
|
||||
|
||||
@@ -100,34 +100,6 @@ describe('check_reqs', function () {
|
||||
return path;
|
||||
});
|
||||
});
|
||||
it('should set ANDROID_SDK_ROOT based on `android` command if command exists in a SDK-like directory structure', () => {
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
spyOn(which, 'sync').and.callFake(function (cmd) {
|
||||
if (cmd === 'android') {
|
||||
return '/android/sdk/tools/android';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return check_reqs.check_android().then(function () {
|
||||
expect(process.env.ANDROID_SDK_ROOT).toEqual('/android/sdk');
|
||||
});
|
||||
});
|
||||
it('should error out if `android` command exists in a non-SDK-like directory structure', () => {
|
||||
spyOn(which, 'sync').and.callFake(function (cmd) {
|
||||
if (cmd === 'android') {
|
||||
return '/just/some/random/path/android';
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
return check_reqs.check_android().then(() => {
|
||||
fail('Expected promise to be rejected');
|
||||
}, err => {
|
||||
expect(err).toEqual(jasmine.any(Error));
|
||||
expect(err.message).toContain('update your PATH to include valid path');
|
||||
});
|
||||
});
|
||||
it('should set ANDROID_SDK_ROOT based on `adb` command if command exists in a SDK-like directory structure', () => {
|
||||
spyOn(fs, 'existsSync').and.returnValue(true);
|
||||
spyOn(which, 'sync').and.callFake(function (cmd) {
|
||||
@@ -398,7 +370,7 @@ describe('check_reqs', function () {
|
||||
fail('Expected promise to be rejected');
|
||||
}, err => {
|
||||
expect(err).toEqual(jasmine.any(Error));
|
||||
expect(err.message).toContain('Please install Android target');
|
||||
expect(err.message).toContain('Please install the Android SDK Platform');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,33 +49,6 @@ describe('emulator', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('list_images_using_android', () => {
|
||||
it('should invoke `android` with the `list avd` command and _not_ the `list avds` command, as the plural form is not supported in some Android SDK Tools versions', () => {
|
||||
const execaSpy = jasmine.createSpy('execa').and.returnValue(Promise.resolve({ stdout: '' }));
|
||||
emu.__set__('execa', execaSpy);
|
||||
|
||||
emu.list_images_using_android();
|
||||
expect(execaSpy).toHaveBeenCalledWith('android', ['list', 'avd']);
|
||||
});
|
||||
|
||||
it('should properly parse details of SDK Tools pre-25.3.1 `android list avd` output', () => {
|
||||
const avdList = fs.readFileSync(path.join('spec', 'fixtures', 'sdk25.2-android_list_avd.txt'), 'utf-8');
|
||||
|
||||
const execaSpy = jasmine.createSpy('execa').and.returnValue(Promise.resolve({ stdout: avdList }));
|
||||
emu.__set__('execa', execaSpy);
|
||||
|
||||
return emu.list_images_using_android().then(list => {
|
||||
expect(list).toBeDefined();
|
||||
expect(list[0].name).toEqual('QWR');
|
||||
expect(list[0].device).toEqual('Nexus 5 (Google)');
|
||||
expect(list[0].path).toEqual('/Users/shazron/.android/avd/QWR.avd');
|
||||
expect(list[0].target).toEqual('Android 7.1.1 (API level 25)');
|
||||
expect(list[0].abi).toEqual('google_apis/x86_64');
|
||||
expect(list[0].skin).toEqual('1080x1920');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('list_images', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(fs, 'realpathSync').and.callFake(cmd => cmd);
|
||||
@@ -91,16 +64,6 @@ describe('emulator', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should delegate to `android` if `avdmanager` cant be found and `android` can', () => {
|
||||
spyOn(which, 'sync').and.callFake(cmd => cmd !== 'avdmanager');
|
||||
|
||||
const android_spy = spyOn(emu, 'list_images_using_android').and.returnValue(Promise.resolve([]));
|
||||
|
||||
return emu.list_images().then(() => {
|
||||
expect(android_spy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should correct api level information and fill in the blanks about api level if exists', () => {
|
||||
spyOn(which, 'sync').and.callFake(cmd => cmd === 'avdmanager');
|
||||
spyOn(emu, 'list_images_using_avdmanager').and.returnValue(Promise.resolve([
|
||||
@@ -132,7 +95,7 @@ describe('emulator', () => {
|
||||
() => fail('Unexpectedly resolved'),
|
||||
err => {
|
||||
expect(err).toBeDefined();
|
||||
expect(err.message).toContain('Could not find either `android` or `avdmanager`');
|
||||
expect(err.message).toContain('Could not find `avdmanager`');
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -252,7 +215,6 @@ describe('emulator', () => {
|
||||
const port = 5555;
|
||||
let emulator;
|
||||
let AdbSpy;
|
||||
let checkReqsSpy;
|
||||
let execaSpy;
|
||||
let whichSpy;
|
||||
|
||||
@@ -269,9 +231,6 @@ describe('emulator', () => {
|
||||
AdbSpy.shell.and.returnValue(Promise.resolve());
|
||||
emu.__set__('Adb', AdbSpy);
|
||||
|
||||
checkReqsSpy = jasmine.createSpyObj('create_reqs', ['getAbsoluteAndroidCmd']);
|
||||
emu.__set__('check_reqs', checkReqsSpy);
|
||||
|
||||
execaSpy = jasmine.createSpy('execa').and.returnValue(
|
||||
jasmine.createSpyObj('spawnFns', ['unref'])
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user