Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a maven module to an Android Studio project

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.

like image 228
W.K.S Avatar asked Jul 16 '15 20:07

W.K.S


People also ask

Can we run Maven project in Android Studio?

You can run Maven to build the project from Android Studio.

Where is Maven repository in Android Studio?

Go to buildscript > repositories and configure the Maven repository address for the HMS Core SDK. Go to allprojects > repositories and configure the Maven repository address for the HMS Core SDK.

Does Android use Maven?

The Android Maven Plugin is used to build applications for the Android operating system as well as build libraries to be used in these efforts in AAR and the legacy APKLIB format using Apache Maven.


2 Answers

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'
}
like image 75
Johan Stuyts Avatar answered Oct 25 '22 12:10

Johan Stuyts


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' }
    }``
like image 20
Bamra Lochaz Avatar answered Oct 25 '22 14:10

Bamra Lochaz