"离子cordova build"无法构建apk

时间:2017-08-08 03:00:22

标签: android cordova ionic-framework

我无法在cordova中构建apk。构建总是失败。

设置我的android SDK主页

导出ANDROID_HOME / home / felipe / Android / Sdk /

首先,构建找不到gradle,所以我把gradle放在路径中。我已经尝试使用下载的gradle或我在android studio中使用的gradle。

export PATH = $ PATH:/home/felipe/gradle-4.1/bin

为了确保我有更新版本的cordova和ionic

npm install -g cordova @ latest npm install -g ionic @ latest

简单示例应用

离子起始侧面菜单侧面 - 类型ionic1

cd sidemenu 离子cordova平台添加android 离子cordova构建android

然后我得到了:

    > ionic cordova prepare
    > cordova prepare
    ✔ Running command - done!
    Running command: /home/felipe/ionic-testes/sidemenu/hooks/after_prepare/010_add_platform_class.js /home/felipe/ionic-testes/sidemenu
    add to body class: platform-android
    > cordova build android
    ✖ Running command - failed!

    [ERROR] Cordova encountered an error.
            You may get more insight by running the Cordova command above directly.

    [ERROR] An error occurred while running cordova build android (exit code 1):

            Running command: /home/felipe/ionic-testes/sidemenu/hooks/after_prepare/010_add_platform_class.js
            /home/felipe/ionic-testes/sidemenu
            add to body class: platform-android
            ANDROID_HOME=/home/felipe/Android/Sdk/
            JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
            Subproject Path: CordovaLib

            FAILURE: Build failed with an exception.

            * What went wrong:
            A problem occurred configuring root project 'android'.
            > Could not resolve all dependencies for configuration ':classpath'.
            > Could not resolve com.android.tools.build:gradle:2.2.3.
            Required by:
            project :
            > Could not resolve com.android.tools.build:gradle:2.2.3.
            > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom'.
            > Could not HEAD 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom'.
            > sun.security.validator.ValidatorException: PKIX path building failed:
            sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested
            target

            * Try:
            Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

            BUILD FAILED

            Total time: 2.176 secs
            Error: /home/felipe/ionic-testes/sidemenu/platforms/android/gradlew: Command failed with exit code 1 Error
            output:
            FAILURE: Build failed with an exception.

            * What went wrong:
            A problem occurred configuring root project 'android'.
            > Could not resolve all dependencies for configuration ':classpath'.
            > Could not resolve com.android.tools.build:gradle:2.2.3.
            Required by:
            project :
            > Could not resolve com.android.tools.build:gradle:2.2.3.
            > Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom'.
            > Could not HEAD 'https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom'.
            > sun.security.validator.ValidatorException: PKIX path building failed:
            sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested
            target

            * Try:
            Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

请。有人能帮帮我吗?感谢您的关注

2 个答案:

答案 0 :(得分:1)

解决。我刚在Android Studio中打开过。 我不知道为什么,但是回答正确的用户已经删除了他的帖子。我在Android Studio中安装了sdk和sdk管理器,我安装了Android Studio建议的其他更新,但只有当我在android studio中打开项目时才会进行所需的更新。

从错误消息中,我想我的open jdk安装中缺少一些证书颁发机构(我使用ubuntu存储库中的openjdk并安装了ca-certificates-java包)。但是,就目前而言,它确实有效。

答案 1 :(得分:0)

请使用此命令创建项目

  1. 离子开始sidemenu sidemenu --blank
  2. Cd sidemenu
  3. 添加Android,iOS所需的平台 4.Cordova构建android
  4. Cordova运行android