在aar中包含依赖项

问题描述 投票:0回答:1

我试图生成一个没有maven使用它的aar。

我有这些依赖:

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"

任何的想法?

android aar
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.