【问题标题】:Adding dependencies to my project when my AAR already contains them当我的 AAR 已经包含依赖项时,向我的项目添加依赖项
【发布时间】:2015-11-06 16:35:59
【问题描述】:

当我的 AAR 库已经使用这些依赖项时,为什么 gradle 强制我向主模块添加依赖项?

例子:

我的 AAR 库 gradle:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile('com.android.support:design:22.2.1')
    compile('com.android.support:appcompat-v7:22.2.1')
    compile('com.android.support:cardview-v7:22.2.1')
    compile('com.android.support:recyclerview-v7:22.2.1')
    compile('de.greenrobot:eventbus:2.4.0')
}

我的应用分级:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.firetrap.blaap"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile ('my_package_name:channels.base@aar')
 }

为什么我不能使用我的 AAR 中的 com.android.support:cardview-v7:22.2.1

【问题讨论】:

  • 您是使用 libs 文件夹中的 aar 还是使用 maven 存储库?
  • 我都试过了,我有一个个人 maven repo 并上传了 aar 并使用它,结果是一样的
  • aar 文件不包含依赖项,如果使用本地 aar 文件,则必须在主模块中添加所有依赖项。对于 maven repo,检查 pom 文件

标签: android gradle android-gradle-plugin aar


【解决方案1】:

这是因为你的类文件不会被带入你的 aar 的 dex 中。但我认为您寻求解决方案而不是您问题的答案。一个解决方案可能是提取和下载 aar 并将其包含在您的库中,我认为这会起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-11
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 2017-03-07
    • 2018-05-27
    • 1970-01-01
    相关资源
    最近更新 更多