How to include dependencies in my android library

I am writing sdk android and now I want to distribute it, but I have problems with my dependencies. I use gradle and android studio.

My sdk has a dependency on volleyball and gson, and I added them as banks in my sdk. When I try to create aar or jar for use in a separate client application, I always get a failure when my sdk ever tries to reference a salvo, since it was not included in either aar or jar. Any ideas on how I should do this? I decided to create live banks with great success.

I also tried using remote dependencies, as shown below, but even after gradle build in the client application, both volleyball 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' } 

and then in the gradle client build 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 someone tell me the correct way to include dependencies in my own library?

+5
source share
2 answers

In your client, change the dependency block as follows:

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

This should also add to your transit dependencies.

+2
source

If you want to include the transitive dependencies of your library in the client application, you need to create an appropriate maven compatible package containing pom.xml. This pom will describe the dependencies of your library so that the client can pull these deps transitively when they include your lib.

See this tutorial: http://blog.blundell-apps.com/locally-release-an-android-library-for-jcenter-or-maven-central-inclusion/

You do not need to load the artifact anywhere during development, just use the local maven repository as the target and mavenLocal() as the repository for your client application. This way you can reference your library as a standard maven dependency using compile 'com.mysdk:mysdk:1.0.0'

+1
source

Source: https://habr.com/ru/post/1201624/


All Articles