[英]Android Studio exporting Android library project as jar
I'm developing Android Library project. 我正在开发Android库项目。 In Eclipse when I want to export it as a jar
file: 在Eclipse中,当我要将其导出为jar
文件时:
src
and thats it (no res
etc!) - This is the requirements from my Library... 我从src
手动选择了一些软件包,多数民众赞成(没有res
等!)-这是我图书馆的要求... Now I migrated to Android Studio, so following some SO discussions I came up with this under gradle.build
: 现在我迁移到Android Studio,因此gradle.build
一些SO讨论之后,我在gradle.build
下提出了这个gradle.build
:
task clearJar(type: Delete) {
delete 'build/outputs/mysdk.jar'
}
task makeJar(type: Copy) {
from('build/intermediates/bundles/release/')
into('build/outputs/')
include('classes.jar')
rename ('classes.jar', 'mysdk.jar')
}
makeJar.dependsOn(clearJar, build)
When I then integrate the Jar in some Android App things not working indicating something went wrong with the process of exporting the Jar (The library project is free of errors/warnings etc.). 然后,当我将Jar集成到某些Android App中时,无法正常工作,表明导出Jar的过程出现了问题(库项目中没有错误/警告等)。
How to achieve similar behaviour of export to jar of eclipse in Android Studio? 如何在Android Studio中实现类似的导出到jar的行为?
Thanks, 谢谢,
You don't want to produce a jar
file as the res/
folder will be missing and anything that references the R
file in your code will fail when executed. 您不希望生成jar
文件,因为res/
文件夹会丢失,并且在代码中引用R
文件的所有内容在执行时都会失败。 This is because the jar
format doesn't support android res
. 这是因为jar
格式不支持android res
。 You want your build to instead target aar
format. 您希望构建以aar
格式为目标。 This is simple using gradle. 使用gradle很简单。 Instead of applying the application plugin ( apply plugin: 'com.android.application'
) just apply the library plugin ( apply plugin: 'com.android.library'
). 无需应用应用程序插件( apply plugin: 'com.android.application'
),只需应用库插件( apply plugin: 'com.android.library'
)。
Then the gradle build
will produce an aar
file which will contain all your resources. 然后, gradle build
将生成一个aar
文件,其中将包含您的所有资源。
Developers who are still using eclipse will be familiar with how to import aar
files because that is the android standard. 仍在使用eclipse的开发人员将熟悉如何导入aar
文件,因为这是android标准。 If they have not learned yet there are plenty of SO posts to help. 如果他们还没有学会,那么有很多SO职位可以提供帮助。
Developers who are using gradle or maven will have no problems consuming your sdk 使用gradle或maven的开发人员在使用您的SDK时不会有任何问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.