如何配置 Androids sdkmanager 命令行工具以使用自定义存储库? [英] How do I configure Androids sdkmanager command line tool to use custom repository?

查看:23
本文介绍了如何配置 Androids sdkmanager 命令行工具以使用自定义存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 Google 的 Android sdkmanager 配置为通过自定义存储库而不是 dl.google.com/android/repository 下载依赖项?

Is it possible to configure Google's Android sdkmanager to download dependencies through a custom repository instead of dl.google.com/android/repository?

背景:

我正在公司防火墙后面设置一个 Android 构建代理,无法直接访问互联网.我可以访问 LAN 上的存储库服务器,该服务器充当预配置远程存储库的镜像.

I'm setting up an Android build agent behind a corporate firewall with no direct Internet access. I can access a repository server on LAN that acts as a mirror to pre-configured remote repositories.

我已经从这里下载了 SDK 工具 https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip

I've downloaded SDK Tools from here https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip

在可以访问互联网的机器上,我尝试像这样配置 ~/.android/repositories.cfg:

On a machine with Internet access I've tried to configure ~/.android/repositories.cfg like this:

### User Sources for Android Repository
#Fri Nov 30 12:36:38 CET 2018
enabled00=true
count=1
disp00=DB Artifactory
src00=https://dl.google.com/android/repository/repository2-1.xml

如果我在 Android Studio 中设置自定义 SDK 更新站点,我得到的配置是什么.

Which is the configuration I get if I set up a custom SDK Update Site in Android Studio.

这里下载的 xml 文件与 Android Studio 配置的完全相同 - 并且我在运行 sdkmanager 命令行工具时使用 Charles Proxy 观察到的也是相同的.

The xml file downloaded here is exactly the same as configured by Android Studio - and its also the same I observe with Charles Proxy when running the sdkmanager command line tool.

它适用于 Android Studio 中的默认Android 存储库"配置,但我的自定义配置在 Android Studio 和命令行中均失败.

It works just fine for the default "Android Repository" configuration in Android Studio, but my custom configuration fails both in Android Studio and from the command line.

我看到这个错误:

Step 25/34 : RUN yes | sdkmanager --licenses --proxy=http -- 
proxy_host=host.docker.internal --proxy_port=3128
 ---> Running in 8d8923c76ba7
Picked up _JAVA_OPTIONS: -XX:+UnlockExperimentalVMOptions - 
XX:+UseCGroupMemoryLimitForHeap
Warning: Errors during XML parse:       ] 42% Downloading sys-img.xml... Parse X
Warning: cvc-elt.1: Cannot find the declaration of element 'sdk:sdk-repository'.
,,Warning: org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 139; cvc-elt.1: Cannot find the declaration of element 'sdk:sdk-repository'.
Warning: javax.xml.bind.UnmarshalException - with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 17; columnNumber: 139; cvc-elt.1: Cannot find the declaration of element 'sdk:sdk-repository'.]
Warning: Additionally, the fallback loader failed to parse the XML. 

任何帮助将不胜感激...

Any help would be much appreciated...

推荐答案

sdkmanager 的源代码 - 似乎有一种替代存储库的方法 - 通过 SDK_TEST_BASE_URL 环境变量:

Looking at the sdkmanager's source code - there seems to be an alternative method of overriding the repository - via SDK_TEST_BASE_URL environment variable:

为了测试,可以设置env var来替换默认的root下载地址.

For testing, the env var can be set to replace the default root download URL.

它必须以/结尾,并且它是更新程序将查找 repository.xml、addons_list.xml 等文件.

It must end with a / and its the location where the updater will look for the repository.xml, addons_list.xml and such files.

因此,您可以执行以下操作:

Thus, you could do something like this:

SDK_TEST_BASE_URL=https://your.company/artifactory/android/ sdkmanager "platform-tools"

上面的示例将尝试使用提供的存储库 URL 安装 platform-tools 包.只需确保 URL 以 /

The example above will attempt to install platform-tools package using the provided repository URL. Just make sure the URL ends with a /

这篇关于如何配置 Androids sdkmanager 命令行工具以使用自定义存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆