[cordova]通過代理服務器使用cordova


通過代理服務器使用npm、cordova等這樣的工具時會遇到一些麻煩,折騰了幾天大概記錄一下步驟,便於以后再遇到時查閱:

步驟

1、下載nodejs

2、配置npm代理、設置taobao源

3、安裝npm install cordova

4、下載android studio,以便獲的最新的android sdk

可通過設置環境變量ANDROID_HOME指定,例如D:\Program Files\Android\sdk

5、運行打包 cordova build android , 會提示下載gradle-2.2.1-all.zip失敗。

手動通過翻牆或download.csdn.net下載。在用戶目錄下搜索 gradle-2.2.1-all.zip.part ,

例如我的路徑為: D:\user\.gradle\wrapper\dists\gradle-2.2.1-all\2m8005s69iu8v0oiejfej094b\gradle-2.2.1-all.zip.part

並將手動下載的gradle-2.2.1-all.zip復制到同文件夾。再次運行命令后cordova會自動解壓zip。

6、如有nexus私有倉庫則修改F:\workspace\cordova\dcapp\platforms\android\build.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:\workspace\cordova\dcapp>cordova build android
Running command: F:\workspace\cordova\dcapp\platforms\android\cordova\build.bat

ANDROID_HOME=D:\Program Files\Android\sdk
JAVA_HOME=D:\java\jdk1.7.0
Running: F:\workspace\cordova\dcapp\platforms\android\gradlew cdvBuildDebug -b F
:\workspace\cordova\dcapp\platforms\android\build.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:\workspace\cordova\dcapp\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
Error code 1 for command: cmd with args: /s /c "F:\workspace\cordova\dcapp\platf
orms\android\gradlew cdvBuildDebug -b F:\workspace\cordova\dcapp\platforms\andro
id\build.gradle -Dorg.gradle.daemon=true"
ERROR building one of the platforms: Error: F:\workspace\cordova\dcapp\platforms
\android\cordova\build.bat: Command failed with exit code 1
You may not have the required environment or OS to build this project
Error: F:\workspace\cordova\dcapp\platforms\android\cordova\build.bat: Command f
ailed with exit code 1
    at ChildProcess.whenDone (C:\Users\Administrator\AppData\Roaming\npm\node_mo
dules\cordova\node_modules\cordova-lib\src\cordova\superspawn.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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM