Android studio library project dependencies - java

I have imported an Android Studio project as a library for another of my projects. My original question for that is here. It worked excellently for a while, until today. Today I finished updating my library (in its own project) and copied the new files over. I edited the settings.gradle and build.gradle files as I did before but I am getting the error:
Project with path 'Eed:libraries:Overt:Util' could not be found in project ':CES'.
The library's original project is structured like this:
Overt/
+ Visible/
+ Control/
+ CES/
+ Util/
In that project, CES is dependent upon Util
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':Util')
}
When I copied the new version of Overt over I modified the project level settings.gradle and module level build.gradle.
Structure:
Eed/
Eed/
libraries/
Overt/
+ Visible/
+ Control/
+ CES/
+ Util/
settings.gradle
include ':Eed'
include ':Eed:libraries:Overt:Visible'
include ':Eed:libraries:Overt:Control'
include ':Eed:libraries:Overt:Util'
include ':Eed:libraries:Overt:CES'
and build.gradle (Eed module)
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project('libraries:Overt:Visible')
compile project('libraries:Overt:Control')
compile project('libraries:Overt:Util')
compile project('libraries:Overt:CES')
}
I have played with modifying the build.gradle in CES but cannot figure out a solution. What am I doing wrong?

If your CES project still has this dependency, then it looks fishy:
compile project(':Util')
It works best if your dependency statements use the same paths as what appears in settings.gradle, to wit:
compile project(':Eed:libraries:Overt:Util')
I don't know if you can build up a relative Gradle project path to refer to a sibling project at the same level as the referring project. What I mean is that CES and Util are both at the same level, :Eed:libraries:Overt:, what what you really want is something like what you can do in a filesystem path with ../Util, but I don't know offhand if that's possible in Gradle.
It could be that if you're expecting your complex module to be able to be imported somewhere and still maintain its module relationships with relative paths, you may be asking a lot. Having said that, if it's a firm requirement, then you can look into remapping directories in settings.gradle via projectDir. See Gradle subproject name different than folder name for a hint on how to get started with that if you want to go that route.

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'
}

Java only project not adding dependecies on Android Studio

I am using Android Studio 0.8.2 and in my project I have one Android module and one Java only module.
The java only module depends on a external library. I have tried adding it in the libs dir of the project:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And using maven repositories:
repositories {
mavenCentral()
}
dependencies {
compile 'net.sf.kxml:kxml2:2.3.0+'
}
Both systems allows compilation but the library is not included on final jar. I have unzipped the jar and the classes are not there!
Exception in thread "main" java.lang.NoClassDefFoundError: org/xmlpull/v1/XmlPullParserException
A Gradle sync shows this warning message:
"A top-level `dependencies` block should only appear in build files that correspond to a module"
Any idea? Thanks advanced.
Looks like you are not declaring dependencies in build.gradle in app folder, but in the main roof of project? Am I right? You should compare declaring dependencies with other projects like hmm on github. Example: https://github.com/loopj/android-async-http/blob/master/sample/build.gradle (this is build.gradle file in module project, if you go up to root, in build.gradle file there is not declaring not connected to gradle depenncies). Read carefuly the comments and warnings.

Including entire project as library android studio

I am trying to import my own library into one of my apps in Android Studio. I have seen instructions in several places that basically amount to :
1 Move the files into a library folder within your project diectory.
2 Add include 'projectName:folderName:libraryName to your settings.gradle file
3 Add compile project('folderName:libraryName') under dependencies to your project level build.gradle file
This works for me if I am importing a module... I think its a module. I'm still trying to figure out gradle. My library structure looks like this:
ProjectName
Module1
Classes
Module2
Classes2
If I import Module1 or Module2 separately in this fashion (where Module1 is my 'libraryName' in the instructions above), they will work. But if I try to import the whole project as one library I get errors.
What am I doing wrong? I would like to import the entire project as I would like it to have many modules. Is there another/better way to do this? What am I misunderstanding?
Update:
As per #ScottBarta 's instructions I merged settings.gradle files. This appears to have worked in my main project because the gradle sync completed properly but I'm not ready to run that project. So I made a tester project and imported the library using the same steps. This time I get the error:
Gradle 'Tester' project refresh failed:
Build script error, unsupported Gradle DSL method found. 'compile()'!
As near as I can tell, the files are equivalent in the two projects:
Main:
include ':Eed'
include ':Eed:libraries:Overt:Visible'
include ':Eed:libraries:Overt:Control'
Test:
include ':app'
include ':app:libraries:Overt:Visible'
include ':app:libraries:Overt:Control'
Main:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project('libraries:Overt:Visible')
compile project('libraries:Overt:Control')
}
Test
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
complie project('libraries:Overt:Visible')
complie project('libraries:Overt:Control')
}
And here's a screenshot of the file structure in the Tester project.
You can only have one settings.gradle file per project, so if you have a multi-module library with its own settings.gradle, you can't bring it in with a single include statement. You'll need to merge the library's settings.gradle into that of the project you're including it in.
When you do the merge, make sure that all the include statements in the merged settings.gradle have sensible paths that will locate their libraries relative to the project root. Also keep in mind that the paths specified in your settings.gradle file have to match what's in your dependencies block. So if you have this:
include ':app'
include ':app:libraries:Overt:Visible'
include ':app:libraries:Overt:Control'
You need this:
dependencies {
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':app:libraries:Overt:Visible')
compile project(':app:libraries:Overt:Control')
}
In the build script you posted in your question, there's a typo: it says complie instead of compile. If that's a typo in your build script and not just a typo in your question here, that will be a problem.

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