AIDE

From Bill's Tutorials at btutor.com

AIDE: The Android IDE

To develop an Android app you need an Integrated Development Environment, that is, an IDE. This lets you write Java code, convert it to an app code, then run your app to test it. The first stage involves writing the Java source code. You can learn how to do this at btutor.com. The second stage involves compiling it into the machine code that makes up the app. And the third stage involves testing your app by running it in a simulated Android device or, in this case, in a real phone or tablet.

There are several IDEs that can be used. The most popular is probably Eclipse which is a general purpose computer application that can be used for app development. Another is the Android Studio software, also a computer application. A third option is to use an IDE that runs on an actual Android device. It is called AIDE (Android Integrated Development Environment). This lets you develop the app then run it on the same Android device.

Like Eclipse and Android Studio, AIDE is free, at least for a starter version. This will save and compile small apps then run them in the same device. When you get to the stage where you want to write larger apps or you want to publish them on Google Play Store then you will have to purchase an upgrade to the full version. You will also have to put up with a lot of ads in the free version.

Getting AIDE

To install AIDE on your mobile go to the Google Play Store and search for AIDE. Several versions will be offered. Choose AIDE - Android IDE - Java, C++. Then download and install the app.

When you first run AIDE it will offer you some options to learn or to code. You can have a look at the learning stuff later if you want. Meanwhile let’s get on with the coding and tap the “for experts” option to select it. This takes you to the next screen, where you are given more options. You can choose the second one to create a new Eclipse app so that your work can be copied to Eclipse should you want to do that at some later stage.

Creating a New App

An app is always developed as a project since it consists of several separate files. So we start the development by creating a new project.The first option is to store your app and it offers the default folder

/storage/emulated/0/AppProjects.

The next option is the name of your app. A default name, MyApp, is supplied by AIDE. You should edit this to Starter which we will use as our first app.

Then you need to enter a package name. This will be the full name of your app in the Play Store or on a mobile device, so it has to be unique, that is, different from all the other apps.

You create a unique package name by adding the app name to your domain name in reverse order. Here we have used the domain name androidjavaapps.com so the package name becomes com.androidjavaapps.starter. Now the Create screen will look like Figure 1.

Creating a new project
Figure 1. The Create New Project page for the Starter app

AIDE: The Project Files

The files that make up the Starter project are shown in Figure 2. If they are not already showing you can tap the blue file icon at the bottom right of the AIDE display or the File options menu at the top right of the screen. If neither of these buttons is available on your device you can use the Files option in the device options menu below the display and to the left. Tapping this opens the options menu.

Projects and file structure in AIDE
Figure 2. The File structure and project folders.

The project files are in a folder of your device which probably has the full path name

/storage/emulated/0/AppProjects/Starter

You can move up through this path by tapping the dotted folder icon at the top. This will take you to

/storage/emulated/0/AppProjects

where you will see all the projects in your IDE. It is also where you will see the option to create a new project.

To navigate down from the Starter folder you can click on any of the sub folders. The src folder, for example, opens to show a com folder then that opens to show an androidjavaapps folder then that opens to show the Java source files including MainActivity.java. In fact this is the only Java file we have so far. Then tapping in the file name opens it in the workspace – if it is not already opened.

You will also see an option to Create a New Class. This allows you to add another java file to your project. Most projects have several java source files and this is where you create them.

Of course, to get back to the Starter folder you just keep tapping the containing folder icon.

If you are looking at a workspace with several files open you can select any one of them by tapping the tag at the top of the file. If the file is already selected then this will open a menu with an option to close it.

So our project will be located in our phone or tablet device in the folder /storage/emulated/0/AppProjects and it will have the name, Starter, and the package name com.androidjavaapps.starter as indicated in the diagram. You should change the package name to your own domain name at this point to ensure it is unique.

AIDE: The Starter Code

Tapping the Create button on the Create new Project screen opens the AIDE workspace and creates a complete set of starter files. Probably two of them are displayed. These are called Main.xml and MainActivity.java. These are the names of two main project files - although the names are incorrectly displayed here in upper case characters.

The Main.xml file is an xml document that is used to create a user interface. It is widely used for Android apps. You can remove it from the screen for the time being by first tapping its name tag to open it (if it is not already open) then tapping its name tag again. This will give you an option to Close. Tapping this will close the file.

Then we are left with just the Java code file as shown in Figure 3. AIDE has given it the name MainActivity.java. We can stick with that. So it will be our main Java code file and the one we will develop for our apps.

The AIDE starter code
Figure 3. The Java code supplied by AIDE to start the project.

Compiling and Running the App

What we have now is actually a fully functioning app. It does not do much but it can be compiled and executed on our Android device. We can do this by tapping the Run icon at the top of the display. This is a right pointing arrow head as shown in Figure 3.

If this is the first time you have run your own app on your phone or tablet then it will probably fail with a warning that the device is set to block installation of apps obtained from unknown sources. You can choose Cancel or Settings. Tap Settings to go to your device settings then find the Unknown Sources option and tap the checkbox to select it. You will be given a warning that this may be harmful to your device. Ignore this and tap OK. It is not malicious software since you have just written it yourself. Now click Install. The app will be installed in your device. Then you can tap either Done or Open. Done returns you to AIDE while Open runs your app. Choose Open to check that it works as expected then you can use the device Back button to return to AIDE.

The Unknown Sources option will remain enabled until you change it so if you want to run any more apps that do not come from the Play Store you can leave it set. If not you may want to cancel the setting.

When you run the app it should simply display the message Hello World, MainActivity in the middle of the screen.

Also a new Starter icon will appear on your app screen as in Figure 4.

The starter app icon
Figure 4. The starter app icon.

 

You can tap this at any time to run the app like any other app in your device. It will be the default Android icon in the form of a green Android figure but we can change that later to our own design.

If you are wondering where the text came from, it came from the other files which were also created by AIDE. These created a resource called R.layout.main which defines the user layout. This is used in the Java line

setContentView(R.layout.main);

It refers to the AIDE default layout which is defined in the Main.xml file. This is found in the Starter/res/layout folder. This, in turn uses a text string defined in the Starter/values/strings.xml file. And this has a line containing the text Hello World, MainActivity. If you feel like a little adventure you can try changing this.

The App

So now we have already developed an app and it can be run in our Android device. It does not do very much but it is a real app. We can run it at any time by tapping the icon. What we can’t do is submit it to the Google Play Store since it is not a final version. We still have some work to do to create a final version and we will cover the process in the last chapter of the book.

However, we can copy this version to other devices and even distribute it to our friends if they are interested.

To do this we use the file system of the device to find the app file. It will be in the bin folder of the project folder and called Starter.apk. All you have to do is to copy this file to the other device. You can do this by usb connection, by sending it as an email attachment or through a cloud store such as Google Drive or Dropbox.

There is just one minor obstruction to overcome in the receiving device. It will probably not be set up to accept apps from unknown sources. So you will have to find this option and set it to accept. The process is the same one that you negotiated when you ran the app in your own device.

So Starter.apk is your app. It is a debugging version rather than the final one but it runs exactly the same. In fact, it is not really a single file. It is a compressed folder that contains all the files the app needs.

Further Reading

You can learn more about Android Java programming in my book "Start Programming Mobile Apps with Android Java" published in Kindle and paperback format by Amazon.