Android source code How to compile debugging _android

Source: Internet
Author: User
Tags documentation

Android provides a better tool chain and development tools, so its development environment is relatively simple to build, I believe many friends have set up a good environment, and wrote the Helloactivity entry program. Let's look at a couple of questions here:

1. What is the structure of the Android file system, and where are the programs we install?

After compiling the Android source code, some files are out/target/product/generic:

Ramdisk.img, System.img, userdata.img, System, data, root

Wherein, the SYSTEM.IMG is obtained by the System package compression, the userdata.img is obtained by the data package compression.

Ramdisk.img is the simulator of the file system, the ramdisk.img extract to know that ramdisk.img files in the root folder is basically the same file.

The simulator loads the ramdisk.img and extracts the memory, then mounts the system.img and userdata.img to the system and data directories under RAMDisk respectively. The applications we compile are placed under System/app. User-installed programs are placed under Data/app.

2. What tools can the Android SDK and the Android source provide for us?

The Android SDK provides many tools, such as ADB,DDMS,EMULATOR,AAPT, and provides Kernel-qemu, Ramdisk.img, system.img, and userdata.img. So as long as we have the Android SDK, we can run Android on the simulator.

Android source code can be compiled from the Android SDK, ADB and other tools, the Android file system, as well as the ADT plug-in, that is, we can compile all the Android-related things from the Android source.

3, after the Android source "make" will generate a lot of tools and the Android file system (SYSTEM.IMG, etc.), we can use the "Make SDK" to generate Android Sdk,android The SDK also includes tools and the Android file system (SYSTEM.IMG, etc.), and we installed the Android SDK when it was originally installed, so what are the tools and the Android file system we should use when we develop?

The question is answered in the back.

4, the official recommended that we use Eclipse+adt into the development of applications, our Helloactivity program is also developed here. When we import the project under the Android source/packages/apps/into Eclipse, there is usually an error that the package cannot be found. So how do we modify, compile, debug the Android source code? What tools does Google use to develop Android?

The question is answered in the back.

The following is a systematic account of the creation of the Android development environment and the use of development tools.

Android SDK and Eclipse installation and Android development environment

The Android tool chain is more complete and requires less external tools. The specific installation process can refer to the official documentation or <<android simulator in ubuntu8.10 installation >> and <<android source compilation >>.

It's important to note that when you compile the Android code with "make," we can use JDK5 or JDK6; When compiling with the "Make SDK", Javadoc is used to generate the document, and Javadoc must use JDK5 Javadoc. Otherwise, compilation is not a pass. So we can put both the JDK5 and the JDK6 and then just point Javadoc and javadoc.1.gz to the corresponding tool JDK5, and the other tools are JDK6. Of course, we can only install JDK5 or use only JDK5 tools. Specific operations can refer to the <<android source code compilation >>

 Second, use Eclipse to develop the Android source code

The main reference here is the official document

Https://sites.google.com/a/android.com/opensource/using-eclipse

Here's how you can use Eclipse to develop the Android code from an official document

1, the establishment of the basic Android development environment

Please refer to the official documentation or <<android simulator in ubuntu8.10 installation >>

2, compile the Android source code

Android source root directory through make to compile, please note some configuration, specific reference to <<android source code compilation >>

 3. Copy Eclipse project configuration file to the Android source root directory

CP Development/ide/eclipse/.classpath./

chmod u+w. Classpath # make the copy writable

4, modify the configuration of the Eclipse program

1), Increase Eclipse memory settings

Change the 3 values of the Eclipse.ini (under the installation directory of the Eclipse software) to the following values:

-xms128m

-xmx512m

-xx:maxpermsize=256m

2), import Android-formatting.xml and android.importorder into eclipse (optional)

Android-formatting.xml, Classpath and Android.importorder are all placed under development/ide/eclipse/.

Android-formatting.xml is used to configure the code style of the Eclipse editor; Android.importorder is used to configure the order and structure of the import of Eclipse.

Import Android-formatting.xml in Window->preferences->java->code Style->formatter

Import Android.importorder in Window->preferences->java->code style->organize imports

3), install Anyedit plug-in (optional)

Download and import eclipse in http://andrei.gmxhome.de/anyedit/

 5, the Android source as a project to import eclipse

Before importing, check for. classpath files in the Android source code has the appropriate files (folders), otherwise it will damage the Android source code (generally add files/folders),. Classpath redundant paths can be deleted

New Java Project (not Android project, or it will destroy the Android source code), select from existing project import, project name arbitrary, complete.

When you import, Eclipse will build a project, slower. After the guide, there are generally no mistakes.

And here's the 4th question.

6, debug the Android program on Eclipse.

In order to not allow other versions of Android tools and Android file systems to affect the following compilation and debugging, you need to remove the path of the Android tool and the Android file system from the environment variables:

Vim ~/.BASHRC

See if there is a path to add the Android tool and the Android file system to the path variable, and annotate it if it is added. In the following way, we do not need to add the Android tool and the Android file system path to the. BASHRC.

Perform:

CD Android Source directory

. Build/envsetup.sh #设了环境变量之后, there will be more mmm and other commands, you can enter Help to view

Lunch 1 # Emulator and other tools such as ramdisk.img and other documents, you can directly call emulator and other tools, but also solve the 3rd problem

Emulator &

DDMS &

Notice that you start the DDMS and then start eclipse so that there is no port conflict in eclipse

Then configure the debug types and ports in eclipse:

Double-click on Run->debug configurations->remote Java application, and then, "Host:" set to LocalHost, "Port:" Set to 8800, "Connection Type" is standard (Socket Attach)

And then "Apply."

Note that the port set above is consistent with the port set in Ddms, and the ADT plug-in uses 8700 ports, so the port set above is 8800. If there is an error that does not connect to the VM, be aware that you must first select a process (corresponding to an application) in DDMS to perform Debug in Eclipse.

When you debug in Eclipse, you can set breakpoints and step into debugging. It is estimated that the Google team also developed and debugged the Android app

7, compile the Android source code

Perform:

CD Android Source directory

. build/envsetup.sh

Then there will be more mm/mmm such as command, Mm/mmm used to compile modules (including C, C + +, Java programs). We can also compile the module by executing the "make module name" directly under the Android source root directory (the module name can be found in the. mk file). After the module is compiled, the corresponding. apk package is generated under Out/target/product/generic/system/app. However, using mm/mmm to compile the generated. APK is not packaged into the system.img, we need to manually package the system folder as system.img through make snod, but it's also cumbersome to rerun the simulator. For our developers, we can do this:

1 the need to modify, debug modules (such as alarmclock.apk) removed from the/system/app, and then make Snod, so system.img no alarmclock.apk.

2 Run the simulator, you can't see the alarmclock.

3) Modify the AlarmClock source code and mm/mmm to compile, under the/system/app generation alarmclock.apk

4 to install the alarmclock.apk into the Android file system through ADB, there are two installation methods:

A, through the adb install xxx/alarmclock.apk

B, through the ADB push Xxx/alarmclock.apk/data/app

Both methods can install AlarmClock to/data/app, and Android automatically displays it in the main menu (as long as there is an activity pack in the ALARMCLOCK.APK Contains Android.intent.category.LAUNCHER attributes), but the A method generates Com.android.alarmclock.apk,b method in/data/app is alarmclock.apk. When using a method, if you have already installed the AlarmClock, you have to uninstall it first, while the B method does not. It is recommended that B method be used. Similarly, uninstall can be done through adb uninstall or adb shell RM xxx/xxx.apk, and it is also recommended that you uninstall by deleting

8, how to develop their own projects

The main story ahead is how to develop the original Android project on Eclipse. For our own works, we can do this:

1 Create a new Android project.

The advantage of building an Android project is that you can fully use ADT functionality.

2) Import the required package

3) compiling, running and debugging

4 to add to the Android source directory, the application is generally placed under the Packages/apps

We observe the original works of Packages/apps will find that their code is very "clean", there is no ADT automatically generated assets, bin and other folders and R.java, of course, there is no. classpath and. Project

5) Writing makefile file xxx.mk

With the exclusive makefile file provided by the Android source code XXX.MK, its format is relatively simple

6 Add newly added projects to Eclipse's Android project

Can be added in eclipse, or you can add a path directly to the. Classpath. For example, add in. classpath:

<classpathentry kind= "src" path= "packages/apps/helloworld/src"/>

R.java, in fact, all projects used to "resources", will be used to R.java, these r.java are placed under OUT/TARGET/COMMON/R. The R.java is generated for each module when we make all the code in the source root directory, and the modules that have the. apk file have been compiled and generated when make is not compiled. Therefore, if the newly added project has been compiled (with mm/mmm), we will first change the "resources" of the project (must be changed "resources", because R.java is generated by "resources"), then make, in the out/target/common/ R corresponds to the package path to see the R.java of your project. Refresh the OUT/TARGET/COMMON/R project in Eclipse and add its package to where you used the R class, such as

Import COM.ANDROID.EXAMPLE.TEST.INSIDE.HELLOWORLD.R So there is no error that cannot find the R definition.

In fact, this error does not have any effect on us, because we are compiled in the shell.

7 to compile the newly added project under the Android source directory

You can use Mm/mmm or make module names

8 upload the project to the server using the Version Control tool (SVN or Git or others)

The above is on the Android source code compiling and debugging, follow-up to continue to collate relevant information, thank you for your support of this site!

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.