How to import Maven dependency in Android Studio/IntelliJ?

后端 未结 5 423
后悔当初
后悔当初 2020-11-29 18:54

I\'ve created a new Android project using the default wizard in Android Studio. Compiled, and deployed the app to my device. All is well.

Now I want to import an ext

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 19:31

    I am using the springframework android artifact as an example

    open build.gradle

    Then add the following at the same level as apply plugin: 'android'

    apply plugin: 'android'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
       compile group: 'org.springframework.android', name: 'spring-android-rest-template', version: '1.0.1.RELEASE'
    }
    

    you can also use this notation for maven artifacts

    compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
    

    Your IDE should show the jar and its dependencies under 'External Libraries' if it doesn't show up try to restart the IDE (this happened to me quite a bit)

    here is the example that you provided that works

    buildscript { 
        repositories { 
            maven { 
                url 'repo1.maven.org/maven2'; 
            } 
        } 
        dependencies { 
            classpath 'com.android.tools.build:gradle:0.4' 
        } 
    } 
    apply plugin: 'android'
    
    repositories {
        mavenCentral()
    }
    
    dependencies { 
        compile files('libs/android-support-v4.jar') 
        compile group:'com.squareup.picasso', name:'picasso', version:'1.0.1' 
    } 
    android { 
        compileSdkVersion 17 
        buildToolsVersion "17.0.0" 
        defaultConfig { 
            minSdkVersion 14 
            targetSdkVersion 17 
        } 
    } 
    

提交回复
热议问题