【问题标题】:cannot run cordova application on device or emulators error running无法在设备上运行cordova应用程序或模拟器错误运行
【发布时间】:2019-09-24 16:53:24
【问题描述】:

当我尝试通过命令行运行我的 Cordova 应用程序时。我的构建成功,但在模拟器或设备上运行它在命令行上给我一个错误

错误:无法在设备上启动应用程序:错误:无法启动 将apk安装到设备:错误:找不到apk架构:arm 构建类型:运行一个或多个平台的调试错误:错误: cmd:命令失败,退出代码 8 您可能没有所需的 运行此项目的环境或操作系统

我已经在 AndroidManifest.xml 文件中指定了最低 sdk 版本

 使用-sdk android:minSdkVersion="10" android:targetSdkVersion="21" 

在模拟器上我运行 API 版本 19、android 4.4.2,在移动设备上我运行 android 4.4.3,并在 Sony Xperia ultra t2 上启用了 USB 调试。

【问题讨论】:

    标签: android cordova


    【解决方案1】:

    使用 Visual Studio 2017 和 Cordova 7+ 时遇到了同样的问题,但得到了不同的解决方案。 Cordova 现在在输出目录中创建子文件夹:/platforms/android/build/outputs/apk/debug/android-debug.apk

    在cordova的GenericBuilder.jsbuild.js现在只继承我们正在寻找的方法)在findOutputApksHelper脚本中,当然,没有添加搜索掩码的子目录:

    .....
    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) {
    .........
    

    所以我改成这样:

    ..........
    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) {
    ............
    

    也许它会对某人有所帮助,因为我花了两个小时才找到它。

    【讨论】:

    • 我用了两天还是不行你的解决方案没有效果
    【解决方案2】:

    我认为这是 cordova 中的一个错误(仅在使用 gradle 时出现)。 它似乎已在当前的 master 分支中修复(您可以与 cordova platform add android@master --usegit 一起使用)

    对于旧版本,我是这样解决的:

    在您的项目中的 cordova/lib/ 文件夹中有一个 build.js 文件。 该文件包含一个函数findOutputApksHelper,它检查生成的apk 是否与特定的文件名方案匹配。 默认情况下,生成的调试 apk 名为 android-debug-unaligned.apk,但是该方法会排除所有包含“-unaligned”的文件。 我修改了这样的功能:

    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;
        });
    }
    

    【讨论】:

    • 感谢您的回复。将尝试这个并尽快通知您
    • 我试过这个并没有解决我的问题,这是相似的。模拟器运行但我无法让科尔多瓦在模拟器上启动应用程序:“无法在模拟器上启动应用程序:错误:找不到 apk 架构:x86 构建类型:调试”
    • 该方法现在称为 module.exports.findBestApkForArchitecture
    【解决方案3】:

    只需从调试/发布文件夹中删除 output.json 文件。然后再试一次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-23
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 2012-05-15
      相关资源
      最近更新 更多