【问题标题】:Which http or Https link call behind gradle dependency?gradle依赖背后的哪个http或Https链接调用?
【发布时间】:2017-05-10 16:48:02
【问题描述】:

在我的 android studio 中,我在我的 gradle 文件中使用了以下依赖项。

compile 'com.android.volley:volley:1.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

现在我尝试在 android studio 中重新打开它,但它显示我未能解决错误。 我的网络管理员阻止了某些站点,这就是为什么这些依赖项对我不起作用的原因。 现在我想访问这些依赖项,但我不知道它们如何与 server 连接,这些依赖项背后的 URL 调用。

【问题讨论】:

  • 你的管理员真是个坏人!如果您能得到一些线索,请查看从 Info 级别开始的日志。

标签: android dependencies android-gradle-plugin


【解决方案1】:

有不止一种可能的选择。

1) 首先尝试将 Volley 添加为来自此 URL 的 jar 依赖项:http://central.maven.org/maven2/com/mcxiaoke/volley/library/1.0.0/library-1.0.0.jar这是官方添加截击的方式

下载 Volley.jar 文件并将其粘贴到 your-project\app\libs 文件夹并添加为 jar 依赖项。然后重建你的项目。如果这不起作用,那么,

2) 尝试移除 espresso 的插件并重新构建。

这可能行得通。

【讨论】:

  • 说,是否可以使用 jar/aar 文件的直接 URL 调用 implementation?这样,如果我有自己的服务器,我可以提供一种半公开的方式来访问它(半公开的,因为它不是流行主机的一部分)。
【解决方案2】:

我们需要指定一些存储库,gradle 可以在其中找到所需的 jar。我们可以直接使用 maven 和 jcenter 仓库。 Gradle 可以使用 mavenCentral()jcenter() 调用 maven 和 jcenter 存储库。 在您的build.gradle 中应该有这样的内容

buildscript {
   repositories {
    jcenter()
    mavenCentral()
   }  
}

如果你点击mavenCentral(),你会发现这条javadoc评论

 /**
 * Adds a repository which looks in the Maven central repository for dependencies. The URL used to access this repository is
 * {@value org.gradle.api.artifacts.ArtifactRepositoryContainer#MAVEN_CENTRAL_URL}. The name of the repository is
 * {@value org.gradle.api.artifacts.ArtifactRepositoryContainer#DEFAULT_MAVEN_CENTRAL_REPO_NAME}.
 *
 * <p>Examples:
 * <pre autoTested="">
 * repositories {
 *     mavenCentral()
 * }
 * </pre>
 * </p>
 *
 * @return the added resolver
 * @see #mavenCentral(java.util.Map)
 */
MavenArtifactRepository mavenCentral();

点击#MAVEN_CENTRAL_URL你会找到这个网址

  String MAVEN_CENTRAL_URL = "https://repo1.maven.org/maven2/";

现在如果你重复 jcenter() 你会得到 ​​p>

https://jcenter.bintray.com/

所以我认为这些是 android 找到它的大部分库的 url。

【讨论】:

    猜你喜欢
    • 2014-07-17
    • 1970-01-01
    • 2013-07-05
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-16
    相关资源
    最近更新 更多