简体   繁体   中英

How to create jar file from Android Library project

我有一个Android库项目,需要将其转换为jar文件,并在我的Android项目中使用它。就像我们在添加网络集成上所做的那样,有什么方法可以实现吗?

An Android project can't really fit into a .jar file, unless you just wanna use the compiled java files, which you would certainly have done it via a normal Java library project instead of a Android Library Project in first place.

Android Library Projects are packaged into aar files. Read more about it here: http://tools.android.com/tech-docs/new-build-system/aar-format and it is automatically handled by Gradle builds and late Android Maven scripts...this last one used to use a ' apklib ' format which has been deprecated to be replaced by aar format. You can read more about it here: https://code.google.com/p/maven-android-plugin/wiki/ApkLib

I've done this before.

But, due to my requirements, i only needed implementation (no android specific resources). Although you can still include Android actual code (if the project you're going to use it in is also an Android project in which you can load the SDK which includes the classes you're exporting in the jar)

Now the .jar file that is automatically generated in the bin folder, will not allow you to do this because it includes all the Android's project resources (which is not understood in the Jar format). Therefore, you must exclude all except the src folder. Note : Make sure you also exclude the files in the root folder of the project (ie, AndroidManifest.xml, etc .. )

In Eclipse : Project properties -> Export -> Jar -> (Include only src folder)

If you're project library includes native code ( NDK ), there is a few other workaround that you need to do to get it to work. If this is the case, comment below, i'll help you out.

Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM