There is a library that I would like to use for my Android App: ez Vcard. However this library uses Maven, which I'm not familiar with. I checked online and my Import Project objection doesn't offer pom.xml soo, how can I add the dependency
<dependency>
<groupId>com.googlecode.ez-vcard</groupId>
<artifactId>ez-vcard</artifactId>
<version>0.9.9</version>
</dependency>
into my project and specifically where?
You don't need a maven project, you can use maven dependencies in gradle projects, you'll just have to use a gradle format of the dependency.
This library appears to be hosted on maven central, so you have to link to this repository host in your global build.gradle:
allprojects {
repositories {
mavenCentral()
}
}
To import this dependency into your project, in your module-local build.gradle file input the following lines:
dependencies {
compile 'com.googlecode.ez-vcard:ez-vcard:0.9.9'
// all the other dependencies...
}
You can actually see here all the different dependency formats (under 'Dependency Information'), from maven to gradle, ivy, sbt and so on, they are all compatible with the repository.
Related
Can anyone explain clairly what is Maven repository in Android Studio ? I try to understand it but I don't find better explainations.
Last time I needed to add some dependencies in my project and they didn't work untill I added a link to Maven and Jcenter in my build.gradle file.
It worked parfectly but my question is just to know What is exactly maven and Jcenter in Android Studio ?
Thanks in advance with your answers.
A maven repository is a "repo", public or private, to store libraries, plugins and in general artifacts.
It is not related to Android Studio or another IDE.
JCenter is one of the maven repo.
JCenter is the place to find and share popular Apache Maven packages for use by Maven, Gradle, Ivy, SBT, etc.
Other common repo used in Android are:
Maven Central
Google maven repo
In a gradle script you can find them in the repositories block:
/**
* The repositories block configures the repositories Gradle uses to
* search or download the dependencies. Gradle pre-configures support for remote
* repositories such as JCenter, Maven Central, and Ivy. You can also use local
* repositories or define your own remote repositories. The code below defines
* JCenter as the repository Gradle should use to look for its dependencies.
*
* New projects created using Android Studio 3.0 and higher also include
* Google's Maven repository.
*/
repositories {
google()
jcenter()
}
Im not Java guy but from fast lookup in google:
Maven is build and dependency management tool (helps in building project and downloading dependencies).
Jcenter looks like repository of available libraries (is source for all dependencies downloaded by maven processes).
I wanna use jetty in my project. I'm building it with Gradle. IntelliJ tells "Cannot resolve symbol jetty" in the following row import org.eclipse.jetty.server.Server; How to fix this? Here are my project directories and gradle dependencies:
Use maven central to grab jetty dependencies. Put the following in your build.gradle:
repositories {
mavenCentral()
}
dependencies {
compile 'org.eclipse.jetty:jetty-webapp:9.4.0.v20161208'
}
I need some retrofit2 dependencies for my java project.
In build.gradle additional repositories are declared:
repositories
{
jcenter()
mavenCentral()
mavenLocal()
}
In dependencies section I declared:
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
So Gradle could not find them.
I used project-report plugin to analyze dependency tree. I got next report:
Interesting thing that before I used 2.0.2 versions for retrofit libraries and Gradle found them.
Any help will be appreciated.
Gradle version 2.12
If using IntelliJ you can include plugin idea or include plugin eclipse, which gives you an option to run gradle idea or gradle eclipseClasspath tasks and refresh the project with updated/freshly added dependencies.
IDE's are not yet ideal supporting gradle.
This is how import dependencies in Android Studio. In this case okhttp:
dependencies {
compile 'com.squareup.okhttp:okhttp:2.5.0'
}
I would like to import a dependency created by myself. For example:
dependencies {
compile 'my_library:1.0.0'
}
At this point if I learn how to create a dependency and import in Android Studio project would be enough.
But I would like host my library on a git(github) repository if possible. This would be awesome.
To achieve it you have some ways:
publish your library (artifact) in central maven or jcenter.
use a github repo and the jitpack plugin
publish the aar in a local maven repo (local o private)
The point 2. is very simple. Just push your codein github and modify the gradle script in the project where you want to use it.
Just add this repo tp your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
and the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
To publish a library in Central Maven or JCenter, it is very long to explain in an answer. Hovewer you can read these posts:
Publish on JCenter
Publish on Central Maven
i had been using eclipse .it was fine with m2 plugin.now i switched to android studio.i dont know how to convert my project to maven project.Any help would be appreciated?
P.s I installed maven in my windows 7. in build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.0'
}
}
mavenCentral() is the central repository shorthand, it's like this tag in the pom.xml.
build.gradle is a Gradle build system build file, to convert to Maven build system you need a pom.xml.
I suggest you import your existing project (which has the pom.xml) view File > Import Project... and select Maven during the import.
Google's suggested way of building Android apps is with Android Studio, which tightly integrates with Gradle and that's the preferred and most advanced way of assembling apks for apps.
Referencing libs
Gradle has what Maven has and more.
<project>
<dependencies>
<dependency>
<groupId>com.github.bumptech.glide</groupId>
<artifactId>glide</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</project>
is the same as (be careful this is not the same as buildscript { dependencies { ... } })
dependencies {
compile 'com.github.bumptech.glide:glide:3.3.1'
}
See the Dependency Information in the Maven Central search for this lib: http://search.maven.org/#artifactdetails%7Ccom.github.bumptech.glide%7Cglide%7C3.3.1%7Cjar