转载自 http://blog.sina.com.cn/s/blog_82f640ed010166ub.html

在CTS Android Hole测试24个failed,查看错误如下:

--------------------------------------------------------------------------------------------------

11-15 15:39:53 I/0123456789ABCDEF:android.holo.cts.HoloTest#testHolo FAIL
junit.framework.AssertionFailedError: Failed bitmap names:[holo_button, holo_button_pressed, holo_progressbar,holo_progressbar_small, holo_progressbar_large,holo_radiogroup_vertical, holo_ratingbar_0, holo_ratingbar_2point5,holo_ratingbar_5, holo_ratingbar_0_pressed,holo_ratingbar_2point5_pressed, holo_ratingbar_5_pressed,holo_searchview, holo_searchview_query, holo_searchview_query_hint,holo_seekbar_0, holo_seekbar_50, holo_seekbar_100, holo_switch,holo_switch_checked, holo_tabhost, holo_toggle_button,holo_toggle_button_checked] Check/mnt/sdcard/cts-holo-assets/failed and/mnt/sdcard/cts-holo-assets/diff for details.
at android.holo.cts.HoloTest.runThemeTest(HoloTest.java:143)
at android.holo.cts.HoloTest.testHolo(HoloTest.java:35)
at java.lang.reflect.Method.invokeNative(Native Method)
atandroid.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
atandroid.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
atandroid.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
atandroid.test.AndroidTestRunner.runTest(AndroidTestRunner.java:190)
atandroid.test.AndroidTestRunner.runTest(AndroidTestRunner.java:175)
atandroid.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
atandroid.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)

--------------------------------------------------------------------------------------------------

花了一个周的时间,终于把Android.hole Test分析清楚,解决了这个问题.

所有源代码路径:

cts\tests\tests\holo\src\android\holo\cts

framework\base\core\java\android\view\

1. Holo测试原理:

1.1)  holoTest启动正常启动自带theme(主题)

runThemeTest(HoloTest.java)->startActivityForResult(ThemeTestActivity.java)->setTheme(LayoutTestActivity.java)->initializeTheme(ContextThemeWrapper.java)

1.2)  快照保存当前主题theme的元素(比如button,textEdit等)比较快照获得元素bitmap和referrencebitmap,判断是否一致,如果一致测试通过,如果不一致,测试失败

protected voidonPreExecute() {

mBitmap =getBitmap();

mReferenceBitmap =BitmapAssets.getBitmap(getApplicationContext(),mBitmapName);

final int threshold = 1;

mSame = compareTo(mBitmap, mReferenceBitmap, threshold);

}

private booleancompareTo(Bitmap bitmap, Bitmap reference, int threshold){

if(bitmap.getConfig() != reference.getConfig() ||

bitmap.getWidth() != reference.getWidth() ||

bitmap.getHeight() != reference.getHeight()) {

return false;

}

int w =bitmap.getWidth();

int h =bitmap.getHeight();

ByteBufferbuffer1 = ByteBuffer.allocate(bitmap.getByteCount());

ByteBufferbuffer2 = ByteBuffer.allocate(reference.getByteCount());

bitmap.copyPixelsToBuffer(buffer1);

reference.copyPixelsToBuffer(buffer2);

final int length= w*h;

for (int i = 0; i< length; i++) {

int pel1 = buffer1.getInt(i);

intpel2 = buffer2.getInt(i);

int dr = (pel1 & 0x000000FF) - (pel2 &0x000000FF);

int dg = ((pel1 & 0x0000FF00) - (pel2 & 0x0000FF00))>> 8;

int db = ((pel1 & 0x00FF0000) - (pel2 & 0x00FF0000))>> 16;

//在这里比较图片,注意表示的颜色

if (Math.abs(db) > threshold ||

Math.abs(dg) > threshold ||

Math.abs(dr) > threshold) {

return false;

}

if (bitmap.hasAlpha()) {

int da = ((pel1 & 0xFF000000) - (pel2 & 0xFF000000))>> 24;

if (Math.abs(da) > threshold) {

Log.i(TAG, "++++++++compareTo 3 ++++++++++" );

returnfalse;

}

}

}

Log.i(TAG, "++++++++compareTo 4 ++++++++++" );

return true;

}

Referrencebitmap在哪里?

cts\tests\tests\holo\res 里面的drawable, 里面是不是有好多drawable啊,你知道为什么吗?懂得应用程序开发的估计都知道,这个就是为了适应各种LCD尺寸和denisity的。(这个很重要哦)

1.3) 如果两个bitmap不一致,就保存到手机上 /mnt/sdcard/diff 和/mnt/sdcard/failed两个文件夹里面。

saveBitmap(LayoutTestActivity.java) ->  BitmapAssets.saveBitmap(BitmapAssets.java)

显示效果图如下:

注意红色表示的就是两个bitmap差异之处,具体看源代码。

2. 测试原因分析

在网上查找了几天,用百度没有搜索出任何有用信息,最后还是google出大拿的一话,恍然大悟:

Android.hool test failed depends onscreen type and dpi, this test still fail with 1280x720 resolutionwith density 320, but can pass with density 240.

原来我的手机屏幕是1280x720 320dpi的,所以显示效果会有差异,导致失败了。

3. 解决办法

# vimdevice/xxx/system.prop

rild.libpath=/system/lib/libreference-ril.so

rild.libargs=-d /dev/ttyS0

ro.sf.lcd_density=320

修改其中ro.sf.lcd_density=240

重新烧录编译img文件下载,重新测试,结果如下:

11-15 15:03:56 I:android.holo.cts.HoloTest#testHolo PASS

11-15 15:05:06 I:android.holo.cts.HoloTest#testHoloDialog PASS

11-15 15:06:13 I/emulator-5554:android.holo.cts.HoloTest#testHoloDialogMinimumWidthPASS

11-15 15:07:17 I:android.holo.cts.HoloTest#testHoloDialogNoActionBar PASS

11-15 15:08:24 I/emulator-5554:android.holo.cts.HoloTest#testHoloDialogNoActionBarMinimumWidthPASS

11-15 15:09:31 I:android.holo.cts.HoloTest#testHoloDialogWhenLarge PASS

11-15 15:10:40 I/emulator-5554:android.holo.cts.HoloTest#testHoloDialogWhenLargeNoActionBarPASS

11-15 15:11:41 I:android.holo.cts.HoloTest#testHoloInputMethod PASS

11-15 15:12:53 I:android.holo.cts.HoloTest#testHoloLight PASS

11-15 15:14:04 I:android.holo.cts.HoloTest#testHoloLightDarkActionBarPASS

11-15 15:15:12 I:android.holo.cts.HoloTest#testHoloLightDialog PASS

11-15 15:16:20 I:android.holo.cts.HoloTest#testHoloLightDialogMinimumWidthPASS

11-15 15:17:24 I:android.holo.cts.HoloTest#testHoloLightDialogNoActionBarPASS

11-15 15:18:31 I:android.holo.cts.HoloTest#testHoloLightDialogNoActionBarMinimumWidthPASS

11-15 15:19:42 I:android.holo.cts.HoloTest#testHoloLightDialogWhenLargePASS

11-15 15:20:54 I/:android.holo.cts.HoloTest#testHoloLightDialogWhenLargeNoActionBarPASS

11-15 15:22:06 I/:android.holo.cts.HoloTest#testHoloLightNoActionBar PASS

11-15 15:23:17 I/:android.holo.cts.HoloTest#testHoloLightNoActionBarFullscreenPASS

11-15 15:24:18 I/:android.holo.cts.HoloTest#testHoloLightPanel PASS

11-15 15:25:26 I/:android.holo.cts.HoloTest#testHoloNoActionBar PASS

11-15 15:26:36 I/:android.holo.cts.HoloTest#testHoloNoActionBarFullscreenPASS

11-15 15:27:36 I:android.holo.cts.HoloTest#testHoloPanel PASS

11-15 15:28:49 I:android.holo.cts.HoloTest#testHoloWallpaper PASS

11-1515:30:01 I: android.holo.cts.HoloTest#testHoloWallpaperNoTitleBarPASS

4. 补充

还有一种办法是,可以生成支持1280x720 320dpi的holo ReferrenceBitmap,就是增加一个res/drawable-xxx 文件夹,具体看HoloTestUtilitiesActivity.java。这个我还没有花时间研究,谁有兴趣可以看看。

JellyBean CTS Android.holo Failed问题解决相关推荐

  1. kafka重新启动时出现:found a corrupted index file due to requirement failed问题解决方法

    kafka重新启动时出现:found a corrupted index file due to requirement failed问题解决方法 参考文章: (1)kafka重新启动时出现:foun ...

  2. Android 异常: failed to connect to localhost/127.0.0.1

    Android 异常: failed to connect to localhost/127.0.0.1 参考文章: (1)Android 异常: failed to connect to local ...

  3. Android: Execution failed for task ':app:processDebugResources' 异常解决

    Android: Execution failed for task ':app:processDebugResources' 解决: sudo apt-get install -y lib32gcc ...

  4. android开发 bug问题解决:Only the original thread that created a view hierarchy can touch its views

    android开发 bug问题解决:Only the original thread that created a view hierarchy can touch its views. 翻译:只有创 ...

  5. 史上最全canOpenURL: failed问题解决办法

    史上最全canOpenURL: failed问题解决办法 由于苹果在IOS9.0开始规定在App中使用Https协议与服务器进行数据交互,导致很多原本正常的功能,莫名的就崩掉了.查看控制台 就会看到各 ...

  6. Unity出现 error building player exception android (invocation failed)

    今天在编译Android的时候出现这个错误 error building player exception android (invocation failed) 百度谷歌之后,看到xuanyuson ...

  7. vue/js如何精准获取用户当前地理位置,精准获取经纬度、精准地图选点,Android定位偏移问题解决

    前言: 当时h5页面使用腾讯地图.百度地图.高德地图等获取用户当前地理位置坐标,均有偏移,偏移好几公里,无法获取精准经纬度.最后调用了微信jssdk的方法,才获取了精准的经纬度. 二.具体步骤 1.调 ...

  8. [Android Studio]Failed to install Intel HAXM 问题解决

    问题描述: 在安装 android-studio-bundle-135.1740770-windows.exe时弹出如下信息 安装环境: 分析问题: 1. 错误日志haxm_silent_run.lo ...

  9. Android之failed for task ‘:app:dexDebug‘致gradle编译OOM问题解决(android-support-multidex)

    当我们的业务越来越多,项目里面的方法和第三方的jar包也会越来越多,然后昨晚就遇到了下面这个问题 UNEXPECTED TOP-LEVEL EXCEPTION:at com.android.dx.me ...

最新文章

  1. python作图一览
  2. 处女座的百日理财计划
  3. 为什么有了MAC层还要走IP层呢?
  4. 实现OC与JS的交互
  5. 在JDK 12精简数字格式中使用最小分数数字
  6. [css] 说说你对前端二倍图的理解?移动端使用二倍图比一倍图有什么好处?
  7. 电子美图更新36张!
  8. RocketMQ是怎么存储消息的?
  9. 中小卖家需要避开的三个坑
  10. 编程实现 有符号乘法溢出判断
  11. php中访问控制_PHP之Trait详解
  12. win10风格美化以及新建系统后优化
  13. 数理统计基本原理复习
  14. 计算机网络超详细笔记(三):数据链路层
  15. Android__ListView控件的使用
  16. cad断点快捷键_CAD如何打断?CAD打断点和CAD打断命令操作方法
  17. 不忘来时路 心系梦归处
  18. 数据库原理及应用实验:数据库安全性控制
  19. 解决Unknown resampling filter (64). Use Image.NEAREST (0), Image.LANCZOS (1), Image.BILINEAR (2), Imag
  20. 计算机中丢失IDAP,certify_ldap.dll

热门文章

  1. 据说,程序员们都需要这样的一张壁纸
  2. 问题口袋中有红黄蓝白黑5种颜色的球若干个。每次从口袋中任意取出三个球,问得到3中不通过颜色的球的可能取法。
  3. 网站运营手册_2020年在线运营计划表(运营方案),6套流程分解,大家参考使用...
  4. date月份加一_js日期、月份:日期加一天等
  5. iOS苹果手机上最好的3个mobi阅读器
  6. 《Python语言程序设计》王恺 机械工业出版社 第二章课后习题答案
  7. mybatis查询数据中文乱码
  8. iPhone的设置中,为何找不到“开发者选项”
  9. 数据驱动分析实践七 - 市场响应模型
  10. 计算机组成原理定点除法手工与机器运算本质,计算机组成原理和结构图式(第二章)...