无法通过cordova 5.3.3运行Android应用程序

时间:2015-10-08 11:56:29

标签: android cordova

以前有一些旧的科尔多瓦版本。我已升级到最新版本 - 5.3.3

我无法通过cordova 5.3.3 cli将应用程序启动到Android模拟器。然而,模拟器启动正常。

我在powershell提示符下完成的事情:

PS C:\code> cordova create foo
Creating a new cordova project.
PS C:\code> cd foo
PS C:\code\foo> cordova platform
Installed platforms:
Available platforms: amazon-fireos, android, blackberry10, browser, firefoxos, w
ebos, windows, windows8, wp8
PS C:\code\foo> cordova platform add android
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: io.cordova.hellocordova
        Name: HelloCordova
        Activity: MainActivity
        Android target: android-22
Copying template files...
Android project created with cordova-android@4.1.1
Discovered plugin "cordova-plugin-whitelist" in config.xml. Installing to the pr
oject
Fetching plugin "cordova-plugin-whitelist@1" via npm
Installing "cordova-plugin-whitelist" for android
PS C:\code\foo> cordova run
Running command: cmd "/s /c "C:\code\foo\platforms\android\cordova\run.bat""
ANDROID_HOME=D:\sdk-new\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_25
WARNING : No target specified, deploying to emulator
Running: C:\code\foo\platforms\android\gradlew cdvBuildDebug -b C:\code\foo\plat
forms\android\build.gradle -PcdvBuildArch=arm -Dorg.gradle.daemon=true
Downloading http://services.gradle.org/distributions/gradle-2.2.1-all.zip

Exception in thread "main" java.lang.RuntimeException: java.net.UnknownHostExcep
tion: services.gradle.org
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.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.net.UnknownHostException: services.gradle.org
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java
:184)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at java.net.Socket.connect(Socket.java:538)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
        at sun.net.www.http.HttpClient.New(HttpClient.java:308)
        at sun.net.www.http.HttpClient.New(HttpClient.java:326)
        at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLC
onnection.java:1167)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConn
ection.java:1103)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConne
ction.java:997)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection
.java:931)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLCo
nnection.java:1511)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1439)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:59)
        at org.gradle.wrapper.Download.download(Download.java:45)
        at org.gradle.wrapper.Install$1.call(Install.java:60)
        at org.gradle.wrapper.Install$1.call(Install.java:47)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.java:65)
        ... 3 more

C:\code\foo\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                    ^
Error code 1 for command: cmd with args: /s /c "C:\code\foo\platforms\android\gr
adlew cdvBuildDebug -b C:\code\foo\platforms\android\build.gradle -PcdvBuildArch
=arm -Dorg.gradle.daemon=true"
ERROR running one or more of the platforms: Error: cmd: Command failed with exit
 code 1
You may not have the required environment or OS to run this project
PS C:\code\foo>

1 个答案:

答案 0 :(得分:1)

我已经解决了部分问题。还有更多...... ...

它看起来像代理问题。从这里了解了gradle属性文件的设置(我猜它是android的包装工具):https://stackoverflow.com/a/8981559/145682

现在我遇到以下问题 - 无法连接到maven repo

PS C:\code\foo> cordova run android
Running command: cmd "/s /c "C:\code\foo\platforms\android\cordova\run.bat""
ANDROID_HOME=D:\sdk-new\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_25
WARNING : No target specified, deploying to emulator
Running: C:\code\foo\platforms\android\gradlew cdvBuildDebug -b C:\code\foo\plat
forms\android\build.gradle -PcdvBuildArch=arm -Dorg.gradle.daemon=true
Downloading http://services.gradle.org/distributions/gradle-2.2.1-all.zip
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
................................................................................
..................................................
Unzipping C:\Users\arun_jayapal\.gradle\wrapper\dists\gradle-2.2.1-all\2m8005s69
iu8v0oiejfej094b\gradle-2.2.1-all.zip to C:\Users\arun_jayapal\.gradle\wrapper\d
ists\gradle-2.2.1-all\2m8005s69iu8v0oiejfej094b

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/co
m/android/tools/build/gradle/maven-metadata.xml.
            > Could not GET 'https://repo1.maven.org/maven2/com/android/tools/bu
ild/gradle/maven-metadata.xml'.
               > repo1.maven.org

* 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: 1 mins 57.481 secs

C:\code\foo\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                    ^
Error code 1 for command: cmd with args: /s /c "C:\code\foo\platforms\android\gr
adlew cdvBuildDebug -b C:\code\foo\platforms\android\build.gradle -PcdvBuildArch
=arm -Dorg.gradle.daemon=true"
ERROR running one or more of the platforms: Error: cmd: Command failed with exit
 code 1
You may not have the required environment or OS to run this project
PS C:\code\foo>

[更新1]

只是认为我没有正确设置代理;你需要设置https代理...以下帖子说你已经把它放在cordova android文件夹中...但是你可以把它放在USER_HOME/.gradle/gradle.properties文件中

https://stackoverflow.com/a/30243902/145682