8

I am writing an android sdk and I now want to distribute it but I am having problems with its dependencies. I am using gradle and android studio.

My sdk has a dependency on volley and gson and I have them added as jars with in my sdk. When ever I try to create an aar or a jar to use within a separate client app I always get a crash when ever my sdk tries to reference volley as it wasnt included in either the aar or jar. Any ideas on how I should be doing this? I have looked into creating fat jars with out much success.

I have also tried using remote dependencies like below but even after a gradle build in the client app both volley and gson are still not included. This is currently what I have in my sdk build.gradle

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.mcxiaoke.volley:library-aar:1.0.0' compile 'com.google.code.gson:gson:2.3' } 

then with in the client build gradle I have

repositories { flatDir { dirs 'libs' } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile(name:'mysdk-1.0.0', ext:'aar') } 

I am using ./gradlew clean build to build the aar and jar of my sdk Can anyone tell me the correct way to include dependencies in my own lib?

2
  • 1
    This is a very concise and clear question. It captures exactly what I wanted to ask, but didn't have to because I found yours! Kudos. Commented Jan 8, 2016 at 17:07
  • How did you solve it? The accepted answer didn't work for me. Commented Feb 26, 2016 at 9:22

2 Answers 2

3

If you wish to include the transitive dependencies of your library in your client app, you'll need to create a proper maven compatible package that contains a pom.xml. This pom will describe the dependencies of your lib, so that client can pull those deps transitively when they include your lib.

See this tutorial(updated link): http://blog.blundellapps.co.uk/locally-release-an-android-library-for-jcenter-or-maven-central-inclusion/

You don't have to upload the artifact anywhere during development, just use your local maven repo as a target, and have mavenLocal() as a repository for your client app. This way, you'll be able to refer to your lib as a standard maven dependency using
compile 'com.mysdk:mysdk:1.0.0'

Sign up to request clarification or add additional context in comments.

1 Comment

1

In your client, change your dependencies block like so:

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile(name:'mysdk-1.0.0', ext:'aar') { transitive = true } } 

This should pull in your transitive dependencies as well.

2 Comments

Where do I call this compile(name: ext:)? I am trying calling it in my client's build.gradle and it gives error on mysdk-1.0.0. I thought mysdk-1.0.0 is just a label which will be given to the resulting jar/aar. What should I do?
This doesn't work for me. Does the AAR files even have the dependency information inside of it? Isn't a POM file required?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.