Run Dalvik on X86

from:http://guoh.org/lifelog/2013/02/run-dalvik-on-x86/


很早以前就想过自己编译一个X86上的Dalvik出来玩玩,尝试之后没有成功,就放下了,最近几个月来又想起来搞搞,按照/PATH/TO/AOSP/dalvik/docs/hello-world.html来编译dalvikvm,创建dex档案,设置各种环境变量之后,运行出现错误

1 E/dalvikvm(10105): execv '/home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/bin/dexopt'failed: No such fileor directory
2 W/dalvikvm(10102): DexOpt: --- END 'Foo.jar'--- status=0x0100, process failed
3 E/dalvikvm(10102): Unable to extract+optimize DEX from 'Foo.jar'
4 Dalvik VM unable to locateclass 'Foo'
5 W/dalvikvm(10102): threadid=1: thread exiting with uncaught exception (group=0xf5a1d9c8)
6 java.lang.NoClassDefFoundError: Foo
7 at dalvik.system.NativeStart.main(Native Method)
8 Caused by: java.lang.ClassNotFoundException: Didn't findclass "Foo"on path: DexPathList[[zip file"Foo.jar"],nativeLibraryDirectories=[/home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/lib]]
9 at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
10 at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
11 at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
12 ... 1 more

在网络上搜了很久没有出现过这种错误现象的,实在无赖提了个问题
在StackOverflow上,一个星期过去了,还是无人问津

最终请教了一个做Dalvik相关工作的同事,在他的帮助之下解决了问题

原来是我的ANDROID_ROOT写的有问题,可能是我没有理解好/PATH/TO/AOSP/dalvik/docs/hello-world.html的意思,也或者是它的内容比较陈旧。
后来改了就可以正常运行了,我改过的rund请参见https://gist.github.com/guohai/5048153

现在描述下主要过程
1. Download AOSP source code

2. Compile dalvik vm on Ubuntu 11.10 X64

1 sourcebuild/envsetup.sh
2 lunch 2 # choose full_x86-eng, because we want to run it on X86 directly
3 makedalvikvm core dexopt ext framework android.policy services

3. Compile Java code and package it to dex.

4. Run & enjoy it.

1 guohai@KNIGHT:~/dev/src/android/git/aosp$ ./rund -cpFoo.jar Foo
2 I/dalvikvm( 3473): DexOpt: mismatch dep name: '/home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/framework/core.odex'vs. '/system/framework/core.odex'
3 E/dalvikvm( 3473): /home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/framework/ext.jar odex has stale dependencies
4 I/dalvikvm( 3473): Zip is good, but no classes.dex inside, and no valid .odex fileinthe same directory
5 I/dalvikvm( 3473): DexOpt: mismatch dep name: '/home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/framework/core.odex'vs. '/system/framework/core.odex'
6 E/dalvikvm( 3473): /home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/framework/framework.jar odex has stale dependencies
7 I/dalvikvm( 3473): Zip is good, but no classes.dex inside, and no valid .odex fileinthe same directory
8 I/dalvikvm( 3473): DexOpt: mismatch dep name: '/home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/framework/core.odex'vs. '/system/framework/core.odex'
9 E/dalvikvm( 3473): /home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/framework/android.policy.jar odex has stale dependencies
10 I/dalvikvm( 3473): Zip is good, but no classes.dex inside, and no valid .odex fileinthe same directory
11 I/dalvikvm( 3473): DexOpt: mismatch dep name: '/home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/framework/core.odex'vs. '/system/framework/core.odex'
12 E/dalvikvm( 3473): /home/guohai/dev/src/android/git/aosp/out/target/product/generic_x86/system/framework/services.jar odex has stale dependencies
13 I/dalvikvm( 3473): Zip is good, but no classes.dex inside, and no valid .odex fileinthe same directory
14 I/dalvikvm( 3473): DexOpt: sourcefilemod timemismatch (4244043d vs 425baf6a)
15 Hello, Dalvik!

一些对我有些帮助的资料

http://stackoverflow.com/questions/6146983/helloworld-cannot-run-under-dalvikvm

http://stackoverflow.com/questions/11773506/how-to-launch-jar-with-exec-app-process-on-android-ics

http://blog.csdn.net/johnnynuaa/article/details/6543425

附上自己无法运行的启动脚本

1 #!/bin/sh
2
3 # base directory, at top of source tree; replace with absolute path
4 base=`pwd`
5
6 # configure root dir of interesting stuff
7 root=$base/out/target/product/generic_x86/system
8 exportANDROID_ROOT=$root #为什么这里不能指到target的路径?
9
10 exportLD_LIBRARY_PATH=$root/lib:$LD_LIBRARY_PATH
11
12 # configure bootclasspath
13 bootpath=$root/framework
14 exportBOOTCLASSPATH=$bootpath/core.jar:$bootpath/ext.jar:$bootpath/framework.jar:$bootpath/android.policy.jar:$bootpath/services.jar
15
16 # this is where we create the dalvik-cache directory; make sure it exists
17 exportANDROID_DATA=/tmp/dalvik_$USER
18 mkdir-p $ANDROID_DATA/dalvik-cache
19
20 exec$base/out/host/linux-x86/bin/dalvikvm -Xdexopt:none $@


你可能感兴趣的:(android,成功,System,process,product)