无法在mac OS中构建android项目

时间:2015-09-30 10:36:10

标签: android cordova

我是phonegap的新手。我已经在mac OS中为所有平台创建了项目。我能够构建除android平台以外的其他平台。我使用的是cordova 5.1.1版本。

cordova build android

cordova build android

Running command: /Users/abc/AndroidDevelopments/Project/abcDemo/abcDemo1.1/platforms/android/cordova/build
ANDROID_HOME=/Users/abc/Library/Android/sdk/
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
Running: /Users/abc/AndroidDevelopments/Project/abcDemo/abcDemo1.1/platforms/android/gradlew cdvBuildDebug -b /Users/abc/AndroidDevelopments/Project/abcDemo/abcDemo1.1/platforms/android/build.gradle -Dorg.gradle.daemon=true
> Configuring > 0/2 projects > root project > Resolving dependencies ':classpath'


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:1.0.0+.
Required by:
:android:unspecified
> Failed to list versions for com.android.tools.build:gradle.
> Unable to load Maven meta-data from https://repo1.maven.org/maven2/com/android/tools/build/gradle/maven-metadata.xml.
> Could not GET 'https://repo1.maven.org/maven2/com/android/tools/build/gradle/maven-metadata.xml'.
> Malformed reply from SOCKS server

* 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: 5 mins 6.688 secs

/Users/abc/AndroidDevelopments/Project/abcDemo/abcDemo1.1/platforms/android/cordova/node_modules/q/q.js:126
throw e;
^
Error code 1 for command: /Users/abc/AndroidDevelopments/Project/abcDemo/abcDemo1.1/platforms/android/gradlew with args: cdvBuildDebug,-b,/Users/abc/AndroidDevelopments/Project/abcDemo/abcDemo1.1/platforms/android/build.gradle,-Dorg.gradle.daemon=true
ERROR building one of the platforms: Error: /Users/abc/AndroidDevelopments/Project/abcDemo/abcDemo1.1/platforms/android/cordova/build: Command failed with exit code 8
You may not have the required environment or OS to build this project
        Error: /Users/abc/AndroidDevelopments/Project/abcDemo/abcDemo1.1/platforms/android/cordova/build: Command failed with exit code 8
        at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
        at ChildProcess.EventEmitter.emit (events.js:98:17)
        at maybeClose (child_process.js:753:16)
at Process.ChildProcess._handle.onexit (child_process.js:820:5)

2 个答案:

答案 0 :(得分:0)

如果您想使用maven local repo而不是远程repo,则需要将jar文件添加到本地存储库。

本地maven存储库位于

  

〜/ .m2目录/存储库

您可以从此链接下载, http://mvnrepository.com/artifact/com.android.tools.build/builder/

要在命令行中安装此库类型:

  

mvn install:install-file -DgroupId = com.android.tools.build \   -DartifactId = builder \   -Dversion = 0.5.4 \   -Dfile = builder-0.5.4.jar \   -Dpackaging = jar \   -DgeneratePom =真

然后在build.gradle文件更改中,

  

mavenCentral()

  

mavenLocal()

这可能会有所帮助:)

答案 1 :(得分:0)

为我配置Android SDK路径是一个头脑。

试试这个:

  1. 下载&安装Android Studio
  2. 安装所需的API
  3. 打开Android Studio并转到配置 - >项目默认 - >项目结构
  4. 您可以在那里找到SDK的路径。您可以在此处点击此链接http://docs.phonegap.com/en/4.0.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide

    基本上,您要做的是在.bash_profile中添加SDK和Android工具的路径。 COPY AND PASTE路径将步骤3转换为bash文件。

    因此...

    1. 打开终端并执行此命令source ~/.bash_profile这将在您的用户根目录中创建.bash文件
    2. 打开.bash_profile(它将被隐藏,因此您可能需要执行此操作以使隐藏文件可见。在终端执行defaults write com.apple.finder AppleShowAllFiles YES
    3. 使用文本编辑工具编辑bash_profile,如上面的链接所示
    4. 祝你好运!