Ionic 2 Native插件无法安装

时间:2017-01-30 19:12:01

标签: java cordova ionic2

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

要求安装本机插件 -

离子插件添加phonegap-plugin-barcodescanner

Installing "phonegap-plugin-barcodescanner" for android


Installing "cordova-plugin-compat" for android

ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_121

Subproject Path: CordovaLib

Unzipping C:\Users\<user_name>\.gradle\wrapper\dists\gradle-2.14.1-all\53l0mv9mggp9q5m2ip574m21oh\gradle-2.14.1-all.zip to C:\Users\<user_name>\.gradle\wrapper\dists\gradle-2.
14.1-all\53l0mv9mggp9q5m2ip574m21oh

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>\EventShareApp\platforms\android\cordova\node_modules\cordova-common\src\superspawn.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>\EventShareApp\platforms\android\cordova\node_modules\cordova-common\src\superspawn.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

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

1 个答案:

答案 0 :(得分:0)

这引用了我之前的问题:Ionic2 - Android build failed

问题在于最新的Android SDK无法使用。

基本上按照'https://cordova.apache.org/docs/en/latest/guide/platforms/android/' - 截至cordova-android@4.0.0,Android项目的Cordova是使用Gradle构建的。之前它是使用Apache Ant构建的。

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

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

CLI打印了以下内容 -

ionic platform add android

如果有人遇到同样的问题 - 如果将SDK更新到最新版本有帮助,请告诉我。