When creating a new module in Android Studio we can choose between an Android Library and a Java Library. From tinkering with both, my understanding is that an Android Library
has access to Android resources while a Java Library
only has access to Java resources.
So creating a Java Library in Android Studio is like creating a new library in an ordinary Java IDE such as Eclipse. (It even seems to give us access to RMI, which Android does not support.)
Is this correct, are there any other differences one should be aware of?
What is the difference between Android and Java? Java is a programming language, while Android is a mobile phone platform. Android development is java-based (most of the times), because a large portion of Java libraries is supported in Android.
The Android platform contains a large number of shared Java libraries that can optionally be included in the classpath of apps with the <uses-library> tag in the app manifest. Apps link against these libraries, so treat them like the rest of the Android API in terms of compatibility, API review, and tooling support.
The output of an app module is an APK, the package of an Android application. A library is a collection of code that represents something that you want to use in multiple applications or otherwise want to keep in a separate "container" than the rest of the app code.
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.
The android library is a aar and the java library is a jar. Technically speaking both are jars, but their structural composition is slightly different from one another. For example an aar look like this:
res <android resources dir>
values
AndroidManifest.xml
classes.jar
<classpath structure>
<.class's>
R.txt
The java library looks like this:
<classpath structure>
<.class's>
META-INF
As mentioned, the java library cannot include any android resources such as layouts, values, colors, styles. An android library can include android resources, but it cannot contain any raw android assets (i.e. anything you put in the assets folder) It is also the developer's responsibility that resource names don't collide with one another. The android developers recommendation is that you assign unique prefixes for your resource names in each android library. Java libraries cannot reference any android SDK classes such as android.content.Context, etc.) There are some tricks you could do to get around that last restriction, but that involves transforming an aar into a jar. This could be done, as long as you're not using any android resources in the aar. The reason one might want to do that transformation is so you can have a "compileOnly" dependency. Currently, you cannot have a compileOnly dependency on an aar library, but you can on a jar library. This technique is used by OSGI application developers who need to reference interfaces that contain android SDK classes. There is an outstanding request to the android developer's team to modify this compilieOnly restriction.
Like the small description of each project type says, a Android Library is just another Android Application project,often referred to as Module.And Java Library is another word for a java project.The only difference between a module
and a project
is the complexity.
Take a look at this nice description from intellij
about modules and how they differ from :
Module-based project structure
This feature is ideal for complex projects, with multiple internal dependencies, and especially for J2EE projects. Module is a separate logical part of a project that incorporates your working sources, libraries, reference to target Java SDK, etc. It can be compiled, run or debugged as a standalone entity.
A project may consist of one or multiple modules. Modules may depend on each other. Modules and libraries can be easily shared among multiple projects.
source
This is also a good read.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With