How do I include dependencies in my android library - java

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?

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: http://blog.blundell-apps.com/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'

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.

Related

include gturri android xml rpc library in android project

i need to include this library but i ve got several problems.
project library on github
i tried to follow the instructions on the github project but they did not work for me. I have to include the library in android studio.
i tried to:
1) copy the whole code in my project but i had a lot of conflicts about package, and, once solved, i began to have problems about lacks of functions not defined
2) i tried to use mvn install command, but it did not work, something like 100 errors displayed
3) i tried to open that project with intelliJ and then i tried to export jar file, but intelliJ told that it s an android project
does anyone have any idea about the procedure to include this library?
Thanks a lot in advance
you could give Jitpack a try. At least it worked for me..
See https://jitpack.io/
In essence: add following code to the build.gradle file of your project:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
and add the following line to the dependencies section in the build.gradle file of your app:
`compile 'com.github.gturri:aXMLRPC:master-SNAPSHOT'`
here is what the dependency section looks like for me:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.github.gturri:aXMLRPC:master-SNAPSHOT'
compile 'com.android.support:support-v4:23.4.0'
}

can I customize my existing LibGDX project with the gds-setup.jar?

I've created my game with Lib-GDX and I'm almost done! :D
the problem is that I forgot to include one of the Third Party feature in the initial GDX setup. Is there any way I can go back and include it, using the gds-setup.jar or any other way? Or must I go the super advanced way and create a new project and include the feature?
To be more precise I'm trying to include the libGDX cross platform Facebook support
You can just add your 3d party stuff to the build.gradle file for your case your need this :
compile "de.tomgrill.gdxfacebook:gdx-facebook-core:1.1.1"
to be added to the dependencies, there is no need of creating new project with gdx-setup.jar
check this topic in the officiel wiki for more info :
Dependency management with Gradle
I just created a new project with gdx-setup.jar and added the Third Party Ext. I wanted. Once that was complete i copied the code that called the TPE in the gradle files and added them to my original game's gradle so for Example:
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "de.tomgrill.gdxfacebook:gdx-facebook-android:1.1.1"//this is what I needed to add
compile fileTree(dir: 'libs', include: '*.jar')
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "de.tomgrill.gdxfacebook:gdx-facebook-core:1.1.1"//this was what I needed to add
compile fileTree(dir: 'libs', include: '*.jar')
}
}
this was all in the main project's gradle folder.

Cannot resolve symbol in Android

I am working on integrating twitter with my android application, I am using twitter4j library to do this.
I have added the twitter4j library files and put it in a folder libs and added compile dependency in build.gradle inside app folder
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:6.5.+'
compile 'org.twitter4j:twitter4j-core:4.0.2'
}
but I am still not able to use this library
In the Gradle drawer to the right, could you hit the refresh button to see if that helps? Also, the dependencies block that you've pasted above doesn't contain a directive for twitter4j - did you happen to simply miss it out in the question, or is it really missing from the gradle.build file?
Try to add this at "repositories" on your buildscript.
repositories { mavenCentral() }

Add library to gradle build

I'm trying to add org.apache.commons.lang3 to my build. I've downloaded the library which is directory containing jar files.
My group is using gradle to build the project, and I know just enough to maybe ask the right question. So what I think the build is doing is
copying a bunch of .bnds to the build directory
compiles the java we have in src/main/java (via source sourceSets.main.java.srcDirs?)
I would like to add the lang3 library, but I'm not sure how to go about doing that. Can I just dump it into src/main/java? Or do I have to tell gradle about it?
This is what I think is relevant from the current build.gradle
ext.releaseDir = "${buildDir}/release/${tpVersion.getProgramName()}"
ext.bundlesDir = "${releaseDir}/nucleus/bin/nucleus_java/bundles/"
dependencies {
compile fileTree(dir: bundlesDir, include: '*.jar')
bnd {
source sourceSets.main.java.srcDirs
include '**/*.bnd'
You could declare it as a dependency, if it exists in any remote repository. That's the way I would do it.
But if you want to use the local file, do not put it in src/main. Use an extra folder called lib or similar on the same directory level as src or you build script.
Then you can add the local dependency to the build.gradle as in this sample:
repositories {
//central maven repo
mavenCentral()
}
dependencies {
//local file
compile files('libs/toxiclibscore.jar')
//dependencies from a remote repository
compile 'java3d:vecmath:1.3.1', 'commons-lang:commons-lang:2.6'
}
The simplest way is to use maven repository for accessing dependencies.
You can also access this jar directly from filesystem with file dependencies.
dependencies {
compile files('libs/a.jar', 'libs/b.jar')
compile fileTree(dir: 'libs', include: '*.jar')
}

Adding JBoss AS 7 libs as Gradle Dependency

I need to add JBoss 7.1.1 libs as a Gradle dependency in my project, because I need them in compile time.
But all the dependencies I have are added from a Maven Repo.
I have seen how to do it, I can add them as a providedCompile dependency, using this technique right here. But what do I associate it to?
How do I add libs that I have in my JBoss Modules as a Gradle dependency?
EDIT
I have seen I can add a file tree to my dependencies like this:
dependencies {
provided fileTree(dir: 'myDir', include: '*.jar')
}
But it doesn't work recursively. It only adds the defined folder,
and JBoss AS 7.1.1 has all the jars splitted in modules, is there any way I can reference the entire module folder, instead of each specific one?
What I want to do is somehting like this, but it doesn't work with this syntax:
dependencies {
provided fileTree(dir: '%JBOSS_HOME%/modules', include: '*.jar')
}
Try the following:
dependencies {
provided fileTree(dir: 'myDir', include: '**/*.jar')
}
This should add all .jar files in all subfolders of 'myDir'.
Explanation: The **/ before the *.jar tells it to recursively check all directories for the .jar files.

Categories