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.
Related
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
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.
I'm going to use the Facebook SDK in my application. I must open the build.gradle and add the following code:
repositories {
mavenCentral()
}
But where in Eclipse can I open this for my project? I have googled, but can't find any relevant information.
you need to add gradle plugin to eclipse and then configure your project to use gradle. For more reference check out the answer:
https://stackoverflow.com/a/14616328/3541465
OR
You can add Facebook sdks manually in eclipse. First import the Facebook sdk in eclipse then add it into your project.
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')
I have a library that is being built in Eclipse, but I would like to upload it to jCenter to be used as a gradle dependency in an Android Studio project. I have tried building the gradle files in Eclipse, making a Bintray account, and trying to link it to jCenter but nothing seems to go through. It may be because I have not published it on Bintray, but I also do not see any option to publish it anyway.
You need to add Bintray plugin to your Gradle project. Please see the examples.