如何释放与另一个Android库项目依赖关系的AAR? [英] How to release an AAR with another android library project dependency?

查看:158
本文介绍了如何释放与另一个Android库项目依赖关系的AAR?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的开发项目结构:

 
projectFolder
|
+ - App
|
+ - MyLib
|
+ - 图书馆
|
+ - LibA

MyLib 取决于LibA,我打包了 MyLib 作为AAR并将其发布到Maven repo,但是当我在另一个项目( TestProj )中包含 MyLib 作为远程aar依赖项时,无法解析 LibA 的依赖关系, LibL 未包含在 MyLib 版本中),
这是build.gradel在 TestProj 的应用程序文件夹中:

 依赖关系{
编译fileTree(dir:'libs ',包括:['* .jar'])
compile('xxx.xxxxxx:yyyyy:1.0-SNAPSHOT@aar'){
transitive = true
}
}

这里是 MyLib的build.gradle

 依赖关系{
编译fileTree(dir:'libs',include:['* .jar'])
compile项目(':Libraries:LibA')
}

如何释放带有 LibA 的MyLib 已经打包了编辑在AAR?

解决方案

我自己回答这个问题。最后,我将 MyLib 中的 build.gradle 更改为:

 依赖关系{
compile fileTree(dir:'libs',include:['* .jar'])
provided project(':Libraries:LibA')
}

so LibA 只会在 MyLib TestProj 在编译时不会再要求 LibA 依赖关系。注意这可能会在运行时导致NoClassDefFoundError,所以你必须告诉那些使用你的库的人将LibA自己包含在他们项目的build.gradle中。



起初,我正在寻找一种将 LibA MyLib 打包的方法,但它似乎很难。 / p>

看到这个问题: Android Studio如何从多个库项目打包单个AAR?


Here is my development project structure:

projectFolder
  |
  +--App
  |
  +--MyLib
  |
  +--Libraries
      |
      +--LibA

MyLib depends on LibA, I have packaged MyLib as an AAR and release it to a Maven repo, But when I include MyLib in another project(TestProj) as a remote aar dependency, I get build error(can't resolve dependency of LibA, LibA is not included with the release of MyLib), This is the build.gradel in app folder of TestProj:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile ('xxx.xxxxxx:yyyyy:1.0-SNAPSHOT@aar'){
      transitive = true
  }
}

And here is the build.gradle of MyLib:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile project(':Libraries:LibA')
}

How can I release MyLib with LibA already packaged in the AAR?

解决方案

Answer the question myself. finally I changed the build.gradle in MyLib to:

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  provided project(':Libraries:LibA')
}

so LibA will only be used in the build process of MyLib, TestProj will not ask for the LibA dependency anymore at compile time. NOTE THAT this may cause NoClassDefFoundError at runtime, so you must told the guys who used your library to include the LibA themselves in build.gradle of their project.

At first, I was looking for a method to package LibA with MyLib, but it seems diffcult.

See this question: Android Studio how to package single AAR from multiple library projects?

这篇关于如何释放与另一个Android库项目依赖关系的AAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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