How to include library project in library project in Android Studio - java

I have a library project(Project A) in Eclipse that itself depends on a library project(Project B). How to include the Project A and Project B(on which Project A depends) as a library project in my Android Studio main Project (Project M)? I know the answer of how to include a single library project. But my question is how to include a library project which itself depends on a library project.

You'll need to include both library projects (A and B) in your main project (M). Android Studio doesn't support a module with transitive dependencies on other modules that aren't specifically defined in the project's settings.gradle file.

Related

Intellij : import project as library for another project

I am developing a project A (Java Maven) which uses a library B (a JAR file)
I have the source code of library B, and I want to change code in project B, while it's used as library for project A.
Is that possible in Intellij to replace a JAR library by its source code ?
I'd configure a multi-module Maven project with the parent aggregate pom.xml and 2 sub-modules: for the app and for the library with their own pom.xml files.
Define a dependency on the lib module for the app module. IDE will resolve such dependencies via the sources and you will see the changes in the project instantly without the need to compile. Refactorings will also work across the modules so that you can rename a method from the usage in the app and it will automatically rename it in the lib.

Include sources from Java library submodule in Android library project aar artifact

I have a java library submodule holding interfaces which are used in another android library submodule. The problem is that the sources of the java library module are compiled but not included in the aar artifact of the android library project.
How can I include the sources of the java library in the android library aar file?
I ended up including the source files of the java library directly into the android library project using:
sourceSets {
main{
java {
srcDir("../java_library/src")
}
}
}
Only this way the sources are included in the aar file. Still will be great to know if it is possible using simple gradle dependency management.

Include another project using Gradle? [duplicate]

I created a library project in Android Studio (currently 0.5.2) by choosing File > New Project... > "Mark this project as a library".
I have two other non-library projects that I would like to add a dependency to this library project.
-My Library
-Project 1 (depends on My Library)
-Project 2 (depends on My Library)
My goal is to keep each project independent and avoid duplicating modules/code. How can this be done without copying the library module into the other projects?
Update:
Android Studio 0.6.0 allows you to Import a module, though, this simply copies the module source into the Project.
You can also refer to a library outside of your project folder using the project().projectDir property. If your external library is relative to your project like so
- MyLibrary
- library
- MyProject
- app
in MyProject/settings.gradle
include ':library'
project(':library').projectDir = new File(settingsDir, '../MyLibrary/library')
in MyProject/app/build.gradle
dependencies {
compile project(':library')
}
This is very similar to this question:
Sharing an Android library between multiple Android apps using Gradle
Instead of pushing to maven central you can push to your local maven repository (mavenLocal() in build.gradle)
Another route (if you don't want to deploy the library somewhere) is to use your VCS and check out the library within your project. Git has submodules for that, Mercurial has subrepos and SVN has external to name a few examples.
Then add it to your Gradle build using a project dependency.

Add android library project to Android project in Android Studio

I have Android project (main) that has a dependency on Android-library (library) project. I have that in Eclipse where I added library project, but now I want to use Android Studio where I cant find similar option. Is it possible to do it by Gradle where I build library project and main project take that from local repository or I need Maven to do so and if I can then how?
Import your Eclipse library-project (e.g. Facebook library-project), then in your project's settings.gradle refer to Facebook project's module local path in this way:
include ':facebook'
project(':facebook').projectDir = new File(settingsDir, '../facebook/app')

How do I add a java gradle submodule to my Android module?

Suppose I have an Android application project in IntelliJ Idea with Gradle. Call it MyApplication.
What I want to do is to add a plain java library module (not Android library project) as a submodule to MyApplication. Lets call this module a testlib.
And then when whole project is built, I want this module compiled to jar and included to /libs folder of MyApplication.
What I tried: I've created a submodule testlib and included it as a dependency to MyApplication, but I get a following warning:
Warning:Gradle: module 'testlib' won't be compiled. Unfortunately you
can't have non-Gradle Java module and Android-Gradle module in one
project.
Is this even possible?
If you've created your project in IntelliJ as an Android-gradle project, then when you go to the "Add new module" window you should see an "Gradle: Java library" option like this:
IntelliJ IDEA does not support Gradle and Non-Gradle modules in one single project. A comment from JetBrains in their forum states this clearly.
The solution is to either convert the Maven modules into Gradle
modules or split the project in two. With the latter approach, if you
build the plain java library module with Maven before building the
Gradle project, you will still be able to use it as a dependency in
the Android application project.
Beware of using different Java language source levels in multi-module
Gradle projects. IntelliJ IDEA does not handle them correctly due to a
bug in either IntelliJ IDEA or Gradle. (There is a pending discussion
whether this should be fixed in the IDE or Gradle.)

Categories