Android aar dependencies

I am new to Gradle build system, I have a library project that includes dependencies like Retrofit, okhttp, etc.

I compiled my project and created aar file. I created a dummy project and added my library as a dependency.

Now, if I do not add Retrofit and okhttp as dependencies in my build.gradle file of the dummy file, my application crashes with no exception found.

My question is: since the library aar file already includes Retrofit and okhttp as a dependency, why should I explicitly add them to the dummy build.gradle file of the application? There is a workaround.

Here is my build.gradle library

apply plugin: 'com.android.library' buildscript { repositories { mavenCentral() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.0.+' } } allprojects { repositories { jcenter() } } android { compileSdkVersion 22 buildToolsVersion "21.1.2" defaultConfig { minSdkVersion 14 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }} dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.+' compile 'com.android.support:recyclerview-v7:21.+' compile 'com.android.support:cardview-v7:21.+' compile 'com.google.android.gms:play-services:6.5.87' compile 'com.squareup.okhttp:okhttp:2.2.0' compile 'com.squareup.retrofit:retrofit:1.9.0' } 
+5
source share
1 answer

I was able to solve this problem by adding the aar file to the local maven repository. Somehow just adding aar to the libs folder and including it as a dependency does not fix the problem.

If you encounter a similar problem, just change the build.gradle library project with these add-ons

  apply plugin: 'maven' version = "1.0" group = "com.example.lib" buildscript { repositories { mavenCentral() mavenLocal() } dependencies { classpath 'com.github.dcendents:android-maven-plugin:1.0' } } repositories { mavenLocal() } uploadArchives { repositories { mavenDeployer { repository(url: "file://${System.env.HOME}/.m2/repository/") } } } 

Run the task in the terminal provided in the Android studio itself, like. / gradlew uploadArchives

Then, in the build.gradle file of your application module, add the library as a dependency

 compile ('com.example.app:ExampleLibrary: 1.0@aar ') { transitive = true; } 
+3
source

All Articles