当我运行我的Andr​​oid UIAutomator code,它会显示错误我的、当我、它会、错误

2023-09-04 23:34:19 作者:仙女味小甜甜

当我运行我的Andr​​oid UIAutomator code,它显示了以下错误。

  

INSTRUMENTATION_RESULT:shortMsg = java.lang.RuntimeException的   INSTRUMENTATION_RESULT:longMsg = com.android.ui.testing   INSTRUMENTATION_ code:0

我只是跑在developer.android.com 给出的样本code 如何解决这个问题?

日志连接如下:

  1月1号至5日:07:53.559:D / AndroidRuntime(5712):>>>>>> AndroidRuntime开始com.android.internal.os.RuntimeInit<<<<<<
1月1号至5号:07:53.559:D / AndroidRuntime(5712):CheckJNI为ON
1月1号至5号:07:53.559:E / AndroidRuntime(5712):无法打开客户XML文件
1月1号至5号:07:53.559:E / AndroidRuntime(5712):/system/csc/customer.xml无法打开文件
1月1号至5号:07:53.564:D / AndroidRuntime(5712):readGMSProperty:启动
1月1号至5号:07:53.564:D / AndroidRuntime(5712):readGMSProperty:已经设置好的!
1月1号至5号:07:53.564:D / AndroidRuntime(5712):readGMSProperty:结束
1月1号至5号:07:53.589:D / dalvikvm(5712):试图加载LIB libjavacore.so为0x0
1月1号至5号:07:53.599:D / dalvikvm(5712):libjavacore.so为0x0添加共享库
1月1号至5号:07:53.609:D / dalvikvm(5712):试图加载LIB libnativehelper.so为0x0
1月1号至5号:07:53.609:D / dalvikvm(5712):libnativehelper.so为0x0添加共享库
1月1号至5号:07:53.664:I / dalvikvm(5712):Zip是不错的,但没有classes.dex内,并在同一目录中没有有效的.odex文件
1月1号至5号:07:53.874:D / dalvikvm(5712):注:类Landroid / APP / ActivityManagerNative;拥有152未实现(抽象)方法
1月1号至5号:07:53.924:D / AndroidRuntime(5712):调用主入口com.android.commands.uiautomator.Launcher
1月1号至5号:07:53.934:D / AndroidRuntime(5712):关闭虚拟机
1月1号至5号:07:53.934:W / dalvikvm(5712):主题ID = 1:螺纹退出与未捕获的异常(组= 0x40ffa2a0)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):未捕获的异常
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):java.lang.RuntimeException的:com.uia.example.my.LaunchSettings
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:95)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:82)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.internal.os.RuntimeInit.nativeFinishInit(本机方法)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.internal.os.RuntimeInit.main(RuntimeInit.java:237)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在dalvik.system.NativeStart.main(本机方法)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):抛出java.lang.ClassNotFoundException:产生的原因com.uia.example.my.LaunchSettings
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在java.lang.ClassLoader.loadClass(ClassLoader.java:501)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在java.lang.ClassLoader.loadClass(ClassLoader.java:461)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:83)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:71)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.uiautomator.testrunner.TestCaseCollector.addTestClasses(TestCaseCollector.java:52)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):在com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:92)
1月1号至5号:07:53.939:E / UiAutomatorTestRunner(5712):... 6个
1月1号至5号:07:53.944:I / AndroidRuntime(5712):VM退出与结果code -1。
 

解决方案

如果您在运行您的uiautomator测试得到ClassNotFindException:

我们中的一些我得到这个错误,因为它们的ROM会将文件夹/数据/达尔维克缓存只读模式。这发生在我身上有氰的S3。

在这种情况下类型,在bash:

  ADB壳
苏
搭配chmod 777 /数据/达尔维克缓存
出口
 

重新运行测试,并应工作。因为Dalvik缓存被锁定的应用程序,uiautomator不能叫Dalvik的解压您的测试和Dalvik的罐子会找不到它的类。

When I run my android UIAutomator code, it shows following error.

INSTRUMENTATION_RESULT: shortMsg=java.lang.RuntimeException INSTRUMENTATION_RESULT: longMsg=com.android.ui.testing INSTRUMENTATION_CODE: 0

I just ran the sample code given in developer.android.com How to solve this error?

Log attached below:

01-05 01:07:53.559: D/AndroidRuntime(5712): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-05 01:07:53.559: D/AndroidRuntime(5712): CheckJNI is ON
01-05 01:07:53.559: E/AndroidRuntime(5712): cannot open customer xml file
01-05 01:07:53.559: E/AndroidRuntime(5712): /system/csc/customer.xml can't open file
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: start
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: already setted!!
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: end
01-05 01:07:53.589: D/dalvikvm(5712): Trying to load lib libjavacore.so 0x0
01-05 01:07:53.599: D/dalvikvm(5712): Added shared lib libjavacore.so 0x0
01-05 01:07:53.609: D/dalvikvm(5712): Trying to load lib libnativehelper.so 0x0
01-05 01:07:53.609: D/dalvikvm(5712): Added shared lib libnativehelper.so 0x0
01-05 01:07:53.664: I/dalvikvm(5712): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
01-05 01:07:53.874: D/dalvikvm(5712): Note: class Landroid/app/ActivityManagerNative; has 152 unimplemented (abstract) methods
01-05 01:07:53.924: D/AndroidRuntime(5712): Calling main entry com.android.commands.uiautomator.Launcher
01-05 01:07:53.934: D/AndroidRuntime(5712): Shutting down VM
01-05 01:07:53.934: W/dalvikvm(5712): threadid=1: thread exiting with uncaught exception (group=0x40ffa2a0)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): uncaught exception
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): java.lang.RuntimeException: com.uia.example.my.LaunchSettings
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:95)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:82)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:237)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at dalvik.system.NativeStart.main(Native Method)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): Caused by: java.lang.ClassNotFoundException: com.uia.example.my.LaunchSettings
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:83)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:71)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.TestCaseCollector.addTestClasses(TestCaseCollector.java:52)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:92)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  ... 6 more
01-05 01:07:53.944: I/AndroidRuntime(5712): VM exiting with result code -1.

解决方案

If you get a ClassNotFindException while running your uiautomator tests :

Some of us my get this error because their ROM puts the folder /data/dalvik-cache in read-only mode. That happened to me with Cyanogen for a S3.

In that case type, in bash :

adb shell 
su
chmod 777 /data/dalvik-cache
exit

rerun your tests and that should work. As dalvik-cache is locked for apps, uiautomator can't ask dalvik to unzip the jar of your tests and dalvik won't find the its classes.