Build the android development environment in Ubuntu 11.04!

Source: Internet
Author: User
Tags gtk

I recently switched from windows to Ubuntu 12.04 lts to develop Android. In Step-by-Step practice, I am guided by this article.

Article by: http://www.cnblogs.com/softman11/archive/2011/06/22/2086793.html


1. Install JDK

First go to the Oracle official website to download the Linux version of JDK, URL: http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u26-download-400750.html

I chose Linux x86-self extracting installer, which is about 81.2 M.

After downloading the file, you can directly run the installation. First, CP the file to your installation directory, and then directly execute it in your installation directory:

./Jdk-6u26-linux-i586.bin (of course, if the execution fails because there is no execution permission, you also need to add the execution permission: chmod + X./jdk-6u26-linux-i586.bin)

The installer will automatically install it to the jdk1.6.0 _ 26 directory of the current directory.

After the program is installed, you need to set the environment variable.

Run:

Sudo gedit/etc/profile

Add the following parts 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, log off the current user, and log on again. The environment variable takes effect.

Verify whether the installation is successful:

Run:

Java-version

If:

Java version "1.6.0 _ 26"
Java (TM) se Runtime Environment (build 1.6.0 _ 26-b06)
Java hotspot (TM) server VM (build between 0-b11, mixed mode)

This information indicates OK.

Note: openjdk has been installed in Ubuntu by default. Therefore, even if you do not install JDK, no error will be reported when you execute Java-version. However, the reported information is different from that when JDK is installed.

2. Install eclipse

Currently, the officially 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.

Download eclipse address: http://www.eclipse.org/downloads/

I downloaded 32bit Linux:

Eclipse IDE for Java developers, 98 mb. This is a basic package for javase development. We recommend that you download the classic version. Note that the latest ADT requires eclipse To Be A version later than 3.5.

Name: eclipse-java-helios-SR1-linux-gtk.tar.gz

Of course, the first step is to decompress the package and execute the command:

Tar zvxf eclipse-java-helios-SR1-linux-gtk.tar.gz

After decompression, an eclipse directory appears. This directory is the installed eclipse. Enter this directory and execute the eclipse file to start eclipse.

You can write a simple program and compile and execute it to verify whether eclispe works normally. You will find that eclipse compilation and execution speed in Linux is faster than that in windows.

Of course, you can also set up a desktop startup shortcut for ease of use.

3. download and install the android SDK starter package

The android SDK starter package is only the core basic tool of the SDK. With it, you can use its management tool to download other required tools. Is there an android script file in this directory? After you execute this tool, the android SDK and AVD manager will be started. This tool can help you download other required parts and create a simulator.

Yes: http://developer.android.com/sdk/index.html

The downloaded file is: android-sdk_r11-linux_x86.tgz, about 26 m.

Next Of course is unwrapped: Tar zvxf android-sdk_r11-linux_x86.tgz

The android-sdk-linux_x86 directory will appear under the current directory after unpacking. This directory is the basic SDK tool. Remember this directory, because this directory will be required when you run the tool or set the ADT later!

4. Install the ADT (androiddevelopment tools) Plug-in

The ADT plug-in is an Eclipse plug-in officially developed by Google and is specially prepared for Android Application Development.

  • Start eclipse and selectHelp>Install newsoftware....
  • Click Add in the upper-right corner.
  • In the Add repository dialog box that appears, enter "ADT plugin" in the name column", In the locationThere are two options in the column. One is to enter the download URL: https://dl-ssl.google.com/android/eclipse/, which can be downloaded and installed online. The second option is if I have downloaded ADT plugin, 5.3 m. Select OK.
  • In the software list below, select the checkbox in front of Developer SDK tools, click the next button below, and then wait until the installation progress bar is complete. A list of installed software is displayed, you can click next, and then the license will appear. You must select agree and click Finish to complete the download process (of course, it may take some time ). After the installation is complete, restart eclipse.

5. Configure the ADT plug-in

The configuration content is to modify the reference pointing to the ADT plug-in eclipse. It needs to point to the previously installed Android SDK directory. Do you still remember this directory?

Start eclipse, selectWindow>Preferences ..

InPreferencesIn the dialog box, select the android tag on the left and the directory of your android SDK on the right. For example, I went to the directory:/home/jackwong/android-sdk-linux_x86, then click Apply, and then click OK.

In this process, a dialog box is displayed asking if you want to participate in the Google satisfaction survey report. You can choose whether to participate or not. Click the process button.

After installation, you can useHelp>Check for updatesTo keep the ADT up to date.

6. Add the Android operating system and components

So far, the basic configurations are almost the same. However, to develop an Android Application, you must add an Android operating system to simulate your application. Of course there are some other components that need to be installed. It is actually done through the android SDK and AVD manager in the SDK kit. Of course, you can directly start this program in Eclipse:Window> Android SDK and AVD Manager.

Of course, you can also directly run the android script under the tools directory under the SDK directory to start.

The recommended parts are generally:

SDK tools. You have installed the SDK starter package.

SDK platform-tools, which must be installed.

SDK platform, which requires at least one. That is, you can download multiple operating systems, such as 2.2 and 3.1, but at least one, because the simulator is required for running. Therefore, if you want to simulate and test various platforms, You need to download one for all versions of Android.

I downloaded three packages: SDK platform-tools 5, Android 3.1, and Android compatibility package.

After the download is complete, the android development environment is ready.

 

7.Write a hello, Android test program.

When the verification result arrives, start eclipse and select File> New> project...

Select the android project under Android, and enter the following information:

Project name: helloandroid this is the project name, that is, the directory name containing the file

Application name: Hello, Android. This is the name of the application and the text displayed on the top of the screen when the program is running.

Package name: My. Android. This does not need to be explained. You should know everything you have learned about Java. This is the package name of the class.

Create activity: helloandroidactivity: This is the name of the activity. Android programs must be started with the activity, that is, the name of an activity subclass.

If you do not need to modify other items, use the default value and click Finish to create the project.

Go to the project and open the helloandroidactivity. Java file,

PutOncreateThe method code is updated 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 and prepare to run.

But if you run it like this, I can guarantee that you will probably fail. Because Android 3.1 is indeed too resource-consuming. You may see that the simulator is stuck after an android icon is displayed.

Therefore, you also need to configure the simulator.

Choose Windows> Android SDK and AVD Manager

Click the new button to create a new virtual machine, as shown in:

One of the key points is skin. By default, wxga is selected and the resolution is 1280*800. In this resolution, my t7500 + 2G notebook cannot start the simulator successfully.

Therefore, we recommend that you modify the resolution. For example, you can use 480*300 or 640*400. Of course, there is another way in the simulator's start... window Selection: scale display to real size is also acceptable. Of course, the default value of 3 inch is too small. It is good to adjust it to 7 inch or 5 inch, but this mode is slow and not clear, not recommended. As shown in:

Okay, everything works. Now you can run it. Of course, if you run as an Android Application, eclipse will automatically start the simulator, automatically install APK, and run it automatically.

Shows the effect:

Of course, there is another problem. The simulator will start on the boot interface, and then it will not move. Friends who have never used android may encounter a bit of confusion here. Of course, they will understand how to do it, for example:

At this time, the system will not continue to run your application. You need to drag the following lock up until the system is unlocked to automatically execute your application. This is a special example for beginners who have never used android.

 

If the scale display to real size mode is set when the simulator is started,

The interfaces after Android 3.1 is started are different, as shown in:

At this time, the unlock method is to drag the HALO to unlock.

As shown in figure:

 

Then execute the application effect, as shown in:

Is it too small? So we still need to lower the resolution.

 

Now, the environment is built here. The rest of the application development depends on your talents! Good luck!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.