The tool chain and development tools provided by Android are relatively complete, so its development environment is relatively simple. I believe that many friends have already built a good environment and written the HelloActivity introductory program. Here are a few questions:
1. What is the file system structure of Android, and where is the program we installed?
After compiling the Android source code, some files in out/target/product/generic:
、、、 system、 data、root
Among them, it is obtained by system packaging and compression, and is obtained by data packaging and compression.
It is the file system of the emulator. You can find out that the files in it are basically the same as those in the root folder.
The emulator loads and decompresses it to memory, and then mounts and then to the system and data directories under ramdisk respectively. The application we compiled is placed under system/app. The program installed by the user is placed under data/app.
2. What tools can Android SDK and Android source code provide us?
The Android SDK provides many tools, such as adb, ddms, emulator, aapt, etc., and provides kernel-qemu,,,,,. Therefore, as long as we have the Android SDK, we can run Android on the emulator.
The Android source code can compile android SDK, adb and other tools, and Android file system, as well as ADT plug-ins. That is to say, we can compile all Android-related things from the Android source code.
3. After the Android source code "make" is used, many tools and Android file systems will be generated (etc.), and we can use "make sdk" to generate the Android SDK. The Android SDK also includes tools and Android file systems (etc.). We also installed the Android SDK during the installation. So what tools and Android file systems should we use during development?
This question is answered later.
4. The official recommendation is to use eclipse+adt to enter the development application, and our HelloActivity program is also developed here. When we import the project under Android source code /packages /apps/ into eclipse, we usually get an error of not finding the package.So how do we modify, compile and debug the Android source code? What tools does Google use to develop Android?
This question is answered later.
The following systematically describes the establishment of android development environment and the use of development tools.
1. Installation of android SDK and eclipse and establishment of android development environment
The Android tool chain is relatively complete and requires few external tools. For the specific installation process, please refer to the official documentation or <<android emulator installation>> and <<android source code compilation>>.
It should be noted here that when using "make" to compile Android source code, we can use JDK5 or JDK6; when using "make sdk" to compile, javadoc will be used to generate documents. javadoc must use JDK5's javadoc, otherwise the compilation will not be possible. Therefore, we can install both JDK5 and JDK6, and then point only javadoc and javadoc. to the corresponding tools of JDK5. Other tools are still used by JDK6. Of course, we can only install JDK5 or use only JDK5 tools. For specific operations, please refer to <<android source code compilation>>
2. Use eclipse to develop Android source code
Here we mainly refer to the official documents
/a//opensource/using-eclipse
Below, we summarize the specific details of how to use eclipse to develop Android source code from the official document
1. Establish a basic android development environment
Please refer to the official documentation or <<Android emulator installation in ubuntu8.10>>
2. Compile android source code
Compiled through make in the root directory of the Android source code. Please pay attention to some configurations. For details, please refer to <<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 the eclipse memory settings
Change the 3 values (in the installation directory of the eclipse software) to the following values:
-Xms128m
-Xmx512m
-XX:MaxPermSize=256m
2) Import and import eclipse (optional)
, .classpath and all are placed under development/ide/eclipse/
Used to configure the code style of the eclipse editor; used to configure the order and structure of the import of eclipse.
Import in window->preferences->java->Code style->Formatter
Import in window->preferences->java->Code style->Organize Imports
3) Install anyedit plug-in (optional)
Download and import eclipse in /anyedit/
5. Import android source code into eclipse as a project
Before importing, check whether the files in the .classpath have corresponding files (folders) in the android source code, otherwise it will also destroy the android source code (usually adding more files/folders). The extra paths in the .classpath can be deleted.
Create a new Java Project (not an Android project, otherwise it will destroy the Android source code), select import from an existing project, and complete the project name.
When importing, eclipse needs to build the project, which is relatively slow. After the introduction, there are usually no errors.
Here we answer the fourth question
6. Debug the programs in Android on eclipse.
In order not to allow other versions of android tools and android file systems to affect the following compilation and debugging, the paths of android tools and android file systems need to be removed from the environment variables:
vim ~/.bashrc
See if there is any path to add android tools and android file system to the PATH variable, and if added, comment it. Through the following method, we do not need to add the path to android tools and android file system in .bashrc
implement:
cd android source code directory
. build/ #After setting the environment variable, there will be additional commands such as mm. You can view it by entering help.
lunch 1 # Correlate the paths of tools such as emulator and files, and you can directly call tools such as emulator, which also solves the third problem
emulator &
ddms &
Note, start ddms first, then start eclipse, so that there will be no port conflict in eclipse.
Then configure the debug type and port in eclipse:
Double-click on Run->Debug Configurations->Remote java application, then set "Host:" to localhost, "Port:" to 8800, and "Connection Type" to Standard(Socket Attach)
Then "Apply"
Note that the port set above should be consistent with the port set in DDMS. The ADT plug-in uses port 8700, so the port set above is 8800. If an error occurs when you cannot connect to the VM, please note that you must first select a process (corresponding to a certain application) in DDMS before you can execute Debug in eclipse.
During eclipse debugging, breakpoints can be set and debugged step by step. It is estimated that the Google team also develops and debugs Android applications in this way.
7. Compile android source code
implement:
cd android source code directory
. build/
Then there will be extra commands such as mm/mmm, which are used to compile modules (including C, C++, and JAVA programs). We can also directly execute "make module name" in the root directory of the Android source code to compile the module (the module name can be found in the .mk file). After the module is compiled, the corresponding .apk package will be generated under out/target/product/generic/system/app. However, using mm/mm to compile the generated .apk will not be packaged into it. We need to manually package the system folder through make snod, but this requires re-running the emulator, which is also very troublesome. For us developers, we can do this:
1) Remove the modules that need to be modified and debugged (for example) from /system/app, and then make snod, so there is no more.
2) Run the emulator and you won't see AlarmClock
3) Modify the AlarmClock source code and compile it with mm/mmmm, and generate it under /system/app
4) Install it into the Android file system through adb. There are two installation methods:
A. Through adb install xxx/
B. Through adb push xxx/ /data/app
Both methods can install AlarmClock in /data/app, and Android will automatically display it in the main menu (as long as there is an Activity containing the attributes), but method A is generated in /data/app, and method B is. When using method A, if AlarmClock has been installed, you have to adb uninstall it first, while method B does not use method B. It is recommended to use method B. Similarly, uninstall can be done through adb uninstall or adb shell rm xxx/. It is also recommended to use deletion to uninstall.
8. How to develop your own project
The previous article mainly talks about how to develop android original projects on eclipse. For our own project, we can do this:
1) Create a new Android project.
The advantage of building an Android project is that it can make full use of ADT functions.
2) Import the required packages
3) Compile, run, debug
4) Add to the corresponding directory of the Android source code, and the application is usually placed under packages/apps
When we observe the original projects of packages/apps, we will find that their code is very "clean", there are no folders such as assets, bin and other automatically generated by ADT, and of course there are no .classpath and .project
5) Write Makefile
The special Makefile file provided by Android source code is relatively simple in format
6) Add the newly added project to the android project of eclipse
You can add it in eclipse or you can directly add the corresponding path in .classpath. As added in .classpath:
<classpathentry kind="src" path="packages/apps/HelloWorld/src"/>
It is automatically generated during compilation. In fact, all projects that use "resources" will be used. These are placed under out/target/common/R. We will generate each module only when we make all the code in the source code root directory; when making, modules that have been compiled and generated with .apk files will not be compiled. Therefore, if the newly added project has been compiled (using mm/mmm), we will first change the "resource" of the project (it must be a "resource" because it is generated by the "resource"), and then make, and you will see your project under the package path corresponding to out/target/common/R. Refresh the out/target/common/R sub-project in eclipse, and then add its package where you use R, such as
import ; This way, there will be no error in not finding the R definition.
In fact, this error has no effect on us because we compile in the shell.
7) Compile the newly added project in the Android source code directory
You can use mm/mmmm or make module name
8) Use version control tools (svn or git or other) to upload the project to the server
The above is the compilation and debugging of Android source code. We will continue to organize relevant information in the future. Thank you for your support for this website!