`
阿尔萨斯
  • 浏览: 4183803 次
社区版块
存档分类
最新评论

编译x86 平台的dalvik

 
阅读更多

参考文章:

我实验的版本是android 4.222222r1。

通过repo init和repo sync下载好源码之后,

敲命令:source ./build/envsetup.sh

然后:lunch


1
2
3
4
5
6
7
8
9
10
11
12
13
You're building on Linux
Lunch menu... pick a combo:
1. full-eng
2. full_x86-eng
3. vbox_x86-eng
4. full_stingray-userdebug
5. full_wingray-userdebug
6. full_crespo4g-userdebug
7. full_crespo-userdebug
8. full_maguro-userdebug
9. full_toro-userdebug
10. full_tuna-userdebug
11. full_panda-eng

输入2,回车。

然后,输入命令:make dalvikvm core ext dexopt framework android.policy services-j16

最后一个参数是为了加快编译速度,根据自己的机器配置来设置。

编译完成之后,如果cd到out/target/product/generic_x86/system/bin

然后,ll

会看到有如下两个文件:

1
2
3
4
5
6
wuhe.jyh@ubuntu:~/4.0.3r1/out/target/product/generic_x86/system/bin$ ll
total 32
drwxr-xr-x 2 wuhe.jyh wuhe.jyh 4096 2013-06-03 15:29 ./
drwxr-xr-x 5 wuhe.jyh wuhe.jyh 4096 2013-06-03 15:29 ../
-rwxr-xr-x 1 wuhe.jyh wuhe.jyh 8311 2013-06-03 15:29 dalvikvm*
-rwxr-xr-x 1 wuhe.jyh wuhe.jyh 12204 2013-06-03 15:29 dexopt*

此时,输入dalvikvm回车:

1
2
3
E/dalvikvm(24398): ERROR: must specify non-'.'bootclasspath
W/dalvikvm(24398): CreateJavaVM failed: dvmClassStartup failed
Dalvik VM init failed (check logfile)

如果cd到android 源码目录~/4.2222r1,然后执行:

./out/target/product/generic_x86/system/bin/dalvikvm

则:

1
2
wuhe.jyh@ubuntu:~/4.0.3r1$ ./out/target/product/generic_x86/system/bin/dalvikvm
-bash: ./out/target/product/generic_x86/system/bin/dalvikvm: No suchfileor directory


启动dalvik,还是需要一些环境设置,用脚本比较方便。在源码根目录,创建文件rund.sh,内容如下(https://gist.github.com/guohai/5048153):

rund.sh ---修改版
我实验的版本是android 4.222222r1。
#!/bin/sh
# base directory, at top of source tree; replace with absolute path
base=`pwd`
# configure root dir of interesting stuff
root=$base/out/host/linux-x86
export ANDROID_ROOT=$root
export LINUX_86_LIb=$base/out/host/linux-x86
export DEX_BOOTJARS=$base/out/target/product/generic_x86/dex_bootjars/system/framework
# configure bootclasspath
bootpath=$base/out/target/product/generic_x86/system/framework
export BOOTCLASSPATH=$bootpath/core.jar:$bootpath/ext.jar:$bootpath/framework.jar:$bootpath/android.policy.jar:$bootpath/services.jar:$DEX_BOOTJARS/conscrypt.jar
export LD_LIBRARY_PATH=$bootpath/lib:$LD_LIBRARY_PATH:$LINUX_86_LIb/lib
# this is where we create the dalvik-cache directory; make sure it exists
export ANDROID_DATA=/tmp/dalvik_$USER
mkdir -p $ANDROID_DATA/dalvik-cache
exec $root/bin/dalvikvm -Xdexopt:none $@
如果上面的运行有错误的话,肯定是缺一些包或者是库、类之类的,自己在编译好的android 工程中找,就上就行了


然后chmod a+x rund.sh

然后,我们创建一个Java文件:

1
2
3
4
5
classFoo {
publicstaticvoidmain(String[] args) {
System.out.println("Hello, Foo!!");
}
}

保存为Foo.java到源码根目录。

然后,shell里边执行:

javac Foo.java

dx --dex --output=Foo.dex Foo.class

然后,我们来执行dalvik虚拟机:

./rund.sh -cp Foo.dex Foo回车

结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
I/dalvikvm(24743): DexOpt: mismatch dep name:'/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/core.odex'vs.'/system/framework/core.odex'
E/dalvikvm(24743):/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/ext.jar odex has stale dependencies
I/dalvikvm(24743): Zip is good, but no classes.dex inside, and no valid .odexfileinthe same directory
I/dalvikvm(24743): DexOpt: mismatch dep name:'/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/core.odex'vs.'/system/framework/core.odex'
E/dalvikvm(24743):/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/framework.jar odex has stale dependencies
I/dalvikvm(24743): Zip is good, but no classes.dex inside, and no valid .odexfileinthe same directory
I/dalvikvm(24743): DexOpt: mismatch dep name:'/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/core.odex'vs.'/system/framework/core.odex'
E/dalvikvm(24743):/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/android.policy.jar odex has stale dependencies
I/dalvikvm(24743): Zip is good, but no classes.dex inside, and no valid .odexfileinthe same directory
I/dalvikvm(24743): DexOpt: mismatch dep name:'/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/core.odex'vs.'/system/framework/core.odex'
E/dalvikvm(24743):/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/services.jar odex has stale dependencies
I/dalvikvm(24743): Zip is good, but no classes.dex inside, and no valid .odexfileinthe same directory
Hello, Foo!!


如果要用gdb调试,只要把rund.sh最后一句修改成:

exec gdb $root/bin/dalvikvm

然后,

./rund.sh

然后在gdb调试下输入运行参数:

setargs-cphello.jarhello

设置断点

bmain

以下就可以单步调试dalvik了。

以下是我的运行结果:

wuhe.jyh@ubuntu:~/4.0.3r1$ ./rund.sh
GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/wuhe.jyh/4.0.3r1/out/host/linux-x86/bin/dalvikvm...done.
(gdb) set args -cp Foo.dex Foo
(gdb) b main
Breakpoint 1 at 0x804877a: file dalvik/dalvikvm/Main.cpp, line 152.
(gdb) r
Starting program: /home/wuhe.jyh/4.0.3r1/out/host/linux-x86/bin/dalvikvm -cp Foo.dex Foo
[Thread debugging using libthread_db enabled]
Breakpoint 1, main (argc=4, argv=0xffffcdf4) at dalvik/dalvikvm/Main.cpp:152
152     setvbuf(stdout, NULL, _IONBF, 0);
(gdb) c
Continuing.
I/dalvikvm(24808): DexOpt: mismatch dep name:'/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/core.odex' vs.'/system/framework/core.odex'
E/dalvikvm(24808):/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/ext.jar odex has stale dependencies
I/dalvikvm(24808): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
I/dalvikvm(24808): DexOpt: mismatch dep name:'/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/core.odex' vs.'/system/framework/core.odex'
E/dalvikvm(24808):/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/framework.jar odex has stale dependencies
I/dalvikvm(24808): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
I/dalvikvm(24808): DexOpt: mismatch dep name:'/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/core.odex' vs.'/system/framework/core.odex'
E/dalvikvm(24808):/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/android.policy.jar odex has stale dependencies
I/dalvikvm(24808): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
I/dalvikvm(24808): DexOpt: mismatch dep name:'/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/core.odex' vs.'/system/framework/core.odex'
E/dalvikvm(24808):/home/wuhe.jyh/4.0.3r1/out/target/product/generic_x86/system/framework/services.jar odex has stale dependencies
I/dalvikvm(24808): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
[New Thread 0xf4ef3b70 (LWP 24811)]
[New Thread 0xf46eeb70 (LWP 24812)]
[New Thread 0xf3ee9b70 (LWP 24813)]
[New Thread 0xf36e8b70 (LWP 24814)]
[New Thread 0xf2ee3b70 (LWP 24815)]
Hello, Foo!!
[Thread 0xf36e8b70 (LWP 24814) exited]
[Thread 0xf2ee3b70 (LWP 24815) exited]
[Thread 0xf3ee9b70 (LWP 24813) exited]
[Thread 0xf46eeb70 (LWP 24812) exited]
[Thread 0xf4ef3b70 (LWP 24811) exited]
Program exited normally.
gdb调试,可以用ctrl x+a切换到简易的图形界面。就像vc下的调试,可以对应到代码行。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics