通过代理服务器使用npm、cordova等这样的工具时会遇到一些麻烦,折腾了几天大概记录一下步骤,便于以后再遇到时查阅:
步骤
1、下载nodejs
2、配置npm代理、设置taobao源
3、安装npm install cordova
4、下载android studio,以便获的最新的android sdk
可通过设置环境变量ANDROID_HOME指定,例如D:Program FilesAndroidsdk
5、运行打包 cordova build android , 会提示下载gradle-2.2.1-all.zip失败。
手动通过FQ或download.csdn.net下载。在用户目录下搜索 gradle-2.2.1-all.zip.part ,
例如我的路径为: D:user.gradlewrapperdistsgradle-2.2.1-all2m8005s69iu8v0oiejfej094bgradle-2.2.1-all.zip.part
并将手动下载的gradle-2.2.1-all.zip复制到同文件夹。再次运行命令后cordova会自动解压zip。
6、如有nexus私有仓库则修改F:workspacecordovadcappplatformsandroiduild.gradle文件中的maven仓库url
allprojects { repositories { maven { url "http://10.98.65.55:8081/nexus/content/repositories/Central/" } } } buildscript { repositories { //mavenCentral() maven{ url 'http://10.98.65.55:8081/nexus/content/repositories/nexus-osc/'} } …… } repositories { //mavenCentral() maven{ url 'http://10.98.65.55:8081/nexus/content/repositories/nexus-osc/'} }
7、在build.gradle同级目录创建gradle.properties 设置代理服务器
systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyPort=8000 systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyPort=8000 systemProp.http.nonProxyHosts=10.*|localhost
8、运行cordova build android 生成
错误提示
F:workspacecordovadcapp>cordova build android Running command: F:workspacecordovadcappplatformsandroidcordovauild.bat ANDROID_HOME=D:Program FilesAndroidsdk JAVA_HOME=D:javajdk1.7.0 Running: F:workspacecordovadcappplatformsandroidgradlew cdvBuildDebug -b F :workspacecordovadcappplatformsandroiduild.gradle -Dorg.gradle.daemon=tru e FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'android'. > A problem occurred configuring project ':CordovaLib'. > Could not resolve all dependencies for configuration ':CordovaLib:classpath '. > Could not resolve com.android.tools.build:gradle:1.0.0+. Required by: android:CordovaLib: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'. > Connection to https://repo1.maven.org refused * 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.299 secs F:workspacecordovadcappplatformsandroidcordova ode_modulesqq.js:126 throw e; ^ Error code 1 for command: cmd with args: /s /c "F:workspacecordovadcappplatf ormsandroidgradlew cdvBuildDebug -b F:workspacecordovadcappplatformsandro iduild.gradle -Dorg.gradle.daemon=true" ERROR building one of the platforms: Error: F:workspacecordovadcappplatforms androidcordovauild.bat: Command failed with exit code 1 You may not have the required environment or OS to build this project Error: F:workspacecordovadcappplatformsandroidcordovauild.bat: Command f ailed with exit code 1 at ChildProcess.whenDone (C:UsersAdministratorAppDataRoaming pm ode_mo dulescordova ode_modulescordova-libsrccordovasuperspawn.js:131:23) at ChildProcess.emit (events.js:110:17) at maybeClose (child_process.js:1015:16) at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
参考资料
gradle build failure Connection to https://repo1.maven.org refused - Stack Overflow
http://stackoverflow.com/questions/30526575/gradle-build-failure-connection-to-https-repo1-maven-org-refused