As far as my habits are concerned, I am not too accustomed to programming with an IDE. There are two reasons: first, the computer is slow, and programming requires you to wait for half a day to open the IDE; second, it is easy to become lazy with IDE, and wait for a while after entering the name of an object, IDE will automatically list a large number of objects, such as methods and interfaces. You only need to press a direction key to select and seldom check documents, it takes a long time to make people feel lazy. If you want to learn something, you still need to start with the command line, and then consider using IDE.
The following describes how to create, compile, run, and debug an android project under the command line.
1. Create a project:
Run "activitycreator. py -- out huaow edu. BUPT. huaow. Example" in the directory where the project is to be stored"
Description:
Activitycreator. py: Create a project script file. in Linux, use "activitycreator. py". If it is windows, replace it with "activitycreator. Bat"
-- Out huaow, where huaow is the output directory of the generated project. All the files executing the android project will be placed in this directory.
Edu. BUPT. huaow. example. This is the package name and the class name. The last field is the name of the generated class, and edu. BUPT. huaow is the package where the example class is located.
After the command is executed, all files of the project will be generated in the huaow directory.
After execution, the terminal outputs the following:
Package: edu. bupt. huaow
Out_dir: huaow
Activity_name: example
Created directory huaow/src/edu/bupt/huaow
Added file huaow/src/edu/bupt/huaow/example. java
Created directory huaow/bin
Created directory huaow/res/values
Added file huaow/res/values/strings. xml
Created directory huaow/res/layout
Added file huaow/res/layout/main. xml
Added file huaow/AndroidManifest. xml
Added file huaow/build. xml
2. Project Compilation:
Ant is needed to compile here, ant is apache for compiling java project file tool, android is based on java design, so here to use it, ant can be downloaded in the http://ant.apache.org, the installation process is similar to that of java and android. You can decompress the package and set the environment variables. For details, refer to setting the java environment variables in linux.
Use ant compilation to directly execute a simple "ant" in the project directory, without any parameters, ant will follow the build. the description in the xml file automatically performs relevant syntax check, dependency analysis, and so on, and finally outputs the compiled file to the bin directory of the project.
After execution, the terminal outputs the following:
Buildfile: build. xml
Dirs:
[Mkdir] Created dir:/home/wangtao/Documents/android/huaow/bin/classes
Resource-src:
[Echo] Generating R. java...
Aidl:
Compile:
[Javac] Compiling 2 source files to/home/wangtao/Documents/android/huaow/bin/classes
Dex:
Package-res:
Package-res-no-assets:
[Echo] Packaging resources...
Package-dex:
[Echo] Packaging dex...
Package:
BUILD SUCCESSFUL
Total time: 6 seconds
3. program running and debugging:
The tool used here is the android debugging tool adb, which is used to install the program. First, enter "emulator" in the command line to start the android simulator.
After the simulator is fully started, Run "adb install bin/example.apk" to install example.apk to the simulator.
Finally, the "example" executable program is found in the "Applications" category of the simulator.
After execution, the terminal outputs the following:
* Daemon not running. starting it now *
33 KB/s (4170 bytes in 0.120 s)