mirror of
https://github.com/apache/cordova-android.git
synced 2025-04-27 04:10:11 +08:00
CB-12981: handle SDK 26.0.2 slightly different AVD list output for Android 8+ AVDs. Would cause "cannot read property replace of undefined" errors when trying to deploy an Android 8 emulator.
This commit is contained in:
parent
03144eb160
commit
1637937664
15
bin/templates/cordova/lib/emulator.js
vendored
15
bin/templates/cordova/lib/emulator.js
vendored
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
/* jshint sub:true */
|
/* jshint sub:true */
|
||||||
|
|
||||||
|
var android_versions = require('android-versions');
|
||||||
var retry = require('./retry');
|
var retry = require('./retry');
|
||||||
var build = require('./build');
|
var build = require('./build');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
@ -169,6 +170,7 @@ module.exports.list_images_using_android = function () {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
module.exports.list_images = function () {
|
module.exports.list_images = function () {
|
||||||
|
return Q.fcall(function () {
|
||||||
if (forgivingWhichSync('avdmanager')) {
|
if (forgivingWhichSync('avdmanager')) {
|
||||||
return module.exports.list_images_using_avdmanager();
|
return module.exports.list_images_using_avdmanager();
|
||||||
} else if (forgivingWhichSync('android')) {
|
} else if (forgivingWhichSync('android')) {
|
||||||
@ -178,6 +180,19 @@ module.exports.list_images = function () {
|
|||||||
throw new CordovaError('Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?');
|
throw new CordovaError('Could not find either `android` or `avdmanager` on your $PATH! Are you sure the Android SDK is installed and available?');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}).then(function (avds) {
|
||||||
|
// In case we're missing the Android OS version string from the target description, add it.
|
||||||
|
return avds.map(function (avd) {
|
||||||
|
if (avd.target && avd.target.indexOf('Android API') > -1 && avd.target.indexOf('API level') < 0) {
|
||||||
|
var api_level = avd.target.match(/\d+/);
|
||||||
|
if (api_level) {
|
||||||
|
var level = android_versions.get(api_level);
|
||||||
|
avd.target = 'Android ' + level.semver + ' (API level ' + api_level + ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return avd;
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
"author": "Apache Software Foundation",
|
"author": "Apache Software Foundation",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"android-versions": "^1.2.0",
|
||||||
"cordova-common": "^2.1.0",
|
"cordova-common": "^2.1.0",
|
||||||
"elementtree": "0.1.6",
|
"elementtree": "0.1.6",
|
||||||
"nopt": "^3.0.1",
|
"nopt": "^3.0.1",
|
||||||
|
@ -75,7 +75,7 @@ describe('emulator', function () {
|
|||||||
return cmd;
|
return cmd;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('should try to parse AVD information using `avdmanager` first', function () {
|
it('should try to parse AVD information using `avdmanager` first', function (done) {
|
||||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||||
if (cmd === 'avdmanager') {
|
if (cmd === 'avdmanager') {
|
||||||
return true;
|
return true;
|
||||||
@ -83,11 +83,18 @@ describe('emulator', function () {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var avdmanager_spy = spyOn(emu, 'list_images_using_avdmanager').and.returnValue({catch: function () {}});
|
var deferred = Q.defer();
|
||||||
emu.list_images();
|
var avdmanager_spy = spyOn(emu, 'list_images_using_avdmanager').and.returnValue(deferred.promise);
|
||||||
|
deferred.resolve([]);
|
||||||
|
emu.list_images().then(function () {
|
||||||
expect(avdmanager_spy).toHaveBeenCalled();
|
expect(avdmanager_spy).toHaveBeenCalled();
|
||||||
|
}).fail(function (err) {
|
||||||
|
expect(err).toBeUndefined();
|
||||||
|
}).fin(function () {
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
it('should delegate to `android` if `avdmanager` cant be found and `android` can', function () {
|
});
|
||||||
|
it('should delegate to `android` if `avdmanager` cant be found and `android` can', function (done) {
|
||||||
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||||
if (cmd === 'avdmanager') {
|
if (cmd === 'avdmanager') {
|
||||||
return false;
|
return false;
|
||||||
@ -95,9 +102,50 @@ describe('emulator', function () {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var android_spy = spyOn(emu, 'list_images_using_android');
|
var deferred = Q.defer();
|
||||||
emu.list_images();
|
var android_spy = spyOn(emu, 'list_images_using_android').and.returnValue(deferred.promise);
|
||||||
|
deferred.resolve([]);
|
||||||
|
emu.list_images().then(function () {
|
||||||
expect(android_spy).toHaveBeenCalled();
|
expect(android_spy).toHaveBeenCalled();
|
||||||
|
}).fail(function (err) {
|
||||||
|
expect(err).toBeUndefined();
|
||||||
|
}).fin(function () {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('should correct api level information and fill in the blanks about api level if exists', function (done) {
|
||||||
|
spyOn(shelljs, 'which').and.callFake(function (cmd) {
|
||||||
|
if (cmd === 'avdmanager') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var deferred = Q.defer();
|
||||||
|
spyOn(emu, 'list_images_using_avdmanager').and.returnValue(deferred.promise);
|
||||||
|
deferred.resolve([
|
||||||
|
{
|
||||||
|
name: 'Pixel_7.0',
|
||||||
|
device: 'pixel (Google)',
|
||||||
|
path: '/Users/maj/.android/avd/Pixel_7.0.avd',
|
||||||
|
abi: 'google_apis/x86_64',
|
||||||
|
target: 'Android 7.0 (API level 24)'
|
||||||
|
}, {
|
||||||
|
name: 'Pixel_8.0',
|
||||||
|
device: 'pixel (Google)',
|
||||||
|
path: '/Users/maj/.android/avd/Pixel_8.0.avd',
|
||||||
|
abi: 'google_apis/x86',
|
||||||
|
target: 'Android API 26'
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
emu.list_images().then(function (avds) {
|
||||||
|
expect(avds[1].target).toContain('Android 8');
|
||||||
|
expect(avds[1].target).toContain('API level 26');
|
||||||
|
}).fail(function (err) {
|
||||||
|
expect(err).toBeUndefined();
|
||||||
|
}).fin(function () {
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
it('should throw an error if neither `avdmanager` nor `android` are able to be found', function (done) {
|
it('should throw an error if neither `avdmanager` nor `android` are able to be found', function (done) {
|
||||||
spyOn(shelljs, 'which').and.returnValue(false);
|
spyOn(shelljs, 'which').and.returnValue(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user