避免将jar依赖包装到aar中 [英] Avoid packaging jar dependencies into aar

查看:674
本文介绍了避免将jar依赖包装到aar中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个用于工作的android库,我们正在使用一些在maven库中不可用的jar。然而,我们在法律上不允许将这些罐子包装到我们的图书馆中,消费者必须在我们的图书馆之外自行获得这些罐子。



我的问题是, t似乎要求我们图书馆的消费者提供这些罐子(我正在使用包含aar的测试应用程序)。我尝试了这个类似的问题的解决方案无济于事。



我已经尝试在我的gradle文件中将它们设置为提供而不是 compile

  //这些都不能解决问题
编译文件('libs / externalDep.jar')
提供的文件('libs /externalDep.jar')

我也尝试在包装选项中排除它们:

  packagingOptions {exclude'libs / externalDep.jar}`

我可以将它添加到我的 build.gradle 中的 android 标记中, :

  android.libraryVariants.all {variant  - > 
variant.outputs.each {输出 - >
def packageLib = output.getPackageLibrary()
packageLib.exclude('libs / externalDep.jar')
}

它们没有被添加到aar中,但构建测试应用程序给了我:

  com.android.build.api.transformTransformException:
com.android.builder.packaging.DuplicateFileException:
在APK中拷贝了复制文件VERSION.txt
File1:path / to / jar / in / test / app / project / externalDep.jar
File2:path / to / build / intermediates / exploded-aar /.../ jars / classes.jar

为了澄清,我并不关心Maven回购依赖关系,那些工作正常。我只想让使用这个库的人必须得到并添加我们使用的那些罐子。

当然,有一种不太复杂的方式来指定它?

jar文件必须从 mymodule / libs / 更改为 mymodule / ,根据这个答案



然后在 build.gradle 文件中,更改:

编译文件('libs / externalDep.jar')



提供的文件('externalDep.jar')


就是这样。

它不会被复制到aar中,而使用aar的客户端必须提供jar文件自己。
使用aar的应用程序项目可以正常指定编译文件('lib / externalDep')


I'm developing an android library for work and we're using some jars that are not available in maven repositories. However, we are not legally allowed to package these jars into our library, the consumer must get those jars themselves in addition to our library.

My problem is that I can't seem to require the consumer of our library to provide these jars (I'm using a test app that includes the aar). I tried the solutions for this similar question to no avail.

I have tried setting them to provided instead of compile in my gradle file:

// Neither of these seem to fix the problem
compile files('libs/externalDep.jar')
provided files('libs/externalDep.jar')

I also tried excluding them in packaging options:

packagingOptions { exclude 'libs/externalDep.jar }`

I can exclude them by adding this to the android tag in my build.gradle:

android.libraryVariants.all { variant ->
variant.outputs.each { output ->
    def packageLib = output.getPackageLibrary()
    packageLib.exclude('libs/externalDep.jar')
}

They're not added to the aar but building the test app gives me:

com.android.build.api.transformTransformException:
  com.android.builder.packaging.DuplicateFileException:
    Duplicate files copied in APK VERSION.txt
File1: path/to/jar/in/test/app/project/externalDep.jar
File2: path/to/build/intermediates/exploded-aar/.../jars/classes.jar

To clarify, I'm not concerned at all with maven repo dependencies, those are working fine. I just want whoever uses the library to have to get and add those jars we're using too.
Surely there's a less convoluted way to specify this?

解决方案

The jar file must be moved up one level, from mymodule/libs/ to mymodule/ as per this answer.

Then in the build.gradle file, change:
compile file('libs/externalDep.jar')
to
provided file('externalDep.jar')

That's it.
It won't be copied into the aar and clients using the aar must provide the jar file themselves.
App projects using the aar can specify compile file('lib/externalDep') as normal.

这篇关于避免将jar依赖包装到aar中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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