我想生成android apk,在Ionic 4中出现此错误

问题描述 投票:0回答:1
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 [email protected]
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.
android ionic-framework apk cordova-plugins ionic4
1个回答
0
投票

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

您有几个选择:

  1. 降级您的Cordova版本
  2. 叉出插件并通过自己替换所有出现的内容,例如context.requireCordovaModule('path')require('path'),从而解决了问题。并不困难,下面是另一个plugin的类似更改的示例。但是,当然,您可能还需要解决其他问题。
© www.soinside.com 2019 - 2024. All rights reserved.