ADK and NDK

There is the Android software development kit (SDK) for java based applications. Typically and the recommended way to program apps is making use of java.

But there is also the Native Development Kits (NDK) available to support other languages as C and convert them into hardware dependent binary code. Reasons for using the NDK are:

The SDK could be obtained by http://developer.android.com/sdk/index.html but it will be better to install it via packet manager of your Linux distribution. The SDK has a GUI where the different android versions and packages can be downloaded. The SDK has all the necessary command line tools to build an android application and could therefore be all you need.

However the preferred way is using launching it via GUI instead of the command line tools. The supported integrated development environment (IDE) is Eclipse using the Android Development Tools (ADT) plug-in using the following link https://dl-ssl.google.com/android/eclipse/. Be aware that this plug in, will call the SDK and is not a replacement nor contains the SDK. You still need to install the SDK and now you have even an option more. The options to install the SDK are:

  1. Use the package management system of your Linux distribution to install it system wide.

  2. Download it manually and install it manually somewhere, hopefully to not break your system in your home directory.

  3. Use eclipse and the ADT to guide you through the steps.

    Figure 13.1. Link to Android SDK

    Android SDK


Eclipse must be configured to find the SDK. The straight forward way is installing first the SDK and then the ADT. If you do it the other way you get a nice demonstration about what the two packages are.

Anyway the SDK is quite autonomous and can be updated via its gui, so your linux package management system does not get aware about those frequent updates. However regular users can not write to /opt/android-sdk-update-manager. An alternative would be to install the SDK into your home directory and keep your system untouched.

The android SDK comes with the android virtual device manager AVD. So you can create virtual devices with various options as different screen sizes. Then you can start them. The purpose of those AVD's is to use them for development and testing. Ctrl+F11 turns the emulator 90°.

The configuration goes in the directory ~/.android to your system.

Installation under Gentoo Linux

Make sure your system has java installed and check the required version of eclipse.

Install the android SDK under gentoo Linux this is done with emerge =dev-util/android-sdk-update-manager-20. See https://forums.gentoo.org/viewtopic-t-919462-highlight-android.html

To work, the user must be put in the android group, this is done with: gpasswd -a <username> android . Unfortunately the user must be log out and log in after that to take effect.

It will be installed in /opt/android-sdk-update-manager/tools/ where the SDK manager could be started via command line as ./android. However usually this is done via Gui of eclipse. Select at least on API (android version).

The classic Eclipse 3.6.2 or higher needs to be installed unfortunately eclipse in gentoo is too old and the gentoo maintainers struggle with the eclipse sources.

Luckily there are overlays

layman -a seden gets the necessary ebuild for a newer (but still old) eclipse. emerge eclipse-sdk..

layman -a java-overlay has binary versions of the newest eclipse versions, so there is no hassle with struggling compiling this complex software. emerge eclipse-sdk-bin and /opt/eclipse-sdk-bin-4.2/eclipse is then the magic command.

It is usually installed under /opt/android-sdk-update-manager there is a subdirectory called tools /opt/android-sdk-update-manager/tools where ./android can be started using the command line.

Developing Apps with the ADT and SDK

To work with the SDK some concepts of eclipse should be understood. Additionally basic java knowledge is required. Things as how to inherit an object, overriding methods and interfaces should be known. The applications are developed within a directory structure. Being new to android application development, this structure looks a bit complicated, but when experienced, the structure gives a familiar touch to all apps available and the individual files can be found easily.

Tutorials

Follow the tutorial http://developer.android.com/training/basics/firstapp/index.html or follow the tutorial but open a sample project as HelloCompute (I know the letter r is missing but thats the case) under File->New Project->Android->Sample Project and jump over the non relevant sections in the tutorial to see if your environment works. Later and as written in the tutorial you have to click on File->New Project->Android->Android Application Project. To debug and run it a virtual device needs to be created, started and unlocked. Then select the project in android and click the run icon.

If this works then redo the tutorial again but concentrate to the project data structure and the eclipse environment your eclipse/android environment will probably be newer then the one described in the tutorial, so it is good that you know that it works with the sample. A good article about android programming can be found under http://www.vogella.com/tutorials/Android/article.html

Note

During editing code, the code is checked and when errors appear a list of proposals to solve it appears too. The tutorial does not mention for instance that some more libraries need to be imported. This can be easily fixed when the errors pop up. Obviously all error must be removed when running an app.

Structure

The goal is to not go and program, but be lazy and use what is already there. The work goes more into configuring and app than doing a lot of programming. This means you must get familiar with the infrastructure android has, so more learning than doing is the way.

The res/AndroidManifest.xml describes the applications requirements.

Activity

To create the GUI of an app, Android uses xml files to describe them. The file /res/layout/activity_main.xml is the one that appears at start. Activity means a single window or since android can just show one window at a time it is also a screen. After your program gets more complex you migt get additional Activities and therefore additional xml files as Help-Activity and Setting-Activity. In eclipse you can switch between xml text view or rendered graphical view to observe this file. This file can be edited in both views.

Those xml files are not left alone there is an associated java file under /src directory. To have you data consistent eclipse allows to create activities for you so don't create those files manually.

Android is and must be quite flexible if it comes to display sizes, it must be usable on any screen size.

An Android App Window is an activity and runs using an activity class that on its onCreate method imports an XML file containing all widgets (buttons and stuff).

Runtime concerns

The main activity object is called and shows up. As with any other multitasking system, loops waiting for an event have to be avoided. However sometimes it needs to be waited, this does not mean that the system can not do something useful as running other apps in parallel. Android uses for that callback methods. The app does its work and then leaves, but it sets up a callback method. This is usually an already existing method of an object. If the event happens later, then this callback method is called. Often those methods are empty and do nothing, however the methods can be overridden with the desired code. In Android those methods have a name that starts with the word on as onCompletion used by the mediaplayer to be called when the audio file has been played. Looking closer also the activities make use of callback methods as onCreate that creates the activity.

Strings

Android needs to support multiple languages. Therefore all strings are located in /res/values/strings.xml and should be referred in the gui.

Indent

If a button is clicked an event is produced, this event needs to be linked to an action. Android uses the Indent class for that. Indents point from the source event to a destination where an action needs to be done. Indents can also be considered as messages. When creating an indent object (an instance of the indent class) the source and destination needs to be passes. The source is in most cases simply the word "this" since source is mostly the current context.

New -> Other -> Android lets to create or overwrite different items.

Icons

To change the icon edit the default icon ic_launcher-web.png then go to New -> Other -> Android -> Android Icon Set and recreate the icon set.

Distribute the app

Android applications are packaged in .apk format and are created in the bin subdirectory of the project. Using an archive manager the contents of the .apk file can be observed. The directories res and META-INF and the files AndroidManifest.xml, classes.dex (dalvik executable byte code) and resources.arsc (binary file containing the android resource tables) appear.

Testing should of course be done before distribution via Google Play or alternative channels. To directly install the apk file found in the project directory is possible. Copy it to a real android device and enable Settings>Security>Unknown sources, use a file manager and click on it. Un-install work as well.

As shown in the tutorial and documentation it is also possible to build android applications via command line. This sounds really out fashioned, but it would allow to automatically create applications for android as Java on Linux to Java on android conversion tool.

Settings

For settings there is the Preference class that can be fed from an xml file /res/xml/preferences.xml" and produces a SharedPreference file as default as /data/data/org.linurs.irsend/shared_prefs/org.linurs.irsend_preferences.xml that holds the data of the preferences. So the work to do is creating the xml file making the system aware of it and read out the data. File -> New -> Others -> Android -> Android XML File is the best way to create the /res/xml/preferences.xml it includes also a graphical editor so for beginning there is no need to go into XML. The strings used in the preference file should not be hard coded but taken out of the /res/values/strings.xml file, there are many reason for that as allowing to modify and translate them easily.

Settings have to be included in a PreferenceFragment. Fragments are user interfaces running inside the Activity.

Help

It is always nice to tell something to the user. This does not mean a lot of programming work. A good way is creating a dedicated help activity and just open a local html file that is placed in the assets subdirectory.

Money Making

Open Source and software for free is obviously a good thing to users and allow many hobby programmer to learn and do programing. However all people need some money to survive and most of them need to earn money.

Therefore it is desirable to convert the many hours of doing programming work into money to get something back. In android there are actually to ways:

  1. Selling the apps as through Play Store

  2. Adding advertising. This can be done using the AdMob SDK

Finally when working in release mode proguard can be enabled that makes it difficult to reverse engineer the code.


Linurs Servernest startpage