Add android library project to Android project in Android Studio - java

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

Related

can't find build.gradle in Eclipse projects

I want to add library to my android project in eclipse but I can't find build.gradle
I tried to install Gradle plugin in eclipse and create new Gradle project but the project is for java not for android
So, how can I create new android project with gradle in eclipse like android studio?
And how to add libraries to my project?
Install gradle on your computer and then open the console.
Go to your project's directory and run the task "gradle init". This will add the files that gradle needs.
To add libraries to you project, add them to the "build.gradle" file and then run "gradle build" task to download them.
PS: as referred in the comments, Eclipse isn't the advisable tool to build an Android project, you should go with Android Studio

Include Github Project into Android Studio 2 project without jar or dependency

i have found this sdk: is24-restapi-java
and i want to import it into my android studio project for further use.
But i can't find a way to include it.
I did some searching through the github project i cannot find a simple jar or dependency that i can include into my project and all advances to generate a jar or something failed.
Can anyone give me a guid or something to include this sdk into my project or am i using the wrong approach?
Goto File -> New -> Import Module.
Source Directory -> Browse the project path
Specify the Module Name – it is used for internal project reference.
Let Android Studio build the project.
Open build.gradle (Module:app) file.
Add the following line with your module name in place of “projectName” in the dependencies block:
compile project(':projectName')
After this Android Studio would start saying “gradle files have changed since last project sync”, press the “sync now” link to start a sync.

How to add an existing java project as a module to an existing Android Studio project

I have two github repositories - one an Android Studio project and another a intellij Idea Java project. Right now i build jar from my java project and use that jar in Android Studio project.
Is there a way I can add my existing java project as a sub-module in my existing Android Studio project so that I do not have to go through the hassle of creating a new jar every time I modify the java project?

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.

Adding a Maven Project to an Android Studio App as a Dependency

I am currently developing an Android App using Android Studio 1.2 .
I want to use an external Java Project as a Dependency in my Android App. This Java Project is a Maven Project.
How can I add this project right into my Android App as a dependency, so I can refer to Classes of the Java/Maven Project withtin my Android App?
The Android App is built using Grandle.
I found the answer.
You need to have Maven installed. Then you build the external project with maven. (you can use e.g. eclipse)
After that, the whole project can be found in your 'local maven repository'. The location is /{USER}/.m2/repository on a Windows machine.
Follow the structure to the project, you've just built.
Convert this path to a name space path:
/{USER}/.m2/repositoryorg/tuda/cdc/pp/classes/1.0
is converted to
org.tuda.cdc.pp:classes-plain:1.0
Pay attention to the double points at the end.
Now add the maevnLocal() thing to you project's grandle file:
allprojects {
repositories {
jcenter()
mavenLocal()
}
}
And then add the following to your app's grandle file under dependencies:
compile 'org.tuda.cdc.pp:classes-plain:1.0'
Then you need to rebuild / sync the project with the changes of the grandle file. After that you are good to go.

Categories