【问题标题】:Transitive dependencies not getting reflected in android application传递依赖没有反映在android应用程序中
【发布时间】:2017-04-12 08:24:24
【问题描述】:

我创建了一个 android 库,它在其 gradle 文件中具有某些依赖项,例如 volley、SqlCipher 等。当我在另一个项目中使用此库的 aar 文件时,我得到了 ClassNotFoundError w.rt。 SqlCipher 和 Volley。 我认为这可能与所谓的传递依赖有关。谁能帮我解决这个问题?

sdk 的 Gradle 文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.2"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFile('proguard-rules.pro')

        }
    }
}

repositories {
    maven {
        url "https://jitpack.io"
    }
    mavenCentral()
    jcenter()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'net.zetetic:android-database-sqlcipher:3.4.0'
    //compile 'net.zetetic:android-database-sqlcipher:3.3.1-2@aar'
    compile 'com.google.android.gms:play-services-location:10.2.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:design:23.0.0'
    compile 'com.google.android.gms:play-services:10.2.0'
}

应用程序的 Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile (project(':sdk-debug'))

}

【问题讨论】:

    标签: android android-gradle-plugin android-library transitive-dependency


    【解决方案1】:

    您需要在包含 aar 的 app.gradle 构建中添加 transitive=true。

    你可以实现如下:

    compile ('YOUR_GROUP_ID:ARTIFACT_ID:VERSION@aar'){
       transitive=true
    }
    

    【讨论】:

    • 我认为它只适用于已发布的库,我还没有发布我的库。
    • 应用程序的 Gradle 文件:依赖项 { compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support: appcompat-v7:25.2.0' compile (project(':sdk-debug')) } settings.gradle : include ':app', ':sdk-debug' 我已将 sdk-debug 包含为模块依赖项。
    • 我已经添加了 sdk 和 app 的 gradle 文件。如果您能提供帮助,请立即查看
    猜你喜欢
    • 2019-10-31
    • 2012-10-06
    • 2022-09-30
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 2021-07-26
    • 1970-01-01
    相关资源
    最近更新 更多