Creating Android Modular Applications on Eclipse - java

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.

Related

What exactly does "Dynamic Web Module" facet add to an eclipse project

Everybody in the world, except me, seems to know what exactly the "Dynamic Web Module" facet is adding to a project. Web search reveals tons of responses how to recover from various errors originating in more or less unwanted changes in the version of this facet, but there is hardly any information about what the facet actually does.
So my questions are:
What exactly does the "Dynamic Web Module" facet add to my eclipse project?
Why should I want this to happen?
Why do my colleagues using IntelliJ, Visual Studio Code etc. –where this concept does not seem to exist– have no problem?
Keeping mind that I didn't decide on these names (and I grumbled about them myself at the time)... The term dates back to the early J2EE Tutorials, like https://docs.oracle.com/cd/E17802_01/j2ee/j2ee/1.4/docs/tutorial-update2/doc/WebApp3.html The tutorial would explain that J2EE web modules are the web applications from the then Java Servlet specification. J2EE loved to subsume the other specs and use its own naming for things that already had names. The doc and tools often followed suit.
It also mentions that they can contain static web resources, and in fact you can run web modules that only contain static resources. So WTP has the concept of a static web module and a dynamic web module, as static web projects and dynamic web projects in Eclipse. The Facet designates a project as being one of the two, and for dynamic modules, which API level it supports and requires at runtime.
Server adapters then have to state which API versions the server types they provide can support. The Server Tools and validation can then help you avoid deploying to an incompatible server, as well as build against a valid server. You want to build against a valid server in the same way you want to compile against your intended Java runtime. It's the most straightforward way to, for example, avoid calling classes and methods that didn't exist at the time.
There's also a Module Core nature that gets added, which supports APIs for describing the deployment details. Details like saying your Java class output folder contents go into WEB-INF/classes, that the jars you select go into WEB-INF/lib and that those static resources go into the application root, all to comply with the layout expected at runtime. That API is meant to be pluggable, so it can be fulfilled by e.g. Maven integration.
The terms in the UI can be changed, but that has its own pain points. The community tends not to update old videos and tutorials that have been correct for years.

JavaFX - POM, UI & Controllers per device

i am new in Java, and begginer in programming (simple bash scripting i can do).
I know there are commonly used POMs, but i want to avoid junk in project and create custom POM. As my English isn't perfect, ill illustrate it.
SRC/Main
Core // where things are going
Main package files, every job is done here
Android // fxml, css, general UI and controllers
include core
PC // as above
include core
web // as above
include core
SRC/Test
// as above but #testing
BIN
Android
PC
Web
Separate platforms that have different display, input, destiny (run in background on android, notifications). It's why title is JavaFX. Compiling different resources for different platform. Where core has possibility to work in commandline.
Goal is to test, build, compile all per-platform packages, using one command. Something like project with subprojects. Maybe i am crazy but i think it should be possible via gradle.
Maybe i am dreaming, so i am asking. It's a good idea? Someone practices this project structure? It's possible to still have automotion like in Maven/Ant/Gradle with this layout? If you know any tutorial related to this POM, i'll be happy to see any link.
Related, but not explaining:
Custom directory structure in Eclipse new project?
How to make java packages
Android Project View
Android Project Structure
CDEJ Project Folder Structure
Maven - creating archetypes
Resources are only part of goal. If you want i can split this question into few small questions.

Gradle: Building different jars for Java and Android

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.

Java - modular library project - how to?

I am supposed to deliver a SDK in Java for the company I work for.
I have a few years of Java EE experience but not so much when it comes to develop API and SDK.
The problem here, is that the SDK is already available in .NET C# and working just fine. I made it myself.
Switching to Java is a nightmare. I tried several solutions. All failed, some were inconclusive due to the fact I could not progress.
As the title says, I a need to develop a Java Library that has modules. Internal modules. Modules the world out there is NOT supposed to see / use / modify.
In C#, it's easy as pie : create your modules respective namespace, make their classes and methods privates, expose one or more wrappers (bridges) to the entire assembly (project) with internal so that the "main module", through it's own public wrapper accessible by the world, can use the tools provided within these internals modules.
The keyword, here, is INTERNAL. I think it's pretty easy to understand. So let's take an example.
Let's say the SDK is consisting of 4 modules.
The 1st module, is the main module, the one that is public and
exposed to the whole world. In other words, the unique entry point
of the SDK. It's like a master of its own universe. It can use the
internal modules at will, but will never show them to the world.
Never.
The 2nd module is network-related. As in, it deals with network to manage connexions to remote services, read and write data from and to a stream. It offers its own little wrapper so that the main module does not need to use the 2nd module internal tools. Like a universe inside a universe.
The 3rd module is a data processing module. It receives packets (hand-made by the 2nd module) so that it can be processed and relevant information dealt with.
So here we are. How can I do that in Java using NetBeans ?
I tried Maven with POM Project, and Netbeans modules. A nightmare.
I tried creating multiple libraries (one per module), tweaked the Main Module library to include its (modules) dependancies but it does not work.
In a standard Java EE console application, as soon as I attempt to instanciate my SDK Manager (ergo the main wrapper from the main module), it fails because Class Not Found exception : could not find classes related to the internal sub-modules.
If I add all modules respective Jar into this Java Console app, it can access all wrappers. Where is the fun in that ?
Thanks for the help !
Project Jigsaw will eventually give you what you want when java 9 comes out.
See this article about how jigsaw works, in particular,
An exports clause in a module declaration makes the public types in
the package it names available to other modules, so we can with Jigsaw
defines boundaries, and not all public types could be used from other
modules, we must explicitly specify which types are visible.

How to maintain a paid and free version of an app

I have built a free version of a game app which is now on the market with a name like com.mycompany.myfreegame. Now I want to make a paid version. There will no doubt be tweaks and bug-fixes to both versions required for years to come so I want to encapsulate the encoding of the free vs paid information in as compact a way possible so that I can essentially fix bugs in both versions simultaneously.
If the entirety of the differences between the two versions was handled at runtime then I could set a single flag in the source code and that would be the end of the problem. Unfortunately there are two other things to consider,
The name of the package needs to be different between the two versions.
Some xml needs to be different. For example the free version needs linear Layouts for holding ads, the paid version does not.
What is the simplest way to achieve this goal?
I think the first approach I'd try is using 3 projects in Eclipse: one for either version of the game, and a library project with all of the shared code. The library project would be where all the code for your core gameplay goes, and the version specific projects manage loading different layouts, putting ads in the free version, and adding levels/features/hats to the paid version.
You might be able to accomplish your goal of a single code base with a compiler flag using an ant task, but that's beyond me.
I think what you're looking for is a Library Project http://developer.android.com/guide/developing/projects/index.html#LibraryProjects
From that web page:
If you are creating an application that exists in both free and paid versions. You move the part of the application that is common to both versions into a library project. The two dependent projects, with their different package names, will reference the library project and provide only the difference between the two application versions.
Another question, very similar to this one, seems to have a decent discussion and answer: Multiple Apps with a shared code base
Edit: Here is a link on how to implement a library project. http://developer.android.com/guide/developing/projects/projects-eclipse.html
In regards to different versions being slightly different, a library project can accomodate. The library project is built first, then the parent (the project that uses the library) is built last and they are merged together. Both projects can define the same resource identifiers and the project built last (parent project), gets priority (overwrites). So essentially, you can override strings/layouts (possibly more, not sure?) in the parent/calling application.
For example: Say you have two projects, free and paid.You could create a string with a default implementation (free version) and override it in your paid version (parent app).
Code in shared libraries Strings.xml file:
<string name="AppName">My Application (Free)</string>
Code in parent app Strings.xml file:
<string name="AppName">My Application Premium</string>
I would go with Maven. You can define a parent project with three sub-projects, say:
Common
Paid
Free
Maven allows to have different configuration files, while having the same code base.
For example, I currently have a project where two databases are used, so all the app config files remain on a common project, where the database configuration files and classes remain on each project folder. When I do a build in the parent, every child project is built, unit tests passed, etc...
Moreover, this is only one of the thousand advantages of maven!
EDIT: I just found out, you have an android-plugin for maven, with cool features also
May be the best way now is to use Android Studio + gradle.
This case allows to build both paid and free versions with one command in console.
More details are in this post: https://stackoverflow.com/a/17286142/1705370
I think you are looking for something similar to this:
Multiple Android Application Package .apk files from single source code
Basically, the easiest approach here is to have two different manifest files and two different main activities and switch the compilation using Ant, though the latter is optional.
Hope it helps.

Categories