How to import Maven dependency in Android Studio/IntelliJ?
As of version 0.8.9, Android Studio supports the Maven Central Repository by default. So to add an external maven dependency all you need to do is edit the module's build.gradle file and insert a line into the dependencies section like this:
dependencies {
// Remote binary dependency
compile 'net.schmizz:sshj:0.10.0'
}
You will see a message appear like 'Sync now...' - click it and wait for the maven repo to be downloaded along with all of its dependencies. There will be some messages in the status bar at the bottom telling you what's happening regarding the download. After it finishes this, the imported JAR file along with its dependencies will be listed in the External Repositories tree in the Project Browser window, as shown below.
Some further explanations here:
http://developer.android.com/sdk/installing/studio-build.html
How to import a maven module to an Android Studio project
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'
}
Import Maven dependencies in IntelliJ IDEA
IntelliJ should download and add all your dependencies to the project's classpath automatically as long as your POM is compliant and all the dependencies are available.
When importing Maven projects into IntelliJ an information box usually comes up asking you if you want to configure Auto-Import for Maven projects. That means that if you make any changes to your POM those changes will be loaded automatically.
You can enable such feature going to File > Settings > Maven > Importing, there is a checkbox that says "Import Maven projects automatically".
If that doesn't help, then I would suggest to make a full clean-up and start again:
- Close your project window (and IntelliJ) and remove all
*.iml
files and all.idea
folders (there should be one per module) - Run
mvn clean install
from the command line - Re-import the project into IntelliJ and pay attention when it asks you to enable auto-import
IntelliJ 2016 Update:
The Import Maven Projects automatically setting has been moved to Build, Execution, Deployment > Build Tools > Maven > Importing in your IntelliJ preferences.
Related Topics
Android.Intent.Action.Screen_On Doesn't Work as a Receiver Intent Filter
See Android Recent Task Executed by the User
How to Store and Retrieve a Byte Array (Image Data) to and from a SQLite Database
How to Store Image Retrieved from Url in a SQLite Database
Bufferoverflowexception When Building Application
Mpandroidchart - Adding Labels to Bar Chart
Speed Up 'Navigation Drawer' Animation Speed on Closing
What's the Purpose of Item-Id's in Android Listview Adapter
What Is the Real World Accuracy of Phone Accelerometers When Used for Positioning
Display Unity Scene as Sub View in Android Studio
Android Access to Remote SQL Database
How to Load a Image from Assets