Build an Android development environment under Ubuntu 11.04!
1. Installing the JDK
First download the Linux version of the JDK to Oracle's official website at: http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u26-download-400750.html
I chose Linux x86-self extracting Installer, about 81.2M.
After the download, of course, you can run the installation directly. Start the CP file in your installation directory and execute it directly in your installation directory:
./jdk-6u26-linux-i586.bin (Of course, if execution fails because there is no execute permission, then you need to add Execute permission: chmod +x./jdk-6u26-linux-i586.bin)
The installer will automatically install the JDK1.6.0_26 directory to your current directory.
The program is installed, and then the environment variable needs to be set.
Perform:
sudo gedit/etc/profile
Add the following section to the configuration file:
Export java_home=/home/jackwong/jdk1.6.0_26
Export JRE_HOME=/HOME/JACKWONG/JDK1.6.0_26/JRE
Export Path=/home/jackwong/jdk1.6.0_26/bin: $PATH
Export classpath=.:/ Home/jackwong/jdk1.6.0_26/lib:/home/jackwong/jdk1.6.0_26/jre/lib
Save, then log off the current user, log back in, and the environment variable is in effect.
Verify that the installation is successful:
Perform:
Java-version
If it appears:
Java Version "1.6.0_26"
Java (TM) SE Runtime Environment (build 1.6.0_26-b06)
Java HotSpot (TM) Server VM (build 20.0-b11, Mixed mode)
This kind of information, it means OK.
Note that Ubuntu has OPENJDK installed by default, so you do not install the JDK, do Java-version will not error, but the reported information and installed JDK is not the same, please note the distinction.
2. Install Eclipse
At present, the official recommended development environment is Eclipse+adt. Of course you can use any other development environment, but I chose the official recommendation because everything is free.
The address of the download eclipse is: http://www.eclipse.org/downloads/
I am downloading 32bit linux:
Eclipse IDE for Java developers, 98 MB, this is a basic package developed by Javase, it is recommended to download the classic version, note that the latest ADT requires that Eclipse must be 3.5 or higher.
File name: eclipse-java-helios-sr1-linux-gtk.tar.gz
Of course the first is decompression, execute the command:
Tar zvxf eclipse-java-helios-sr1-linux-gtk.tar.gz
After the decompression is successful, an Eclipse directory appears. This directory is installed Eclipse, enter this directory, execute Eclipse file, you can start eclipse.
You can go in and write a simple program, compile and execute, to verify that the ECLISPE is working properly, and you will find that the compilation execution speed of Eclipse under Linux is faster than that of Windows.
Of course you can also set up a desktop shortcut, easy to use.
3. Download and install the Android SDK Starter package
Android SDK Starter Package This is just the core basic tool of the SDK, with it, then use its management tool to download other parts you need to. Do you see an Android script file in this directory? Executing it will launch the Android SDK and AVD Manager, which can help you download other parts you need, and can also create a simulator.
Yes: http://developer.android.com/sdk/index.html
Download next to file is: android-sdk_r11-linux_x86.tgz, about 26M.
The next course is unpacking: Tar zvxf android-sdk_r11-linux_x86.tgz
After unpacking, the Android-sdk-linux_x86 directory will appear in the current directory. This directory is the basic tool of the SDK. Remember this directory, because you will need this directory in the future when you run the tool or set up ADT!
4. Installing the ADT (androiddevelopment Tools) plug-in
The ADT plugin is a plugin for Google's official development of Eclipse, which is designed for Android app development.
- Start Eclipse, then select Help > Install newsoftware....
- Click the Add button in the upper-right corner
- In the pop-up Add Repository dialog box, the Name column fills in "ADT Plugin", in the location column there are two choices, one is to fill in the download URL:https:// dl-ssl.google.com/android/eclipse/, so you can download the installation online. The second option is if I have already downloaded ADT Plugin, then click the Archive button next to directly find the plug-in to the package, for example, I use the second kind, I have downloaded, the file name is adt-11.0.0.zip,5.3m. Regardless of that, finally choose OK, you can.
- Then, in the list of software below, select the checkbox in front of the developer SDK tools and click on the Next button below and wait for the installation progress bar to complete, where the list of installed software will appear, you can click Next, and then the license will appear. You have to choose Agree, and then click Finish to finish (of course there is a download process that may take a little time). After the installation is complete, restart Eclipse.
5. Configuring the ADT Plug-in
The content of the configuration is to modify the reference to the ADT plugin in eclipse to point to, need to point to the previous installed Android SDK directory, remember this directory?
Start Eclipse, select Window > Preferences .
In the pop-up Preferences dialog box, select the Android tab on the left and the right SDK location to select the directory of your Android SDK. For example, I go to the directory is:/home/jackwong/android-sdk-linux_x86, then click Apply, then click OK.
In this process, a dialog will pop up asking if you want to participate in Google's satisfaction survey report. You can choose to join or not. Click the Process button.
Once installed, you can use the Help > Check for Updates option to keep ADT up-to-date.
6. Add Android OS and widgets
So far, the basic configuration is pretty much the same, but in order to develop Android apps, you must also add an Android operating system for the simulator to emulate your application. Of course there are some other parts that need to be installed. This is done through the Android SDK and AVD Manager in the SDK Toolkit. Of course, this program can be launched directly in Eclipse:Window > Android SDK and AVD Manager.
Of course, you can also run the Android script directly under the Tools directory in the SDK directory to launch it.
The recommended parts are generally:
SDK Tools, which you have installed the SDK starter package is actually ready.
SDK Platform-tools, this to install.
SDK platform, this requires at least one. That is, the operating system, you can download multiple, such as 2.2,3.1 you can download, but at least one must, because the simulator is required to run. So, if you want to test all kinds of platforms, then you need to download one of the various versions of Android.
I downloaded the SDK platform-tools 5 and Android 3.1,android compatibility package three packages.
After the download is complete, the Android development environment is built.
7. Write a hello,android test program
It's time to validate the results, start eclipse, choose File->new->project ...
Then select Android Project under Android and fill in the following information:
Project Name:helloandroid This is the item name, which is the directory name that contains the file
Application Name:hello,android This is the application name and the text that is displayed at the top of the screen when the program runs
Package Name:my.android This does not need to explain, learned Java should know, this is the class of packages name
Create Activity:helloandroidactivity This is the name of the activity, the Android program to be displayed is activated by the activity, that is, the name of an activity sub-class
Others can be created without changes, using default values, and clicking Finish to complete the project.
Enter the project, open the Helloandroidactivity.java file,
Update the code inside the onCreate method as follows:
Import Android.widget.TextView;
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
TextView TV = new TextView (this);
Tv.settext ("Hello, android!= Hello, Android! ");
Setcontentview (TV);
}
Save, ready to run.
But if you run this way, I can guarantee that you will probably fail. Because Android 3.1 does cost a lot of resources. You may see the simulator show an Android logo after it has stalled.
Therefore, you also need to set the simulator.
Select Windows->android SDK and AVD Manager
Then click the New button to create a virtual machine as shown in:
One of the key points, is the skin part, the default is to choose WXGA, the resolution is 1280*800, this resolution, I t7500+2g notebook, anyway, it is impossible to start the simulator successfully.
So, it is recommended that you modify, using a custom resolution, such as I use the 480*300 or 640*400 effect can be accepted. Of course there is also a way to start the simulator ... Window selection: Scale display to real size can also, of course, the default is 3 inches too small, adjusted to 7 inches or 5 inches of the effect is good, but this mode is relatively slow, and see not very clear, not recommended. As shown in the following:
Okay, everything is OK, now run, of course run as Android application, Eclipse will automatically start the simulator, automatically install APK, Autorun.
The effect is as follows:
Of course, there is a problem, the simulator will boot to the boot interface, and then do not move, may not have used Android friends here will encounter a bit of confusion, the use of course understand what to do, such as:
This time the system will not continue to run your application, you need to drag the following lock up, until the system is unlocked, will automatically execute your application. This is a special explanation for beginners who have not used Android.
If the simulator is set to start: Scale display to real size mode,
The interface after the Android 3.1 boot is different, as shown in:
This time the way to unlock is also to drag the halo can be unlocked.
The unlock is complete as shown:
Then execute the application effect as shown in:
Isn't it too small? So the resolution must be lowered.
Well, the environment has been written here, the rest of the application development, it depends on your intelligence! Good luck!
Very helpful for planning to make Android mobile