getting gradle error while creating cordova projec

2019-01-20 15:15发布

问题:

I just updated cordova version from 4.0 to 5.1, and everything worked fine also in creating project. But as soon as I gave command of cordova build I got below error.

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'.
               > peer not authenticated

After 2 days suffering I came to know it's coming due to gradle, I downloaded and added it also in environment variable. I do get this error also when I go to android folder in cordova project and give command of gradle init. Don't know what can be reason of it. Am still using eclipse instead of android studio can it also be a reason ?

回答1:

This is a Java SSL connection error, you need to add the appropriated SSL certificate to the Java Keystore for Java accept the connection.

Step 1: Download the certificate

With Mozilla Firefox:

  1. Go to https:// repo1.maven.org (remove the space).
  2. Click on the green padlock at the left of the address bar.
  3. Click on Details.
  4. Click on View certificate.
  5. Click on Details.
  6. Click on Export.
  7. Export file to "X.509 Certificate (PEM) (*.crt; *.pem)"

Step 2: Add the certificate to default Java Keystore

sudo keytool -import -alias MavenRepo -keystore $JAVA_HOME/jre/lib/security/cacerts -file /PATH/TO/YOUR/EXPORTED/FILE.crt

Your $JAVA_HOME variable should be declared in your .bashrc file, so you can use this command just replacing the /PATH/TO/YOUR/EXPORTED/FILE parameter.

PS: The default password of Java Keystore is: changeit

From: https://github.com/meteor/meteor/issues/6362#issuecomment-189852511



回答2:

Problem is due to Proxy When you are in corporate network It may be happened. Don't Worry gradle.properties which consist of proxy setting ie

systemProp.https.proxyHost=www.somehost.org
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

Add gradle.properties file your platform/android

& then Build. It works for me



回答3:

I had the same error, but it was after i installed git which in turn changed my environment variables. I went back there to remove the added path and it worked



回答4:

if you are behind a proxy, try "npm config " command. I met similar issue and solved by setting the proxy with:

"npm config set proxy http://mydomain:proxyPort"
"npm config set proxy https://mydomain:proxyPort"


回答5:

OK silly answer, previously I was using cordova 4.0 and eclipse which was using ant for build.

But from cordova 5.0 it requires gradle. I just installed android studio and mapped my old sdk downloaded with eclipse. As I mapped it and opened one of cordova created project in android studio. I got one error but due to one of stackoverflow question here, I solved the issue.

Created new project and it took some time to download all the dependencies, but at last it solved. Now I can create with CMD.

So key of the answer is you need to install android studio if you are still using eclipse.