I have imported library module in my project. but I want to convert existing library module to a jar and then I want to use this jar(library module) in my current project.but I did this all process and trying to a specific class in my layout but The following classes could not be found: - com.halilibo.bettervideoplayer.BetterVideoPlayer, this error getting. The main issue is that jar file only contain java classes but module also contains resources, drawable also. I converted my module to jar but specific class is not getting imported.
-
Possible duplicate of [How to make a .jar out from an Android Studio project](https://stackoverflow.com/questions/21712714/how-to-make-a-jar-out-from-an-android-studio-project) – Yajairo87 Aug 23 '17 at 13:21
-
one issue is that jar file only contain java classes and in my module it has resources also – Saket Shrivastava Aug 23 '17 at 13:25
-
1Resources should go under `src/main/resources/`, not under `src/main/java`. If you have done that it should work automatically. – Mark Rotteveel Aug 23 '17 at 13:41
-
Yes it's same but not fetching that class information – Saket Shrivastava Aug 23 '17 at 13:45
1 Answers
You need to create AAR
file instead of JAR
as you have to include resources.
Library reuse has long been available in Java based applications through Java Archive (.jar) files. Android AAR files build upon this concept to allow you to package not only the source code but also the libraries self contained Android resources. The library can have its own manifest and resources and can also optionally provide assets, NDK built libraries, proguard configuration and even its own custom lint filters. This is all bundled into a zip archive that can be published to a repository for your team (or the world!) to get easy access from a Gradle build.
- Start by selecting New Module… from the File menu
- Select Android Library as the module to be created
- Step through the process of using a template for the creation of your library much like creating a new project
One key difference in the created library and an Android application will be the libraries Gradle build script includes apply plugin: com.android.library
instead of apply plugin: com.android.application
.
When you build your project the AAR file will automatically be assembled and placed in these folders
| build
| outputs
| aar
| applib-debug.aar
| applib-release.aar
https://androidbycode.wordpress.com/2015/02/23/building-an-aar-library-in-android-studio/

- 3,234
- 1
- 27
- 30