【问题标题】:Does including a AAR from jCenter also include its dependencies?包含来自 jCenter 的 AAR 是否也包含其依赖项?
【发布时间】:2015-12-20 11:22:29
【问题描述】:

我已将 MoPub SDK 集成到一个新的 Android 应用程序中,使用最简单的方法,即向我的主模块的 build.gradle 添加依赖项(按照 MoPub integration guide 中的说明):

repositories {
    jcenter()
}

dependencies {
    compile('com.mopub:mopub-sdk:4.1.0@aar') {
        transitive = true
    }
}

该指南提到 MoPub SDK 需要几个依赖项:

要求和依赖关系

  • android-support-v4.jar, r22
  • android-support-annotations.jar, r22
  • android-support-v7-recyclerview.jar, r22
  • MoPub Volley 库(mopub-volley-1.1.0.jar - 在 JCenter 上可用)

我应该自己添加这些依赖,还是由 Gradle 依赖管理系统来处理?

【问题讨论】:

    标签: android gradle android-gradle-plugin aar mopub


    【解决方案1】:

    这些被称为 Transitive dependencies 并且 Gradle 会自动检索它们(假设您在问题中指定了 transitive=true)

    它们在 mopub-sdk pom 文件中指定,该文件是 library repo 中包含的信息的一部分。

    你可以查看文件,你会发现:

      <dependencies>
        <dependency>
          <groupId>com.google.android.exoplayer</groupId>
          <artifactId>exoplayer</artifactId>
          <version>r1.4.2</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.android.support</groupId>
          <artifactId>support-annotations</artifactId>
          <version>22.2.0</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.android.support</groupId>
          <artifactId>support-v4</artifactId>
          <version>22.2.0</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.android.support</groupId>
          <artifactId>recyclerview-v7</artifactId>
          <version>22.2.0</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
          <groupId>com.mopub.volley</groupId>
          <artifactId>mopub-volley</artifactId>
          <version>1.1.0</version>
          <scope>compile</scope>
        </dependency>
      </dependencies>
    

    一个转折点是 google 支持库依赖项在 JCenter() 上不可用,您必须使用 Android SDK 管理器单独安装它们。在本地安装它们后,Gradle 可以在 Android SDK 为此目的设置的本地存储库中找到它们。

    【讨论】:

    • 很好的答案,解决了比我预期的更多的疑虑!
    【解决方案2】:

    您不需要全部添加。 Gradle 处理它。

    我一直都在使用 mopub,并且只使用这些就可以正常工作:

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile('com.mopub:mopub-sdk:3.12.0@aar') {
            transitive = true
        }
        compile project(':mm-ad-sdk')
        compile 'com.android.support:appcompat-v7:23.1.1'
        compile 'com.android.support:support-v4:23.1.1'
        compile 'com.android.support:preference-v7:23.1.1'
        compile 'com.google.android.gms:play-services:8.3.0'
        compile 'com.android.support:design:23.1.1'
    }
    

    支持库适用于我的项目。因此没有为 mopub 添加。如果您想使用 admob,只需添加 play-services。如果您打算使用 mopub 进行调解,则其他网络的类似依赖项/jar 引用。

    【讨论】:

      猜你喜欢
      • 2016-11-07
      • 2018-04-02
      • 2015-11-11
      • 2016-07-28
      • 2017-04-30
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多