要在Android Studio中显示Java的字节码,可以使用以下步骤:
在Android Studio中打开要查看字节码的Java文件。
打开“View”菜单,并选择“Tool Windows”下的“Terminal”选项。
在终端窗口中,输入以下命令并按Enter键:
javap -c -s -verbose .java
例如,如果要查看名为"MainActivity.java"的Java文件的字节码,输入以下命令:
javap -c -s -verbose MainActivity.java
这是一个使用Android Studio显示Java字节码的示例:
public class MainActivity {
public static void main(String[] args) {
int a = 10;
int b = 20;
int c = a + b;
System.out.println("Sum: " + c);
}
}
在终端窗口中输入以下命令:
javap -c -s -verbose MainActivity.java
终端窗口将显示以下字节码信息:
Classfile /path/to/MainActivity.class
Last modified 2021-11-01; size 330 bytes
MD5 checksum 1c5a2c6a4eef2816bc8f9e3f9d2cbe6a
Compiled from "MainActivity.java"
public class MainActivity
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Methodref #4.#19 // java/lang/Object."":()V
#2 = Fieldref #20.#21 // java/lang/System.out:Ljava/io/PrintStream;
#3 = Methodref #22.#23 // java/io/PrintStream.println:(Ljava/lang/String;)V
#4 = Class #24 // java/lang/Object
#5 = Utf8
#6 = Utf8 ()V
#7 = Utf8 Code
#8 = Utf8 LineNumberTable
#9 = Utf8 main
#10 = Utf8 ([Ljava/lang/String;)V
#11 = Utf8 SourceFile
#12 = Utf8 MainActivity.java
#13 = Utf8 StackMapTable
#14 = Class #25 // java/lang/System
#15 = Utf8 out
#16 = NameAndType #26:#27 // println:(Ljava/lang/String;)V
#17 = Utf8 Sum:
#18 = Methodref #28.#29 // java/lang/String.valueOf:(I)Ljava/lang/String;
#19 = NameAndType #5:#6 // "":()V
#20 = Class #30 // java/lang/System
#21 = NameAndType #15:#31 // out:Ljava/io/PrintStream;
#22 = Class #32 // java/io/PrintStream
#23 = NameAndType #16:#33 // println:(Ljava/lang/String;)V
#24 = Utf8 java/lang/Object
#25 = Utf8 java/lang/System
#26 = Utf8 println
#27 = Utf8 (Ljava/lang/String;)V
#28 = Class #34 // java/lang/String
#29 = NameAndType #35:#36 // valueOf:(I)Ljava/lang/String;
#30 = Utf8 java/lang/System
#31 = Utf8 Ljava/io/PrintStream;
#32 = Utf8 java/io/PrintStream
#33 = Utf8 (Ljava/lang/String;)V
#34 = Utf8 java/lang/String
#35 = Utf8 valueOf
#36 = Utf8 (I)Ljava/lang/String;
{
public MainActivity();
descriptor: ()V
flags: ACC_PUBLIC
Code:
stack=1, locals=1, args_size=1
0: aload_0
1: invokespecial #1 // Method java/lang/Object."":()V
4: return
LineNumberTable:
line