Android 在代理后面添加 Cordova/Phonegap 插件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22073101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:29:51  来源:igfitidea点击:

Adding Cordova/Phonegap plugins behind a proxy

androidnode.jscordovaphonegap-plugins

提问by white_pawn

I've successfully installed Cordova (clean install, under Windows), and I'm able to deploy a small app to Android, but unable to add any plugins behind my company's proxy. I've already tried setting every possible npm and git variable I could think of via:

我已经成功安装了 Cordova(在 Windows 下干净安装),并且我能够将一个小应用程序部署到 Android,但无法在我公司的代理后面添加任何插件。我已经尝试通过以下方式设置我能想到的所有可能的 npm 和 git 变量:

npm config set proxy url:port
npm config set http-proxy url:port
npm config set https-proxy url:port

(replaced url:port with the actual proxy) and

(用实际代理替换 url:port)和

git config --system --add http.proxy url:port
git config --global --add http.proxy url:port

but to no avail.

但无济于事。

Every time I run something as simple as

每次我运行一些像

cordova plugin add org.apache.cordova.splashscreen

I get the following:

我得到以下信息:

Fetching plugin "org.apache.cordova.splashscreen" via plugin registry
Error: Fetching plugin failed: Error: read ECONNRESET
at C:\Users\x\AppData\Roaming\npm\node_modules\cordova\src\plugin.js:105:41
at _rejected  (C:\Users\x\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:808:24)
at C:\Users\x\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:834:30
at Promise.when (C:\Users\x\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:1079:31)
at Promise.promise.promiseDispatch (C:\Users\x\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:752:41)
at C:\Users\x\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:574:44
at flush (C:\Users\x\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:108:17)
at process._tickCallback (node.js:415:13)

Any help would be much appreciated!

任何帮助将非常感激!

回答by Tom Chamberlain

The issue can be solved by setting HTTP_PROXY before you run the phonegap command:

该问题可以通过在运行 phonegap 命令之前设置 HTTP_PROXY 来解决:

set HTTP_PROXY=http://username:password@proxyhost:proxyport

Where your username:password is your login credentials. It's not using the setting in nodejs.

您的用户名:密码是您的登录凭据。它没有使用 nodejs 中的设置。

On unix you wouldn't use set.

在 unix 上你不会使用 set。

回答by QuickFix

One easy way if you don't manage to make git work behind a proxy (sorry I won't be able to help you with that) is to

如果您无法让 git 在代理后面工作(对不起,我无法帮助您),一种简单的方法是

  • download the git of the plugin using the zip download of git site
  • extract the zip to some path
  • run cordova plugin add pathtotheextractedplugingit
  • 使用git站点的zip下载下载插件的git
  • 将 zip 解压缩到某个路径
  • cordova plugin add pathtotheextractedplugingit

There are several ways to get the url of a plugin git repo, one of them is to go on phonegap build plugin listing pageand then click on the plugin you need to get it's url.

有几种方法可以获取插件 git repo 的 url,其中一种方法是进入phonegap build 插件列表页面,然后单击您需要的插件以获取它的 url。

For the splash screen plugin it would be https://github.com/apache/cordova-plugin-splashscreen

对于闪屏插件,它将是https://github.com/apache/cordova-plugin-splashscreen

回答by John Torres Barreto

This solution work form me in windows. In your user folder: C:\Users\your_user_name.gradle If exists a file called gradle.properties Edit & add

这个解决方案在 Windows 中为我工作。在您的用户文件夹中: C:\Users\your_user_name.gradle 如果存在名为 gradle.properties 的文件 编辑并添加

systemProp.http.proxyHost=[Proxy_IP]
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=[your_username]
systemProp.http.proxyPassword=[your_password]
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost
systemProp.https.proxyHost=[Proxy_IP]
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=[your_username]
systemProp.https.proxyPassword=[your_password]
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

If the file does not exists, create it. Replace the text between [] with your right data. Obviously, the [] must be deleted. I left the "proxyPort" with 8080 because is the default in the most of cases.

如果文件不存在,请创建它。用正确的数据替换 [] 之间的文本。显然,[] 必须被删除。我将“proxyPort”保留为 8080,因为在大多数情况下这是默认设置。