问题
I have worked on an Android library (an API client) that uses Retrofit and Joda DateTime.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'joda-time:joda-time:2.8.1'
}
Now that the library is completed I compiled it into an AAR file and I want to use it in an application, so I added it to the libs folder of the application and included it in the build.gradle file like so :
dependencies {
compile(name:'s3papiandroidclient', ext:'aar')
//Some other things
}
However, when I try to initialize the API client from the library, the application crashes when it comes to calling objects from RetroFit or DateTime (For instance, retrofit.RestAdapter). It looks like Gradle does not read the dependencies from the AAR library, thus doesn't install Retrofit and DateTime in my application. I tried to use the transitive=true
parameter on my AAR file, does not help.
Other point that might help, I tried to generate a POM file, and the dependencies don't appear in it either. It looks like there's really something going on with these and I am completely stuck on that.
The only workaround I could find is to add manually the dependencies from the AAR file to the app's build.gradle file but it doesn't make sense, I assume Gradle can import dependencies on its own !
Regards,
Gyoo.
回答1:
It looks like Gradle does not read the dependencies from the AAR library
That is because there are no dependencies in an AAR file.
I tried to generate a POM file, and the dependencies don't appear in it either
Then there is a problem in how you are generating the POM file. Plus, AFAIK, you would need to put the AAR and its POM file in a repository, in order for Gradle to recognize the POM and use the dependency information inside of it.
来源:https://stackoverflow.com/questions/31745072/local-aar-file-doesnt-manage-dependencies