How To Add Maven Dependency (Android Studio)

橙三吉。 提交于 2019-12-07 05:49:22

问题


I have this code below..

<dependency>
    <groupId>me.gujun.android.taggroup</groupId>
    <artifactId>library</artifactId>
    <version>1.4</version>
    <type>apklib</type>
</dependency>

But where do you put this in Android Studio? I've already placed a dependency in build.gradle which is compile 'me.gujun.android.taggroup:library:1.4@aar'


回答1:


In Android Studio 3.0 and above, you can just copy

<dependency>
    <groupId>me.gujun.android.taggroup</groupId>
    <artifactId>library</artifactId>
    <version>1.4</version>
    <type>apklib</type>
</dependency>

into build.gradle, and it automatic converts it to:

implementation 'me.gujun.android.taggroup:library:1.4'



回答2:


I had a similar issue just now. I was trying to use khttp in an Android app. Here's the XML that library gave me:

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

...and

<dependency>
    <groupId>com.github.jkcclemens</groupId>
    <artifactId>khttp</artifactId>
    <version>-SNAPSHOT</version>
</dependency>

What I ended up doing was editing the root build.gradle file and adding this:

allprojects {
    repositories {
        maven {
            url "https://jitpack.io"
        }
    }
}

Then, I edited the app's gradle file, and added this line to the existing dependencies { .... } section:

compile 'com.github.jkcclemens:khttp:master-SNAPSHOT'

Once done, I hit the "try again" or "sync" button on the yellow bar that appeared to get Android Studio 3.0.1 to recognise the changes I'd made.

I followed the instructions on the JitPack homepage.



来源:https://stackoverflow.com/questions/41506976/how-to-add-maven-dependency-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!