Skip to content

Android in Eclipse IDE Eclipse

Android in Eclipse IDE Eclipse

Android in Eclipse IDE Eclipse is a widely deployed multilanguages and multiple OS open source development framework (Windows, Linux and Mac OSX in 32 or 64 bits versions). A large number of plugins can be installed on Eclipse platform; it allows the development not only of many Java-based frameworks (including J2EE, J2ME, etc.), C/C++, PHP, Python, etc., but also of many tools, for example for collaborative work management and synchronization with Git repositories10 or Apache Subversion11, or also testing tools and coding performance tools (for example JUnit for Java12), or design/modeling tools, and many others. The first step is then to download and install the Eclipse standard version available at the URL link: https://www. downloads. Eclipse is launched by running the “eclipse.exe” file (by doubleclicking on the icon or from the start menu) in the “Eclipse” folder; under Windows, a shortcut can be created on the desktop using the shortcut menu (displayed by a right click on the file icon).

Android Development Toolkit Android Development Toolkit (ADT) SDK can be downloaded from the URL in order to be installed independently: http://developer. NOTE.– Google provides two SDKs for one version, the open source Android version, fully open, and the version giving access to Google APIs not open and which requires a license agreement (charged or free). The ADT plugin for Eclipse must be installed via the software installer in the menu Help/Install new software. Enter the URL to install Android plugins and select the components before clicking the Next… button on the toolbar. This can take some time, but once you agree on all installations (choose to trust the software in case of system dialogue) and restart Eclipse, new menus and tools are available in Java perspective.

Android SDK manager makes it possible to install (or uninstall) available versions for your Android projects you may install at least the minimum version with which you want your projects to be compatible.

You are also able to install tools and extras (APIs and Google drivers). Documentation, source code and project examples are located in the installation folder of the Android SDK (e.g. for Windows, usually in the Program files folder: C:\Program Files (x86)\Android\android-sdk). NOTE.– Updates are regularly suggested; in order to only display updates or new versions, you just need to check the update/new checkbox, then uncheck Installed and obsolete (unchecked by default). Installing packages can take a lot of time and bandwidth, it requires opening some connection ports that are not always allowed on some local networks. For this reason, make sure your network configuration is adapted to the installation.

Eclipse working environment window Like most IDEs, the main window in Eclipse is a container for internal working windows with a menu bar and one or several toolbars. Internal windows can be displayed, moved, reduced/enlarged or hidden, but we will focus on the default layout and more specifically on the Java perspective; indeed, several perspectives are available, based on installed plugins, for example J2EE, JavaScript, version management and synchronization, and debugging. Figure 2.6 shows the Java perspective (2) with the packages explorer and the projects explorer on the left (1), the source code window in the center (3), displaying or hiding views can be managed from the Windows menu (4) and the LogCat window (5).

LogCat The Logcat is a console displaying the logs of the mobile connected to the computer’s USB port (it requires installing the Android Composite Android Device Bootloader (ADB) pilot, provided by Google on Google devices13). It is a very useful source of information displaying logs that were voluntarily added in programs (with three possible modes: debugging, info or error). Unhandled exceptions also appear in the Logcat, which indicates their origin in case of processing malfunction. NOTE.– If the Logcat window is not displayed by default, it can be displayed from the menu “Windows|show view|other…” .

Android project This section aims at familiarizing beginners with the Android project based on the example of an existing project.

Import an existing Android project From the menu File|New|Project…|Android Project from existing code, in the example projects available in the Android SDK, we can select (for example) the ApiDemos project on C:\Program Files (x86)\Android\android-sdk\samples\android-23\legacy\ApiDemos (for Windows environment only) in the import project dialogue window. The option Copy projects into workspace makes it possible to copy the project in the user’s workspace (the original source project is thus not modified).

Android project Properties Properties can be accessed from the menu Project|Properties or from the shortcut menu (right click on the project): the Android property section enables selection of the SDK we wish to compile the application with.

NOTE.– The Android SDK should match the declarations made into the Manifest file (see AndroidManifest.xml) and we must make sure the coding and the APIs used are compatible, for example to use Google APIs (Maps, Google Cloud Messaging, etc.), we must compile with the proper library version of the Google API.

Structure of an Android project The tree view of an Android project in Eclipse is usually made up of the following folders (under the project root): – archive files (compatibility libraries and dependencies of Android and external libraries added by the developer); – the SRC folder of the project packages and sources (extension .java files); – the GEN folder with java files generated by ADT during the project compilation, for example the file (“R” for “Resources”) that contains the reference constants of all resources of the project (views, menus, screen and buttons controls, strings, picture files, themes, etc.) and the file to manage the log display in debug mode.

– The ASSETS folder: all external resources added by the developer to be used by the application (for example configuration files) are in this folder. Once the project app is deployed on the device, these files are stored in the same unchanged state as during compilation (in read-only) but they can be copied by the application on the phone in a memory storage area (and then be modified) if needed.

– The BIN folder of binary files generated during compilation. That includes the APK archive of the application, which will be deployed on Android devices.

– The LIBS folder of external libraries (added and managed by the developer).

– The RES folder of resources files: the user interfaces descriptions (in the subfolder layout), the values subfolder contains styles, strings (including translations), the menus can be found in menus subfolder, etc. All these resources are described into XML files. Additional descriptions are located in the subfolder xml and the pictures files (e.g. icons of the application) are found in the subfolder drawable-xxx while media files are in the subfolder raw. The subfolders of the Android project can be split according to the layout target resolution and format, or according to the Android version (indicated by an extension in the subfolder name).

The AndroidManifest.xml file In an Android project, the application’s declarative file (manifest) is to be found at the root of the project: it is the AndroidManifest.xml file, whose content in XML format. Manifest information can also be viewed by theme in the Eclipse interface as well as the tabs manifest, application, permissions and instrumentation. In the manifest section, general attributes will be entered, such as the name of the application package, the version and the name of this version, the compatibility of the Android SDK number and the features the application needs to access (software or hardware), the section with the permissions the user must agree to grant the application when being installed; the instrumentation section enables linking classes extending the superclass used for example for automated tests, whereas the application section contains the attributes of the application and the activities declarations (including filters and metadata, for example to declare the application launcher’s main activity or the activities filtered on NFC technology discovery), as well as the declaration of some APIs with or without activation keys, for example Google APIs (monitored from the console: Maps, Google Play, Street view, Google Cloud Messaging, Prediction, YouTube, etc.).

NOTE.– To go further in the use of the AndroidManifest file, visit the Android developer website at the URL: http://developer.

Filters intents on activities and services Filters defined at the activity tags section in the Manifest file (subcategory of the tag application) are intended to provide the intended use of a given activity. There are three types of intent filters: – the action filter indicates the type of action executed by the activity, for example for the main activity and the android.intent.action.MAIN action, or a filter on NFC technology discovery (see section 2.2.1); – the category filter indicates the category of the activity, for example the application will be launched with the activity declared in the manifest with the filter on android.intent.category.LAUNCHER; – the data filter indicates the type of data that the activity expects (i.e. the activity will only be wake-up when this format is detected): a named format, a URL, a domain, etc. For example, the data filter is used to target a specific type of content of NFC tags; a domain, a URL, etc.