0

Im trying to generate an aar to use it without maven.

I have these dependencies:

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'

But when I imports the generated aar in my app Im getting this error:

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

Any idea?

Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110
  • Tried those? https://stackoverflow.com/questions/35578135/noclassdeffounderror-for-okhttpclient https://stackoverflow.com/questions/3781151/java-lang-classnotfoundexception-on-working-app – Eugene Babich Feb 15 '19 at 09:48
  • I think that is not problem of multidex, I think that .aar cant include dependencies from maven – Pablo Cegarra Feb 15 '19 at 09:51
  • May be yes, may be no. Look here too https://stackoverflow.com/questions/46171191/activity-class-cannot-be-found-in-aar-file-java-lang-noclassdeffounderror – Eugene Babich Feb 15 '19 at 10:30

1 Answers1

0

This is my solution, I dont know if is the best, but now is working:

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
Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110