Ionic 2 原生插件无法安装



当我尝试在 Ionic2 项目上添加本机插件时 - CLI 抛出错误为:

请求安装本机插件 -

离子插件添加电话间隙插件条形码扫描仪

Installing "phonegap-plugin-barcodescanner" for android

Installing "cordova-plugin-compat" for android
ANDROID_HOME=C:Program Files (x86)Androidandroid-sdk
JAVA_HOME=C:Program FilesJavajdk1.8.0_121
Subproject Path: CordovaLib
Unzipping C:Users<user_name>.gradlewrapperdistsgradle-2.14.1-all53l0mv9mggp9q5m2ip574m21ohgradle-2.14.1-all.zip to C:Users<user_name>.gradlewrapperdistsgradle-2.
14.1-all53l0mv9mggp9q5m2ip574m21oh
Exception in thread "main"
java.lang.RuntimeException: java.util.zip.ZipException: error in opening zip file
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78)
        at org.gradle.wrapper.Install.createDist(Install.java:47)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.util.zip.ZipException: error in opening zip file
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:219)
        at java.util.zip.ZipFile.<init>(ZipFile.java:149)
        at java.util.zip.ZipFile.<init>(ZipFile.java:163)
        at org.gradle.wrapper.Install.unzip(Install.java:160)
        at org.gradle.wrapper.Install.access$400(Install.java:29)
        at org.gradle.wrapper.Install$1.call(Install.java:70)
        at org.gradle.wrapper.Install$1.call(Install.java:47)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
        ... 3 more
Failed to install 'cordova-plugin-compat':Error: cmd: Command failed with exit code 1
    at ChildProcess.whenDone (F:<path>EventShareAppplatformsandroidcordovanode_modulescordova-commonsrcsuperspawn.js:169:23)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:850:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)

Failed to install 'phonegap-plugin-barcodescanner':Error: cmd: Command failed with exit code 1
    at ChildProcess.whenDone (F:<user_name>EventShareAppplatformsandroidcordovanode_modulescordova-commonsrcsuperspawn.js:169:23)
    at emitTwo (events.js:100:13)
    at ChildProcess.emit (events.js:185:7)
    at maybeClose (internal/child_process.js:850:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)    
Error: cmd: Command failed with exit code 1 enter code here

我尝试使用不同的本机插件 - 但每次错误都保持不变。

这参考了我之前的问题: Ionic2 - 安卓构建失败

问题在于最新的Android SDK不可用。

基本上按照"https://cordova.apache.org/docs/en/latest/guide/platforms/android/"——从cordova-android@4.0.0开始,Cordova for Android项目是使用Gradle构建的。早些时候,它是使用Apache Ant构建的。

现在,Gradle正在寻找最新的Android SDK。当我删除 android 平台并使用ionic platform add android命令再次添加时 - CLI 列出了最新的 Android SDK(在我的情况下是 SDK 24)未安装。

我使用Android SDK

管理器安装了所需的SDK版本,随后添加了Android平台以及cordova插件,顺利安装,没有任何错误。

CLI 打印了以下内容 -

..ionic plugin add onesignal-cordova-plugin
Fetching plugin "onesignal-cordova-plugin" via npm
Installing "onesignal-cordova-plugin" for android
ANDROID_HOME=C:Program Files (x86)Androidandroid-sdk
JAVA_HOME=C:Program FilesJavajdk1.8.0_121
Subproject Path: CordovaLib
Incremental java compilation is an incubating feature.
:clean
:CordovaLib:clean
BUILD SUCCESSFUL
Total time: 1.611 secs
Subproject Path: CordovaLib

如果有人遇到同样的问题 - 请让我知道将 SDK 更新到最新版本是否有帮助。

相关内容

  • 没有找到相关文章

最新更新