18

I would like to include retrofit as a module in my Android Studio project. The problem is that retrofit is a maven project and so Android Studio won't let me import it. Is there a way around this?

A similar question has been asked before, but it received no answers.

W.K.S
  • 9,787
  • 15
  • 75
  • 122
  • 1
    What is the issue that you are running into? What have you tried? – Ethan Aug 12 '15 at 04:39
  • As IntelliJ itself supports Gradle and Maven modules in the same project, maybe using IntelliJ with an Android plugin instead of Android Studio would allow for this, but I'm not sure if this is possible to add Android support to a plain IntelliJ, anyone knows? – Jaime Hablutzel Nov 12 '15 at 23:11

6 Answers6

18

Use a custom group and/or artifact in the POM of your clone, so your clone cannot be confused with the original.

Build and install your clone of Retrofit using Maven as usual: mvn install. (Using the command line or an IDE other than Android Studio.) You have to build your Retrofit clone manually after each change you make to it, for Gradle to see the changes.

Add the local Maven repository to your Gradle script. See https://docs.gradle.org/2.5/dsl/org.gradle.api.artifacts.dsl.RepositoryHandler.html#org.gradle.api.artifacts.dsl.RepositoryHandler:mavenLocal():

repositories {
    mavenLocal()
}

Add the GAV of your clone as a dependency to your Gradle script:

dependencies {
    compile 'com.yourgroup:retrofit:1.9.0-custom'
}
Johan Stuyts
  • 3,607
  • 1
  • 18
  • 21
7

Go to your project then goto the app. You will see a build.gradle file under app (DO NOT use the gradle under gradle folder but the ine under app folder). Add this line.

 dependencies {
....
compile 'com.squareup.retrofit:retrofit:1.9.0'

...

}

Then, make sure that you define the repository details in directory and add the url.

 repositories {
        flatDir {
            dirs 'libs'
        }
        maven { url 'http://download.crashlytics.com/maven' }
    }``
Binoy Babu
  • 16,699
  • 17
  • 91
  • 134
  • 2
    Thanks but I want to include a local clone of Retrofit, I don't want to fetch it from the maven repository – W.K.S Aug 07 '15 at 07:34
  • 1
    How can I include this library. I'm trying from last 4 hours but in vain. Please suggest something. The link is https://github.com/Almeros/android-gesture-detectors – Husnain Iqbal Apr 22 '16 at 13:05
3

See Migrating from Maven to Gradle. Just execute gradle init.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
dhaag23
  • 6,106
  • 37
  • 35
  • Worked for me! After converting to Gradle via 'gradle init', go to your project tree root -> right-click -> New -> Module -> Import Grade Project -> Select the converted project. – AmitW May 03 '17 at 08:24
  • 1
    Doesn't work for me, `gradle init` only works for very basic POM files (converting dependency elements to implementation elements etc), my POM has a dependencyManagement block with import-scoped dependencies and `gradle init` just ignores that, meaning the generated build doesn't work – Adam Burley Jul 26 '21 at 21:03
  • It's not straightforward – EnthusiastiC Jan 02 '23 at 16:21
1

Just add it to the dependencies { } block of your application's build.gradle file.

dependencies {
    compile 'com.squareup.retrofit:retrofit:1.9.0'
}
Mark Vieira
  • 13,198
  • 4
  • 46
  • 39
  • 3
    Thanks but I want to include a local clone of Retrofit, I don't want to fetch it from the maven repository – W.K.S Aug 07 '15 at 07:34
0

In android studio simply go to project structure -> module you want to add retrofit -> dependencies tab -> plus(add) -> library dependency and then type retrofit in text box and select com.squareup.retrofit:retrofit and add to your dependencies

nariman amani
  • 263
  • 6
  • 21
0

another soluation , just download latest jar file from https://github.com/google/retrofit then goto new module ->create module of jar->select the path of that jar file->then on your project module gradle dependency add(implementation(':name retrofit module').

jyothi
  • 1