我正在Android Studio中编写一个库项目。我的gradle文件包括gson volley播放服务等...
将我的库嵌入到项目中时,我得到:
有人可以解释在创建库项目时gradle是如何工作的吗?
我该向谁解释集成我的SDK的开发人员,如何排除模块工作以及为什么它在包含我的aar的应用程序中不起作用?
最佳答案
有两种情况需要考虑
依赖项{
编译'com.google.code.gson:gson:2.4'
app/build.gradle
中声明它您可能需要调查哪些重复的库声明了Gson
依赖性。然后,您可以从该库中排除Gson。
您可能要检查此Excluding transitive dependencies
在这里,我将提供一个从库中排除
appcompat-v7
的示例运行此命令以查看依赖关系图树
./gradlew app:dependencies
它将显示依赖关系树,如下面的示例
| \--- com.mikepenz:materialdrawer:4.6.3
| +--- com.android.support:appcompat-v7:23.1.1 (*)
| +--- com.android.support:recyclerview-v7:23.1.1 (*)
| +--- com.mikepenz:materialize:0.5.1
| | \--- com.android.support:appcompat-v7:23.1.1 (*)
| +--- com.mikepenz:iconics-core:2.5.3
| | \--- com.android.support:appcompat-v7:23.1.1 (*)
| \--- com.android.support:support-annotations:23.1.1
找到库后,声明重复的依赖项。您可以开始排除它。
dependencies {
compile("com.mikepenz:materialdrawer:4.6.3") {
exclude module: 'appcompat-v7'
}
}