【问题标题】:I want to generate android apk and I have this error in Ionic 4我想生成 android apk,我在 Ionic 4 中有这个错误
【发布时间】:2023-03-03 03:06:01
【问题描述】:
d:\Projets-et-Formations\IONIC\GApp>ionic cordova build android
> cordova platform add android --save
Using cordova-fetch for cordova-android@^8.0.0
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: io.ionic.starter
        Name: Illimi_na_kowa
        Activity: MainActivity
        Android target: android-28
Subproject Path: CordovaLib
Subproject Path: app
Android project created with cordova-android@8.1.0
Installing "cordova-plugin-app-preferences" for android
Failed to install 'cordova-plugin-app-preferences': CordovaError: Using "requireCordovaModule" to load non-cordova module "path" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.        
    at Context.requireCordovaModule (C:\Users\ss\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\Context.js:57:15)
    at module.exports (d:\Projets-et-Formations\IONIC\GApp\plugins\cordova-plugin-app-preferences\bin\before_plugin_install.js:6:14)
    at runScriptViaModuleLoader (C:\Users\ss\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:181:32)
    at runScript (C:\Users\ss\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:157:16)
    at C:\Users\ss\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:125:20   
Using "requireCordovaModule" to load non-cordova module "path" is not supported. Instead, add this module to your dependencies and use regular "require" to load it.
    at process._tickCallback (internal/process/next_tick.js:68:7)
[ERROR] An error occurred while running subprocess cordova.

        cordova platform add android --save exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

【问题讨论】:

  • 到目前为止你有什么尝试?查看错误,在我看来,使用最新版本的 cordova 构建的插件有问题。再次检查错误。 SO中还有其他几个类似问题的帖子,其中大多数都是通过重新安装cordova或插件来解决的。

标签: android ionic-framework apk cordova-plugins ionic4


【解决方案1】:

问题是 Cordova 版本 9 与插件 cordova-plugin-app-preferences 不兼容。在插件的 GitHub 上有一个开放的 issue

你有几个选择:

  1. 降级您的 Cordova 版本
  2. fork 插件并通过将所有出现的位置(如 context.requireCordovaModule('path') 替换为 require('path'))来解决问题。这并不难,这是另一个plugin 的类似更改示例。但是,当然,您可能还需要解决其他问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 2019-07-06
    • 2019-08-22
    • 1970-01-01
    • 2019-10-15
    相关资源
    最近更新 更多