简体   繁体   中英

How to use different versions of the same gradle dependency in different Android Studio modules?

In my Android Studio project, I have two modules app and library . Therefore I also have two build.gradle files.

build.gradle(app):

dependencies {
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    ...
}

build.gradle(library):

    dependencies {
    compile 'com.squareup.okhttp:okhttp:2.3.0'
    ...
}

When I call some retrofit methods in my library module, it uses okhttp 2.4.0 instead of 2.3.0. Why is this the case and how can I change this?

Retrofit most likely has a transitive dependency on okhttp and uses 2.4.0 .

You might try

compile ('com.squareup.retrofit:retrofit:2.0.0-beta1'){
    exclude module: 'okhttp'
}
compile 'com.squareup.okhttp:okhttp:2.3.0'}

to force retrofit to use the okhttp dependency that you declared yourself. I don't know though if Retrofit relies on a certain version / implementation of OkHttp and will work properly if it is changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM