直接把在launcher2目录下执行mm生成的apk push到emulator上, emulator起不来, 日志报出错误信息如下:
V/RenderScript_jni( 4600): createRenderScript
D/dalvikvm( 4600): Trying to load lib /system/lib/librs_jni.so 0x0
I/dalvikvm( 4600): Unable to dlopen(/system/lib/librs_jni.so): Cannot load library: load_library[1051]: Library '/system/lib/librs_jni.so' not found
D/RenderScript_jni( 4600): RenderScript JNI library not found!
W/dalvikvm( 4600): No implementation found for native Landroid/renderscript/RenderScript;.nDeviceCreate ()I
D/AndroidRuntime( 4600): Shutting down VM
W/dalvikvm( 4600): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 4600): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 4600): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.launcher2/com.android.launcher2.Launcher}: android.view.InflateException: Binary XML file line #25: Error inflating class com.android.launcher2.AllAppsView
E/AndroidRuntime( 4600): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
E/AndroidRuntime( 4600): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime( 4600): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 4600): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 4600): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 4600): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 4600): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 4600): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 4600): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 4600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 4600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 4600): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 4600): Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class com.android.launcher2.AllAppsView
E/AndroidRuntime( 4600): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
E/AndroidRuntime( 4600): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
E/AndroidRuntime( 4600): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
E/AndroidRuntime( 4600): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
E/AndroidRuntime( 4600): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime( 4600): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime( 4600): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
E/AndroidRuntime( 4600): at android.app.Activity.setContentView(Activity.java:1622)
E/AndroidRuntime( 4600): at com.android.launcher2.Launcher.onCreate(Launcher.java:234)
E/AndroidRuntime( 4600): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 4600): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
E/AndroidRuntime( 4600): ... 11 more
E/AndroidRuntime( 4600): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 4600): at com.android.launcher2.AllAppsView.<init>(AllAppsView.java:158)
E/AndroidRuntime( 4600): at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 4600): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
E/AndroidRuntime( 4600): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
E/AndroidRuntime( 4600): ... 21 more
E/AndroidRuntime( 4600): Caused by: java.lang.UnsatisfiedLinkError: nDeviceCreate
E/AndroidRuntime( 4600): at android.renderscript.RenderScript.nDeviceCreate(Native Method)
E/AndroidRuntime( 4600): at android.renderscript.RenderScript.<init>(RenderScript.java:303)
E/AndroidRuntime( 4600): at android.renderscript.RSSurfaceView.createRenderScript(RSSurfaceView.java:151)
E/AndroidRuntime( 4600): at android.renderscript.RSSurfaceView.createRenderScript(RSSurfaceView.java:156)
E/AndroidRuntime( 4600): ... 25 more
I/Process ( 63): Sending signal. PID: 4600 SIG: 3
I/dalvikvm( 4600): threadid=7: reacting to signal 3
E/dalvikvm( 4600): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
E/ActivityThread( 63): Failed to find provider info for android.server.checkin
两处标红的信息告诉我们缺少了两个库文件:libRS.so和librs_jni.so. 本人是手动去添加的,做法如下:
1.
cd <android源码>/frameworks/base/libs/rs
source <android源码>/build/envsetup.sh
mm (生成libRS.so)
mm snod
2.在<android源码>/frameworks/base/graphics/jni目录下生成和添加librs_jni.so的过程同上
3.将<android源码>/packages/apps/Launcher2/res/drawable-hdpi目录里的所有资源拷贝到<android源码>/packages/apps/Launcher2/res/drawable目录下.这样做是因为launcher2默认只提供了hdpi资源,需要的其它分辩率资源找不到时也会报错.
4.重启模拟器 由于launcher2默认只提供了hdpi的资源, 所以好像只能在wvga尺寸的屏幕上正常显示,在常用的HVGA上gridview显示有问题.两种分辩率的效果图:
![Android编译并运行launcher2](http://www.hzhike.com/School/UploadFiles_7810/201106/20110623173343360.jpg)
![Android编译并运行launcher2](http://www.hzhike.com/School/UploadFiles_7810/201106/20110623173344242.jpg)
![Android编译并运行launcher2](http://www.hzhike.com/School/UploadFiles_7810/201106/20110623173344599.jpg)
来源 : http://www.hzhike.com/School/2011/201106/20110623173241.html