如何在我的Android库中包含依赖项 [英] How do I include dependencies in my android library

查看:100
本文介绍了如何在我的Android库中包含依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个android sdk,现在我想分发它,但它的依赖项存在问题.我正在使用gradle和android studio.

I am writing an android sdk and I now want to distribute it but I am having problems with its dependencies. I am using gradle and android studio.

我的sdk依赖于volley和gson,我将它们作为jar添加到我的sdk中.每当我尝试创建要在单独的客户端应用程序中使用的aar或jar时,当我的sdk尝试引用凌空(因为它未包含在aar或jar中)时,我总是会崩溃. 关于我应该如何做的任何想法?我已经开始尝试制作胖罐子了,但是没有成功.

My sdk has a dependency on volley and gson and I have them added as jars with in my sdk. When ever I try to create an aar or a jar to use within a separate client app I always get a crash when ever my sdk tries to reference volley as it wasnt included in either the aar or jar. Any ideas on how I should be doing this? I have looked into creating fat jars with out much success.

我还尝试过使用如下所示的远程依赖项,但是即使在客户端应用程序中构建了gradle之后,仍然不包括volley和gson. 这是我目前在sdk build.gradle

I have also tried using remote dependencies like below but even after a gradle build in the client app both volley and gson are still not included. This is currently what I have in my sdk build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.google.code.gson:gson:2.3'
}

然后在我拥有的客户端构建gradle中

then with in the client build gradle I have

repositories {
    flatDir {
        dirs 'libs'
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name:'mysdk-1.0.0', ext:'aar')
}

我正在使用./gradlew clean build来构建我的SDK的aar和jar 谁能告诉我在我自己的库中包含依赖项的正确方法吗?

I am using ./gradlew clean build to build the aar and jar of my sdk Can anyone tell me the correct way to include dependencies in my own lib?

推荐答案

在您的客户端中,像这样更改您的依赖项块:

In your client, change your dependencies block like so:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name:'mysdk-1.0.0', ext:'aar') {
        transitive = true
    }
}

这也应该引入传递依赖.

This should pull in your transitive dependencies as well.

这篇关于如何在我的Android库中包含依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆