Gradle: Building different jars for Java and Android - java

I recently completed the initial work on a Firebase library. This library is currently implemented for use with Firebase-server (Java), but I would also like to build a version for use with Firebase-android. Making the Android version should be a simple matter of changing the Firebase SDK being used and implementing the Android version of my Firebase wrapper interfaces.
When building the project, I would like it to create a separate artifact for both Java servers and Android. I imagine this is something that could be done using Gradle. How would I go about doing this?
As a followup question, would it be necessary or a good idea to include the respective Firebase SDK dependencies in my build artifacts?

I believe the process I was looking for is known as creating a multi-project Gradle build.
I created three modules: core, server, and android. The core module contains the code required by the two derivative modules, while the derivative modules import the Firebase SDKs they need and implement the core interfaces in the way they require.

Related

Use both versions of Google cloud resource management Java API in the same project

Currently I'm working on a Java project which needs to have Google Cloud integration.
I need to get all folders and all projects from a service account using Cloud Resource Management API.
The problem is folders are new and only available in version 2 of the API, but projects are in version 1. I cannot include 2 jar files because the there will be conflict and only one of them will be used.
Does anyone have similar issue and solved the problem?
Thanks.
In simple terms, you can make two programs, one for each API, and make them talk to each other (Have one launch the other).
Have the version 2 program grab all the folder info you need, and the pass the relevant parts to your program with the version 1 API.
It's not great, but it works.
Better yet you could make a converter to update each project as it is opened, so that it will only use the version 2 API going forward.

Sharing Java model classes between Eclipse (Maven) and Android Studio (Gradle)

I have created a Java webservice in Eclipse which provides a REST API and an Android project (in Android Studio) which consumes said API. The problem I am facing right now is that I want to use the same model/domain classes in both the Java webservice and the Android application (the webservice uses Maven whereas the Android application uses Gradle).
At the moment I am manually mirroring any changes I make to the model classes in both the Java webservice and the Android project. This is however very tedious and obviously not a good solution.
My questions is how I can solve this issue. I thought about creating a Maven module containing the model classes and importing them in the Java webservice and the Android project. However I am uncertain if this a solution which will work.
Are there any better (and maybe obvious) solutions I am not seeing? Thanks in advance for any help!
Edit: Is it actually smart to share the whole model classes? I clearly don't want to use all the attributes from the webservice in the Android project (e.g. passwords will never be stored in the Android project but have to be stored in the webservice).
You could create a library for your model, and share it between the provider (REST API) and the consumer (your Android app). That could be done with a multi-module maven project, where you can have a module for your model layer and another module for your REST API layer that uses the previous model artifact.
Doing so, you could install the model library in your local repository (or deploy it in whatever centralized repository you may need) and use it from your Android application.
But I would advice you against sharing the model that way, because you would be tight-coupling your consumer and provider at the model level. That would make it harder to evolve them independently.

Combine Java library with Android product flavor

I'm trying to apply the equivalent of Android's product flavor with a Java library. My project configuration can be resumed in:
App module (type: Android application)
Api calls module (type: Java library)
The app module only has one product flavor (the default one) and the api module will have several ones, one per environment (local, preproduction server and production server).
I've been checking some questions and I've found this one that achieves something similar to product flavors with only Java projects. There is also this other question that explains how to get android libraries with product flavors.
My question is: can an Android app module define a dependency on a Java library module defining the library configuration?
Should I refactor my architecture making the Android app module has several product flavors, in each one passing the configuration parameters to the Java library?

How to contribute modules in Play Framework 2.0?

The original Play Framework 1.x had an elegant and simple module management system. Coupled with the Play repository, it was a great way to quickly enhance an application with third party components & libraries.
With Play 2.0, things are very different.
How does one contribute the so called "modules"?
Quoting Guillaume Bort from the mailing list:
modules are just standard subprojects.
[...] now as everything is compiled, your module routes file must
define its own route for controllers.Assets.at
By the way, the route inclusion between modules is not ready yet. Will
work on that soon.
Simply explained, now any SBT project can be a Module. Which is (somehow) an improvement, as you can import existing projects without having to convert them to a specific "Play framework module project" format.
For example, in Play 1.x you have several modules which provide a lot of the logic inside a jar file that belongs to the "Play Module" project. The source of that jar is not in the same project, which may complicate debugging. With the new system you can simply import the sbt-jar project (no need to create a wrapper project) or, if you are importing a Play project that contains that other project, you can follow the dependencies more easily.
An additional benefit is that you can reuse full Play projects as Modules. Which means that your Admin module for application X can be created as a full and independent Play project and then reused in Application Z by just adding a line to the Sbt build file. Lots of possibilities in there.
If you want to create/contribute a module for Play 2.x and don't know where to start check out this two-parts tutorial.
Part 1
Part 2
Have a look at https://github.com/playframework/modules.playframework.org/wiki.
This Play 2.0 appliction will be the official Play Framework modules directory, hosted at modules.playframework.org, and will replace the original Play 1.x modules page.
It's in an very early stage at the moment and help is certainly needed. Contribution is possible.
Check out: https://github.com/playframework/modules.playframework.org

Creating Android Modular Applications on Eclipse

I am currently porting a framework for building applications on J2ME to Android. This framework consists of several projects that compile to libraries (jars). Each individual JAR can contain graphical data (resources, J4ME screens, etc.). Every project generally has a well defined entry point (module). When someone wants to build an application using the framework he must only create a Midlet project and add library dependencies and use the imported classes.
We have been using the same approach to develop the Android framework. In this case we have only used normal Java Projects inside Eclipse that compile to jar libraries. These projects have dependencies with the Android Framework (android.jar). When building a new application we create an Android Project inside Eclipse and add the dependencies.
Our next step is to build more advanced modules for Android that can also contain graphical information (Activities, Dialogs, Literals, Drawables, etc.). So far only an Android Eclipse project was needed (the end application), that contained all the graphical-related classes and resources. It seems that when using resources (literals, drawables, etc.) the only approach is to create an Android Application, since the resources are only referenceable by means of an integer handler automatically created by ADT plugin (R.XXX). So building graphical modules may not be built by means of plain Java jar projects.
Android developer information explains that modular applications are feasible, but I have not found a concise tutorial explaining the process, but some tips such as how to prevent an error to ocurr when an application invokes an intent made available by other application. This is valid when building applications that use resources from other applications. I do not need several installed applications on the system, but one built from several components.
Has anyone experience developing with similar requierements? Any good tutorial or tips to start out?
It seems that the only available way is described here as hinted by the accepted answer of this other question.
The solution however is rather new (it only works with latest Android SDK tooks R6 and SDKs 2.0.X are left out of support). It has some major caveats on which I hope Google is already working:
No binary library linking. This means that the main application needs access to sources (in Eclipse implies having all the linked library projects open).
The names of resources (layouts, drawables, etc) are treated globally. This means that if you have two "main.xml" layouts, only the most relevant (uppermost in library list) will be used.
Missing funcionalities/BUGs. The documentation states that exported activities of a library project must only be declared in AndroidManifest.xml of library project. This does not work in current version. Comments inside TicTacToe example hints that this is the desired working, but for current release of Android Tools used activities from library projects must be explicitly defined in AndroidManifest.xml of main application project.

Categories