Our Android project is a monorepo containing couple of app modules, and even more library modules. One of the libraries should be also accessible to other developers so we have decided to deploy it on MavenCentral. Let's call it the library L. This library however also contains dependency within the monorepo to another module (let's call it a module m). In order to test whether the library L is correctly accessed by the other developers, we have created a demo Android project. But when trying to include the dependency of the publish library L, generally all works great except that the module m could not be resolved in the demo Android project.
Understandingly, the module m could not be resolved due to it being available neither on MavenCentral nor as an AAR file. We cannot publish the module m on MavenCentral since it should not be available for others to get, but including it as an AAR file, doesn't work either. Terminal throws an error:
Direct local .aar file dependencies are not supported when building an AAR. The resulting AAR would be broken because the classes and Android resources from any local .aar file dependencies would not be packaged in the resulting AAR. Previous versions of the Android Gradle Plugin produce broken AARs in this case too (despite not throwing this error).
So the question comes - how can a project - that includes a submodule that can't be exposed, be published to repository like mavenCentral?
Related
I work for a company which has a android mobile application developed by an offshore team. I have access to GitHub repositories.
I am piecing together the android app block by block and it is giving me hell.
How do I distinguish between module, libraries, jar, library projects, gradle projects, aar and jar. Can someone please give me a practical definition. NOT out of a freaking google search. I have Google too.
PS yes I am a noob and not proud of it.
I'm just giving a brief description about each of these. I hope I'm clear.
Module : A Module is an component of your application that can build / test independently and re use it in another application if required.
Libraries : AAR files, JAR files etc.
JAR : Java library
AAR : Just like JAR, only difference is that it also contains android specific files like resources etc.
Gradle Project : Gradle is just a build system which is used by Android Studio to build the android project. Its very much powerful as compared to the build system which was used in Eclipse earlier.
Library Project : An Android library project is similar to an Android app project in that it also includes a project manifest file in the project’s root directory. Also, this directory contains src, res, and other directories that you also find when building an app project.
However, there is a significant difference. You cannot compile a library project into an APK file because a library project doesn’t describe an app. Instead, it provides reusable code and resources that contribute to an app when the app’s project and source code refer to the library project. At build time, this code and these resources are merged into the app’s APK file.
To explain more on this, let me give you an example :
Say you want to use a networking library volley for making API calls, now since this is an open source library from Google you can clone it making customisations as per your requirement.
You can make volley library as your Library Project, build it independently, unit test, etc.
Now say you started building an application where you need to make HTTP calls so you need to add volley library to your project. You have two choices for that :
Compile your library project volley, generate the aar file and add it your app Project.
Add Volley as module in your project. (If you choose this option you can make changes to volley library in same studio project since it will act as a component in your project)
Please let me know if something is not clear.
1.) Module
A module is a collection of source files and build settings that allow you to divide your project into discrete units of functionality. Your project can have one or many modules and one module may use another module as a dependency. Each module can be independently built, tested, and debugged.
There are 4 type of module in Android Studio.
Phone & Table Module
Android Wear Module
Android TV Module
Glass Module
2.) Support Library
The Android Support Library offers a number of features that are not built into the framework. These libraries offer backward-compatible versions of new features, provide useful UI elements that are not included in the framework, and provide a range of utilities that apps can draw on.
Support libraries provide a range of different features:
Backward-compatible versions of framework components.
UI elements to implement the recommended Android layout patterns.
Support for different form factors.
Miscellaneous utility functions.
3.) Jar file
JarFile is used to read jar entries and their associated data from jar files.
for more detail visit this : https://developer.android.com/reference/java/util/jar/JarFile.html
4.) Android Library Project
The Android team introduced a new binary distribution format called Android ARchive(AAR). The .aar bundle is the binary distribution of an Android Library Project.
An AAR is similar to a JAR file, but it can contain resources as well as compiled byte-code. This allows that an AAR file is included in the build process of an Android application similar to a JAR file
5.) Gradle and Gradle Project
Gradle is an automated build toolkit that allows the way in which projects are built to be configured and managed through a set of build configuration files. This includes defining how a project is to be built, what dependencies need to be fulfilled for the project to build successfully and what the end result (or results) of the build process should be. The strength of Gradle lies in the flexibility that it provides to the developer. The Gradle system is a self-contained, command-line based environment that can be integrated into other environments through the use of plug-ins. In the case of Android Studio, Gradle integration is provided through the appropriately named Android Studio Plug-in.
for more detail visit this : http://www.techotopia.com/index.php/An_Overview_of_Gradle_in_Android_Studio
I have around 49 android apps. All of them have a reference to one library project. Till now, I have been developing on eclipse. Now, I am moving to Android Studio. What's the way to reference a library project in Android Studio?
I tried the answer mentioned in
How to include library projects in Android Studio that are stored in a separate git repository?
This actually copies the library project within the app project. So, If i change anything in the library, it will not be reflected in 48 other apps.
How about creating a library project, then adding it to Bintray and including in your projects dependencies?
Follow this guide up to the point where you'll be able to include your library like this:
repositories {
maven {
url 'https://dl.bintray.com/$DEVELOPER$/maven/'
}
}
...
dependencies {
compile 'groupId:artefact:0.0.1'
}
Then consider sharing it on jCenter / mavenCentral.
Beware, that sharing code privately on Bintray is not free. This solution would be really optimal for opensource library though
you can have your library code in git and add it to your application projects as a sub module. so if you modify the library from one project you can push the changes to the library git and then from other application you can pull those changes. it would be better to keep separate branch of library for each application so as not to conflict with the usage on modification.
i have explained the steps to add a git library as a sub module in here: Android Studio, how to add my own git repository as a library project(sub module)?
I have an app and a library that I wrote. My issue is that when including the library as a jar (I see all of the classes included when decompiled),the app itself cannot interact with sub-classes from decencies of the library.
What is a good way to ensure that by including the library the app also pulls in the required dependencies?
What is a good way to ensure that by including the library the app also pulls in the required dependencies?
The best way is to publish the library in a maven repo (private or public).
In this way with gradle you will be able to download the library and all dependencies (described in the pom file).
Adding the jar (or an aar) in a project you have to add also the nested dependencies in the project since the jar and the aar don't contain the nested dependencies.
EDIT:
When I use the response of How to manually include external aar package using new Gradle Android Build System I have an error.
BASE:
I never use AAR file, with the release of Android Studio we can use it.
But I don't find any explanation to use it.
Do you know how to use it?
It's necessary to make some things like ask for the permissions or create the dependencies?
Thanks
AAR format is a jar file containing a compiled Android Library project. Here's some info on what is inside an AAR file
What this means for app developers is that instead of (the old way):
Downloading the source code of a library project
Building it in eclipse
Setting your application project to depend on the local library project
You can instead add the dependency specification to your project/app/build.gradle's dependencies block: compile 'fr.baloomba:viewpagerindicator:2.4.2'
Then gradle (on the next build) searches for the aar file in a central binary repository, downloads the library and allows you to use it's functionality in your project. ( ex: http://search.maven.org/remotecontent?filepath=fr/baloomba/viewpagerindicator/2.4.2/viewpagerindicator-2.4.2.aar )
You can also search the central repository's web interface for libraries to depend on. Once you've clicked on a library to add to the project, click "Gradle/Grails" under "Dependency Information" to copy the line to add to build.gradle.
In my opinion this is a huge improvement.
You don't need to add any permissions to the app, either way, adding a Library project dependency is a compile time thing, not runtime or user-facing.
My desired end result is to have a Project that can output different productflavors of Mobile, Tv, and Wear apps, that share the same code-base. So I would like the codebase to be a dependency for all three app-types, where each app module would only contain activities and interaction with the codebase.
My first idea was to add a "Android Library Module" to my newly created project, but I noticed that this is really just a new app module with its own resources and everything. I would like the codebase to function more like a "Java Library", but it needs access to packages like "android.graphics.Color".
So in short, is the correct way of achieving this result to use a java library that has a reference to an android sdk or am i just going about this the wrong way?
Continuation of this question at:Does an Android Library need a manifest ,app_name,Icon?
There's no in-between. If you want access to Android APIs, then the library needs to be an Android library so that the build system can properly link it in to dependent projects. It's true that Android Libraries have resources and other things you may not need, but you can ignore those bits and treat it essentially as a plain Java library if you wish. Even if you're not using resources, you may find useful the ability to specify AndroidManifest.xml attributes to be merged into the dependent app.
The Android Library project doesn't build a fully-fledged APK as its output; it generates an AAR, which is conceptually similar to a JAR archive, but has resources and meta-information useful to Android projects.
Supplemental answer defining terms
The Android Studio documentation defines a module as follows:
A module is a collection of source files and build settings that allow
you to divide your project into discrete units of functionality. Your
project can have one or many modules and one module may use another
module as a dependency. Each module can be independently built,
tested, and debugged.
So basically a module is a subproject in your bigger project.
Types of modules
Android app module - The app module is usually what you are working with in a normal project. When you compile it you get an APK file that will run on a device. Here are the different types of app modules that exist:
Phone & Tablet Module
Android Wear Module
Android TV Module
Glass Module
Library module - The purpose of a library is to share code. For example, you could have a project with a couple different app modules. The common code that they both use could be located in the library.
Android Library - In addition to Java code, this allows you to also include Android resource files and a manifest. If you are making an Android project and are wondering what kind of library to use, then choose the Android Library. When compiled it creates an AAR (Android Archive) file.
Java Library - This only allows you to include Java code files, no Android resource files. This is useful for cross-platform code sharing. When compiled it creates a JAR (Java Archive) file.
Google Cloud module - This type of module is the Google Cloud backend for communication with your client side app.
One additional point that I've not seen well documented: An android library module can have a dependency on another android library module or java library module, but a java library module cannot have a dependency on an android library module.