在aar中包含依赖项

时间:2019-02-15 09:22:30

标签: android aar

我正在尝试生成aar以在没有maven的情况下使用它。

我有以下依赖性:

api fileTree(include: ['*.jar'], dir: 'libs')
api 'com.squareup.retrofit2:retrofit:2.5.0'
api 'com.squareup.retrofit2:converter-gson:2.5.0'
api 'com.squareup.okhttp3:logging-interceptor:3.12.0'
implementation 'com.android.support:appcompat-v7:28.0.0'

但是当我在应用程序中导入生成的aar时,我收到此错误:

 Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.OkHttpClient$Builder"

有什么主意吗?

1 个答案:

答案 0 :(得分:0)

这是我的解决方案,我不知道它是否是最好的,但是现在可以正常工作了。

android {
    ...

    configurations {
        retrofit
    }
}

dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    retrofit 'com.squareup.retrofit2:retrofit:2.5.0'
    retrofit 'com.squareup.retrofit2:converter-gson:2.5.0'
    retrofit 'com.squareup.okhttp3:logging-interceptor:3.12.0'

}
task copyLibs(type: Copy) {
    from configurations.retrofit
    into "libs"
}
build.dependsOn copyLibs