简体   繁体   中英

cannot run cordova application on device or emulators error running

When I'm trying to run my Cordova application through command line. My build is successful but running on emulator or device it gives me an error on command line

ERROR: Failed to launch application on device: ERROR: Failed to install apk to d evice: Error: Could not find apk architecture: arm build-type: debug ERROR running one or more of the platforms: Error: cmd: Command failed with exit code 8 You may not have the required environment or OS to run this project

I have specified the the minimum sdk version in the AndroidManifest.xml file

uses-sdk android:minSdkVersion="10" android:targetSdkVersion="21"

on emulator I am running API version 19, android 4.4.2 and on mobile I am running android 4.4.3 with enabled USB debugging on Sony Xperia ultra t2.

With Visual Studio 2017 and Cordova 7+ had the same problem, but came to a different solution. Cordova now makes subfolder in output dir: /platforms/android/build/outputs/apk/ debug /android-debug.apk

In cordova's GenericBuilder.js ( build.js now only inherit method we're looking for) in findOutputApksHelper script, of course, doesn't add that subdirectory to search mask:

.....
function findOutputApksHelper (dir, build_type, arch) {
    var shellSilent = shell.config.silent;
    shell.config.silent = true;

    var ret = shell.ls(path.join(dir, '*.apk')).filter(function (candidate) {
.........

So I changed it like this:

..........
function findOutputApksHelper (dir, build_type, arch) {
    var shellSilent = shell.config.silent;
    shell.config.silent = true;

    var subAPKMask = build_type + '\\*.apk';

    var ret = shell.ls(path.join(dir, subAPKMask)).filter(function (candidate) {
............

Maybe it will be helpful to someone, cause I spent two hours of life to find that.

I think this is a bug in cordova (that only appears when using gradle). It seems to be fixed in the current master branch (which you can use with cordova platform add android@master --usegit )

For the old version I workedaround it like this:

There is a file build.js in your cordova/lib/ folder in your project. This file contains a function findOutputApksHelper which checks if the generated apks match a specific filename scheme. By default the generated debug apks are named android-debug-unaligned.apk, however the method excludes all files that contain "-unaligned". I modified the function like this:

function findOutputApksHelper(dir, build_type) {
    var ret = findApks(dir).filter(function(candidate) {
        // Need to choose between release and debug .apk.
        if (build_type === 'debug') {
            console.log("candidate: "+candidate);
            return /-debug/.exec(candidate);
        }
        if (build_type === 'release') {
            return /-release/.exec(candidate) && !/-unaligned/.exec(candidate);
        }
        return true;
    });

    ret = sortFilesByDate(ret);
    console.log("ret " + ret);
    if (ret.length === 0) {
        return ret;
}

    var archSpecific = !!/-x86|-arm/.exec(ret[0]);
    return ret.filter(function(p) {
        return !!/-x86|-arm/.exec(p) == archSpecific;
    });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM