UseEclipseDevelopmentAndroidSource code is the content to be introduced in this article, mainly to understand and learnEclipse AndroidDevelopment source code, details aboutEclipse AndroidFor details about the development source code, see this article.
1. What is the structure of the Android file system? Where are the installed programs?
After the Android source code is compiled, some files in out/target/product/generic:
- ramdisk.img、system.img、userdata.img、 system、 data、root
Here, system. img is packaged and compressed by system, and userdata. img is packaged and compressed by data.
Ramdisk. img is the file system of the simulator. After extracting ramdisk. img, you can see that the files in ramdisk. img are basically the same as those in the root folder.
The simulator loads ramdisk. img and decompress it To the memory. Then, the system. img and userdata. img are mounted to the system and data directories under ramdisk respectively. The compiled application is stored in system/app. The programs installed by the user are stored in data/app.
2. What tools does the Android SDK and android Source Code provide for us?
The Android SDK provides many tools, such as adb, ddms, emulator, and aapt. It also provides kernel-qemu, ramdisk. img, system. img, and userdata. img. Therefore, with the android SDK, we can run android on the simulator.
Eclipse Android source code can compile android SDK, adb and other tools, android file systems, and ADT plug-ins. That is to say, we can compile all android-related things from android source code.
3. After making the Android source code, many tools and the android file system will be generated. img, etc.), and we can use the "make sdk" to generate the android SDK. The android SDK also includes tools and the android file system. img, etc.), and we also installed the android SDK during the original installation, So what tools and android file systems should we use during development?
This question will be answered later.
4. We officially recommend using eclipse + adt to develop applications. Our HelloActivity program is also developed here. When we import the project under the Android source code/packages/apps/into eclipse, the error that cannot find the package usually occurs. So how can we modify, compile, and debug the android source code? What tools does Google use to develop android?
This question will be answered later.
The following describes how to establish the Eclipse Android development environment and how to use the development tools.
I. Installation of Android SDK and eclipse and establishment of android Development Environment
Android tool chain is relatively complete and requires fewer external tools. For more information about the installation process, see the official documentation or <android simulator installation in Ubuntu8.10> and <android source code compilation>.
Note that when "make" is used to compile the Android source code, JDK 5 or JDK 6 can be used. When "make sdk" is used to compile the code, javadoc is used to generate the document, javadoc of JDK 5 must be used; otherwise, the compilation will fail.
Therefore, we can install JDK5 and jdk6, and then point javadocand javadoc.1.gz to corresponding tools of jdk5. other tools still use jdk6. Of course, we can only install JDK 5 or only use JDK 5. For more information, see <android source code compilation>
2. Use eclipse to develop Android source code
For more information, see the official documentation.
- https://sites.google.com/a/Android.com/opensource/using-eclipse
Next, we will summarize from the official documents how to use eclipse to develop the Android source code.
1. Establish a basic Android Development Environment
Please refer to the official documentation or <Android simulator installation in Ubuntu8.10>
2. Compile the Android source code
Use make to compile the Eclipse Android source code in the root directory. Pay attention to some configurations. For more information, see <android source code compilation>
3. Copy the eclipse project configuration file to the root directory of the Android source code.
- 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 three values of eclipse. ini in the eclipse installation directory to the following values:
- -Xms128m
- -Xmx512m
- -XX:MaxPermSize=256m
2) Import Android-formatting.xml and android. importorder into eclipse (optional)
The Android-formatting.xml,. classpath, and android. importorder are all placed in the 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 eclipse import.
Import Android-formatting.xml in window-> preferences-> java-> Code style-> Formatter
Import Android. importorder to window> preferences> java> Code style> Organize Imports.
3) install the anyedit plug-in (optional)
Download and import data to eclipseat at http://andrei.gmxhome.de/anyedit/
5. Import the Android source code as a project into eclipse
Check Before importing. whether the files in classpath have corresponding file folders in the Android source code). Otherwise, the android source code will be damaged by adding more files/folders ),. the redundant paths in classpath can be deleted.
Creating a Java Project is not an Android project; otherwise, the android source code will be damaged.) www.linuxidc.com selects to import an existing Project, and the project name is arbitrary.
During import, Eclipse Android requires a build project, which is relatively slow. After the import, there are generally no errors.
4th questions are answered here
6. debug the Android program on eclipse.
To prevent other versions of Android tools and android file systems from affecting compilation and debugging, you need to remove the paths of android tools and android file systems from the environment variables:
- vim ~/.bashrc
Check whether the PATH of the Android tool and android file system is added to the PATH variable. If yes, comment it out. In the following method, we do not need to add the path of the android tool and the android File System to. bashrc.
Run:
Cd Android source code directory
. Build/envsetup. sh # After the environment variable is set, mmm and other commands will be added. You can enter help to view
Lunch 1 # maps emulator and other tools with the paths of files such as ramdisk. img, you can directly call emulator and other tools, and solve 3rd Problems
- emulator &
- ddms &
Note: first start ddms and then start eclipse, so that there will be no port conflict in eclipse.
Configure the debugging type and port in eclipse:
Double-click Run-> Debug deployments-> Remote java application and set "Host:" to localhost and "Port:" To 8800, "Connection Type" is Standard (Socket Attach)
Then "Apply"
Note: The port set above must be the same as the port set in DDMS. The ADT plug-in uses port 8700, so the port set above is 8800. If the VM cannot be connected, note that you must select a process corresponding to an application in DDMS before executing Debug in eclipse.
During eclipse debugging, you can set breakpoints and perform one-step debugging. It is estimated that the google team developed and debugged Android applications in this way.
7. Compile the Android source code
Run:
Cd Android source code directory
. Build/envsetup. sh
Then there will be more commands such as mm/mmm. mm/mmm is used to compile modules including C, C ++, and JAVA programs ). You can also execute "make Module name" in the root directory of the Android source code to compile the module Module name, which can be found in the. mk file ). After the module is compiled, it will generate a corresponding .apk package under out/target/product/generic/system/app. However, the. APK compiled with mm/mmmwill not be packaged into the system. in img, We need to manually package the system folder as system through make snod. img, but you have to re-run the simulator, which is also very troublesome. For our developers, we can do this:
1. Remove the modified versions from/system/app, and then make snod,system.imghas no alarmclock.apk.
2) run the simulator and you will not be able to see AlarmClock.
3) modify the source code of AlarmClock and compile it with mm/mmm. Then, generate alarmclock.apk under/system/app.
4. Install alarmclock.apk to the Android file system through adb. there are two installation methods:
A. Run adb install xxx/AlarmClock.apk
B. push xxx/AlarmClock.apk/data/app through adb
You can install AlarmClock under/data/app. androidwill automatically display the lock in the main menu. Only alarmclock.apk contains an Activity package containing android. intent. category. LAUNCHER attribute), but method A generates com.android.alarmclock.apk in/data/app, and method B generates AlarmClock.apk. When using method A, if AlarmClock has been installed, you must first adb uninstall it, and method B does not need. The B method is recommended. Similarly, you can use adb uninstall or adb shell rm xxx/xxx.apk to uninstall the SDK. We recommend that you delete the SDK.
8. How to develop your own projects
The previous section mainly describes how to develop the original Android project on eclipse. For our own projects, we can do this:
1) Create an Android project.
The advantage of building an Android project is that you can make full use of the ADT function.
2) import the required package
3) Compile, run, and debug
4) Add the app to the corresponding Android source code Directory, which is usually stored in packages/apps.
When we observe the original project of packages/apps, we will find that their code is "clean", without folders such as assets and bin automatically generated by ADT and R. java, of course not. classpath and. project
5) write the Makefile xxx. mk.
The dedicated Makefile xxx. mk provided by the Android source code is in a simple format.
6) Add the newly added projectEclipse AndroidEngineering
You can add a path in eclipse or in. classpath. For example, add the following content to. classpath:
- <classpathentry kind="src" path="packages/apps/HelloWorld/src"/>
R. java is automatically generated during compilation. In fact, all projects that use "Resources" will use R. java. These R. java files are placed under out/target/common/R. During makefull code under the source code root directory, modules that have been compiled and generated with .apk files will not be compiled for each worker. Therefore, if the newly added project has been compiled (using mm/mmm), we must change the "resource" of the project first, Because R. java is generated by a "resource"), and then make, you will see the R of your project in the package path corresponding to out/target/common/R. java. Refresh the out/target/common/R sub-project in eclipse, and then add its package to the place where you use the R class, as shown in
Import com. Android. example. test. inside. helloworld. R.
In fact, this error has no effect on us, because we compile it in shell.
7) inEclipse AndroidCompile the newly added project in the source code directory
You can use the mm/mmm Or make Module name.
8) Use a version control tool (svn, git, or other) to upload the project to the server.
From the official documents and practices, we can summarize the following points:
1. You can use eclipse to edit JAVA programs and check for errors mainly in class library inclusion and syntax), but you cannot compile and run the Android source code on eclipse, still make (or mm or mmm) in shell)
2. Some eclipse configuration files are provided in the Android source code folder,
. Claapath: the configuration file of the eclipse project, so that we can directly import the file and JAVA package corresponding to the Android source code to the project.
Android-formatting.xml and android. importorder: This is very important, mainly used to regulate our encoding style, it is easier to make our code style consistent
3. When importing the Android source code as a project into eclipse, pay attention to the following two points:
1) the newly created project must be a java project, not an Android project. Otherwise, the android source code will be damaged. Generally, multiple files/folders are added)
2) check whether the file in. classpath has a corresponding file folder in the Android source code before importing the file. Otherwise, the android source code will be damaged by adding more files/folders)
In general:
1. Use eclipse to edit code and check for errors
2. If you do not compile or run the Android source code program on eclipse, you can only compile the android source code through make (or mm or mmm) on the command line.
3. the Android source code program principle can be debugged on eclipse: eclipse uses the ddms server to debug on emulator), and can perform single-step debugging and breakpoint debugging.
4. The program to be debugged removes it from/system/app/and installs it under data/app, which is more convenient.
5. It is easier to install and uninstall programs by using adb push and adb shell rm.
For example, if you modify the source code in eclipse, use step 1.
- mmm packages/apps/Contacts/
- make snod
- emulator &
Emulator may not run.
Because every time you modify the source code, you should:
- cd /path/to/android/root
- . build/envsetup.sh
- lunch 1
- make
- emulator &
Successful!
Summary: Usage DetailsEclipseDevelopmentAndroidThe content of the source code is introduced.Eclipse AndroidLearning the development source code content can help you!