Re: Developing for AWT/Swing and Android portability
Martin Gregorie <martin@address-in-sig.invalid> writes:
are there any decent Android emulators that can be used to
develop Android graphical apps under Linux?
The standard Android SDK contains an emulator (which can be
somewhat slow).
Are there any decent compatibility packages that would let a Java
graphical application compile and run on both Linux and Android platforms?
The emulator can execute Android software under Linux.
Otherwise, Android applications (especially user interfaces,
but also other parts) have to be structured differently than
Swing applications from the beginning (from ground up), so a
compatibility layer is difficult and one would have to forgo
many features of Android or Swing using such a layer.
However, one can split an application into two parts, which I
here call the ?application-specific processing library?
(ASPL) and the ?platform-specific application proper? (PSAP).
The ASPL contains code for data storage (in containers, such
as java.util.list) and data processing and uses solely the
common subset of both Java implementations (i.e., of Android
and of Java SE). It is a library written specifically for
the use by the specific application (it might, however,
itself delegate to other, more general, libraries).
The two PSAPs contains everything that depends on the
platform, including the methods ?main? or ?onCreate?,
respectively.
So, you have to write a new PSAP for every platform, but you
do only have to write one ASPL. Start by writing the
application for one platform first, building the PSAP and
the ASPL at the same time. Try to move as much code as
possible out of the PSAP and into the ASPL. You can even
refactor an existing application this way, starting with an
empty ASPL and the whole application being the PSAP, and
then step-by-step moving parts into the ASPL. Then, write a
new PSAP for the next platform, but now you can /reuse/ the
same ASPL. (If the splitting was not done with both
platforms already in mind, some changes to the ASPL might
still become necessary, because the structure of the ASPL
might impose some constraints on the PSAP that cannot be
fulfilled on the other platform.)