Android virtual machine Dalvik, various java package functions of Android, Android related file types, application structure analysis, ADB

With the release of Google's Android SDK, there are countless discussions about its API and its expected impact in the field of mobile phones. However, one of the topics aroused thousands of waves in the Java community, which is the basis of the Android platform - Dalvik virtual machine.

The primary difference between Dalvik and the standard Java virtual machine (JVM)

Dalvik is register based and JVM is stack based., Register based virtual machines take less time to compile for larger programs.

Differences between Dalvik and Java runtime environment

Dalvik is optimized to allow multiple instances of virtual machines to run simultaneously in limited memory, and each Dalvik application is executed as an independent Linux process. Independent processes can prevent all programs from being shut down when the virtual machine crashes

The birth of Dalvik has also led people to worry that the first large-scale separation of the Java platform may be in progress - some people have linked davlik with Microsoft's JVM and sun's lawsuit against Microsoft, waiting to see if similar things will happen to Google; Others pointed out that Google did not claim that Dalvik was a java implementation, while Microsoft did. Sun also expressed concern about the possible division of the camp, and proposed to cooperate with Google to ensure the compatibility between Dalvik and the JVM - Google explained that Dalvik is an attempt to solve the division on the current Java ME platform and to provide a platform with less restricted licenses. Some people even doubt whether this is a large-scale contest between sun and Google for the future of Java.

In Android application development, Java language is usually used. In addition to being familiar with the basic knowledge of Java language, you also need to understand the extended Java functions provided by Android. In general Java applications, if you need to reference the basic class library, you usually need to use the following method: import javax. Swing. *; The above code represents swing, a GUI component that references Java. Javax.swing is a package in Java. Android provides some extended Java class libraries. The class library is divided into several packages, and each package contains several classes.

Description of important packages:

A considerable part of Android itself is written in Java (basically, the blue parts in the frame composition are developed in Java). Android applications must be developed in Java.

Unlike J2SE, Java can be compiled into classes and run directly. Class files on Android platform cannot run directly on Android. Because Google uses its own Dalvik to run applications, the classes here certainly can't run in the Java environment of Android Dalvik. The Android class file is actually an intermediate target file in the compilation process. It needs to be linked into a DEX file before it can run on Dalvik.

The bytecode file format supported by the Android virtual machine Dalvik is defined by Google's own Dalvik virtual machine on the newly released Android platform. This virtual machine does not execute Java bytecode, but another bytecode: the bytecode in dex format. After compiling java code, Java bytecode can be converted into DEX bytecode through tools on Android platform. Although Google says Dalvik is customized for mobile devices, many people in the industry think it is to avoid applying for a Java license from sun. This dalvikvm has been optimized for mobile programs / CPUs, and can run many VMS at the same time without taking up too many resources.

Apk is the extension of Android installation package. An Android installation package contains all files related to an Android application. The APK file packs the androidmanifest.xml file, application code (. DEX file), resource file, and other files into a compressed package. A project can only enter one. APK file.

This example takes a simple helloactivity program as an example to briefly introduce the source code structure of Android application. In fact, although Android applications are not very complex, they usually involve Java programs, XML files and makefile. Helloactivity is simple, but although the sparrow is small and has all kinds of internal organs, it is the best example of learning Android applications.

The source code of helloactivity project is in development / samples / helloactivity / of Android directory. The structure of the code is as follows: tests is an independent project, which can be ignored temporarily. Other parts are seen as an Android application project. The main components of the project are as follows: androidmanifest.xml: the description file of the project, which is useful at runtime. Android.mk: the makefile of the whole project

HelloActivity 的源代码

Res: the directory where the resource files are placed Src / COM / example / Android / helloactivity / helloactivity.java: This is a Java class file. The path of this file represents the position in the structure of the java package of andorid. The use mode of this package is com.example.android.helloactivity.

The helloactivity project will generate out / target / common / obj / apps / helloactivity after compilation_ Intermediates / directory. The contents in this directory are related to helloactivity project. More specifically, they are related to android.mk file in development / samples / helloactivity /.

classes.dex 

Is one of the most important files. It is a bytecode file for Android's Java virtual machine Dalvik to run. Classes.jar is a jar file. Jar means Java archive, that is, Java archive. It is a platform independent file format that can synthesize multiple files into one file. The directory structure after decompression: (classes compiled by Java standard) each file with class extension is actually the bytecode of each class compiled by Java program.

The target APK file is the file installed and run by the Java virtual machine Dalvik of Android. In fact, this APK file will be generated by the intermediate result of compilation and the original file. The essence of APK file is a zip package. The directory structure of the APK package after decompression is as follows:

It is worth noting that the XML file here has been processed, which is different from the original file and cannot be read as a text file.

Android.mk is the "makefile" of the whole project, and its contents are as follows:

This file is similar in all Android projects, including local_ PACKAGE_ Name indicates the name of the package. LOCAL_ MODULE_ Tags represents the module's target. Samples are used here. Eng development is often used in formal applications (applications in the packages directory).

Androidmanifest.xml is the description file of the helloactivity project. Its contents are as follows: package is used to describe the name of the package, Android: labeapplication represents the title displayed on the interface of the application, and Android: name in activity represents the name of the Android activity.

Invalid Sign

Android ADB tool using ADB (Android debug bridge) is a general debugging tool provided by Android. With this tool, my mother can manage the state of the device or mobile phone simulator. ADB function operation: quickly update the code in the device or mobile phone simulator, such as application or Android system upgrade, run shell command on the device, manage the predetermined port on the device or mobile phone simulator, copy and paste files on the device or mobile phone simulator ADB common operations: install applications to the simulator Android does not provide a command to uninstall applications, Can only be deleted manually: enter the shell of the device or simulator. Through the above commands, you can enter the shell environment of the device or simulator. In this Linux shell, you can execute various linux commands. In addition, if you want to execute only one shell command, The following methods can be adopted: for example, the debugging information of the kernel will be printed, and the publishing port can be set as any port number as the request port of the host to the simulator or device. For example: ADB install app.apk ADB shell CD data / APP RM app.apk ADB shell ADB shell [command] ADB shell dmesg ADB forward TCP: 5555 TCP: 8000 ---------------------------------------- Android programming foundation 11 copying files can copy files to or from a device. Copy a file or directory to the device or simulator: for example, copy a file or directory from the device or simulator, such as searching / waiting for simulator The device instance obtains the currently running simulator, the instance list of the device and the status of each instance | wait for the running device to check the bug report and record the wireless communication log. There are many wireless communication logs, which are unnecessary to record during operation, You can access the database SQLite3 ADB push ADB push test.txt/tmp/test.txt ADB pull ADB pull / Android / lib / libwebcore.os ADB devices ADB wait for device ADB bugreport ADB shell logcat - B radio ADB get product ADB get serialno ADB shell

Reproduced at: https://www.cnblogs.com/ITlearning/p/3143497.html

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>