gpt4 book ai didi

gradle - java.lang.ClassNotFoundException : Didn't find class “xxx.xxx.MainActivityTest.java” on path: DexPathList

转载 作者:行者123 更新时间:2023-12-03 03:26:45 26 4
gpt4 key购买 nike

我正在尝试使用 CLI 在模拟器中运行仪器测试(Espresso),以使用快速 channel /屏幕抓取生成我们的应用程序的屏幕截图。该应用程序基于 IONIC Cordova。

在 Android Studio 中执行我的 Espresso 测试时,它会记录:

Testing started at 16:34 ...

07/30 16:34:29: Launching MainActivityTest
$ adb push /Users/administrator/Jenkins/workspace/generatescreenshots/app/platforms/android/app/build/outputs/apk/debug/app-debug.apk /data/local/tmp/de.konzeptix.test.app
$ adb shell pm install -t -r "/data/local/tmp/de.konzeptix.test.app"
Success


$ adb push /Users/administrator/Jenkins/workspace/generatescreenshots/app/platforms/android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk /data/local/tmp/de.konzeptix.test.app.test
$ adb shell pm install -t -r "/data/local/tmp/de.konzeptix.test.app.test"
Success


Running tests

$ adb shell am instrument -w -r -e debug false -e class 'de.konzeptix.test.app.test.MainActivityTest' de.konzeptix.test.app.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Tests ran to completion.

如果我以这种方式尝试,我的测试类就会找到,并按预期执行。

我必须在命令行上工作,而不是在 Android Studio 中工作,因为整个过程是通过我们的 CI 服务器 (Jenkins) 启动和运行的。

因此,没有“即时运行”来禁用,也没有“清理和重建”来解决这个问题,正如其他几个问题中提出的那样......

如果我尝试在 cli 上调用我的测试,则找不到我的测试类。
这是该过程的输出:
00:03:06.842 +----------------------------+---------------------------------------------------------------------------------------+
00:03:06.843 | Detected Values from './fastlane/Screengrabfile' |
00:03:06.844 +----------------------------+---------------------------------------------------------------------------------------+
00:03:06.845 | app_package_name | de.konzeptix.test.app |
00:03:06.845 | tests_package_name | de.konzeptix.test.app.test |
00:03:06.846 | use_tests_in_classes | ["de.konzeptix.test.app.test.MainActivityTest.java"] |
00:03:06.847 | app_apk_path | ./platforms/android/app/build/outputs/apk/debug/app-debug.apk |
00:03:06.847 | tests_apk_path | ./platforms/android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk |
00:03:06.848 | locales | ["de-DE"] |
00:03:06.849 | launch_arguments | ["'shot0 topsBtn'", " 'shot1 articlesBtn'", " 'shot2 eventsBtn'"] |
00:03:06.850 | device_type | phone |
00:03:06.850 | clear_previous_screenshots | true |
00:03:06.851 +----------------------------+---------------------------------------------------------------------------------------+
00:03:06.852
00:03:06.852
00:03:06.853 +-----------------------------+---------------------------------------------------------------------------------------+
00:03:06.854 | Summary for screengrab 2.99.1 |
00:03:06.869 +-----------------------------+---------------------------------------------------------------------------------------+
00:03:06.870 | android_home | /Users/administrator/Library/Android/sdk |
00:03:06.870 | locales | ["de-DE"] |
00:03:06.870 | clear_previous_screenshots | true |
00:03:06.870 | output_directory | fastlane/metadata/android |
00:03:06.871 | skip_open_summary | false |
00:03:06.871 | app_package_name | de.konzeptix.test.app |
00:03:06.871 | tests_package_name | de.konzeptix.test.app.test |
00:03:06.872 | use_tests_in_classes | ["de.konzeptix.test.app.test.MainActivityTest.java"] |
00:03:06.872 | launch_arguments | ["'shot0 topsBtn'", " 'shot1 articlesBtn'", " 'shot2 eventsBtn'"] |
00:03:06.872 | test_instrumentation_runner | android.support.test.runner.AndroidJUnitRunner |
00:03:06.872 | ending_locale | en-US |
00:03:06.873 | app_apk_path | ./platforms/android/app/build/outputs/apk/debug/app-debug.apk |
00:03:06.873 | tests_apk_path | ./platforms/android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk |
00:03:06.873 | device_type | phone |
00:03:06.874 | exit_on_test_failure | true |
00:03:06.874 | reinstall_app | false |
00:03:06.874 +-----------------------------+---------------------------------------------------------------------------------------+
00:03:06.874
00:03:06.949 Clearing phoneScreenshots within fastlane/metadata/android
00:03:06.951 $ /Users/administrator/Library/Android/sdk/platform-tools/adb devices -l
00:03:06.960 ▸ List of devices attached
00:03:06.966 ▸ emulator-5554 device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:1
00:03:06.974 $ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell echo \$EXTERNAL_STORAGE
00:03:06.981 ▸ /sdcard
00:03:06.988 Cleaning screenshots on device
00:03:07.000 ls: /sdcard/de.konzeptix.test.app/screengrab: No such file or directory
00:03:07.001 Exit status: 1
00:03:07.021 ls: /data/data/de.konzeptix.test.app/app_screengrab: Permission denied
00:03:07.022 Exit status: 1
00:03:07.025 Validating app APK
00:03:07.026 $ /Users/administrator/Library/Android/sdk/build-tools/28.0.1/aapt dump permissions ./platforms/android/app/build/outputs/apk/debug/app-debug.apk
00:03:07.032 ▸ package: de.konzeptix.test.app
00:03:07.036 ▸ uses-permission: name='android.permission.DISABLE_KEYGUARD'
00:03:07.040 ▸ uses-permission: name='android.permission.WAKE_LOCK'
00:03:07.045 ▸ uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
00:03:07.049 ▸ uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
00:03:07.052 ▸ uses-permission: name='android.permission.CHANGE_CONFIGURATION'
00:03:07.054 ▸ uses-permission: name='android.permission.INTERNET'
00:03:07.057 ▸ uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
00:03:07.059 ▸ uses-permission: name='android.permission.READ_PHONE_STATE'
00:03:07.062 ▸ uses-permission: name='com.sec.android.provider.badge.permission.READ'
00:03:07.065 ▸ uses-permission: name='com.sec.android.provider.badge.permission.WRITE'
00:03:07.067 ▸ uses-permission: name='com.htc.launcher.permission.READ_SETTINGS'
00:03:07.070 ▸ uses-permission: name='com.htc.launcher.permission.UPDATE_SHORTCUT'
00:03:07.072 ▸ uses-permission: name='com.sonyericsson.home.permission.BROADCAST_BADGE'
00:03:07.075 ▸ uses-permission: name='com.anddoes.launcher.permission.UPDATE_COUNT'
00:03:07.077 ▸ uses-permission: name='com.majeur.launcher.permission.UPDATE_BADGE'
00:03:07.080 ▸ uses-permission: name='com.google.android.providers.gsf.permission.READ_GSERVICES'
00:03:07.081 ▸ uses-permission: name='com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE'
00:03:07.083 ▸ uses-permission: name='com.google.android.c2dm.permission.RECEIVE'
00:03:07.084 ▸ permission: de.konzeptix.test.app.permission.C2D_MESSAGE
00:03:07.086 ▸ uses-permission: name='de.konzeptix.test.app.permission.C2D_MESSAGE'
00:03:07.087 Installing app APK
00:03:07.088 $ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 install -t -r ./platforms/android/app/build/outputs/apk/debug/app-debug.apk
00:03:07.447 ▸ Success
00:03:07.449 Installing tests APK
00:03:07.450 $ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 install -t -r ./platforms/android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
00:03:08.115 ▸ Success
00:03:08.122 Granting the permission necessary to change locales on the device
00:03:08.124 $ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm grant de.konzeptix.test.app android.permission.CHANGE_CONFIGURATION
00:03:08.302 $ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell getprop ro.build.version.sdk
00:03:08.328 ▸ 28
00:03:08.349 Granting the permissions necessary to access device external storage
00:03:08.350 $ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm grant de.konzeptix.test.app android.permission.WRITE_EXTERNAL_STORAGE
00:03:08.413 $ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell pm grant de.konzeptix.test.app android.permission.READ_EXTERNAL_STORAGE
00:03:08.462 Running tests for locale: de-DE
00:03:08.464 $ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell am instrument --no-window-animation -w \
00:03:08.467 -e testLocale de_DE \
00:03:08.468 -e endingLocale en_US \
00:03:08.468 -e class de.konzeptix.test.app.test.MainActivityTest.java \
00:03:08.468 -e 'shot0 topsBtn' -e 'shot1 articlesBtn' -e 'shot2 eventsBtn' \
00:03:08.469 de.konzeptix.test.app.test/android.support.test.runner.AndroidJUnitRunner
00:03:09.116 ▸ de.konzeptix.test.app.test.MainActivityTest.java:
00:03:09.123 ▸ Error in de.konzeptix.test.app.test.MainActivityTest.java:
00:03:09.130 ▸ java.lang.ClassNotFoundException: de.konzeptix.test.app.test.MainActivityTest.java
00:03:09.137 ▸ at java.lang.Class.classForName(Native Method)
00:03:09.143 ▸ at java.lang.Class.forName(Class.java:453)
00:03:09.150 ▸ at android.support.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:72)
00:03:09.157 ▸ at android.support.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
00:03:09.164 ▸ at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:789)
00:03:09.172 ▸ at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:539)
00:03:09.179 ▸ at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:382)
00:03:09.186 ▸ at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
00:03:09.193 ▸ Caused by: java.lang.ClassNotFoundException: Didn't find class "de.konzeptix.test.app.test.MainActivityTest.java" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/de.konzeptix.test.app.test-uaWS_ap-9oK2KRdJOAlBJg==/base.apk", zip file "/data/app/de.konzeptix.test.app-BROFUx3GSnQkL4K7pknnyw==/base.apk"],nativeLibraryDirectories=[/data/app/de.konzeptix.test.app.test-uaWS_ap-9oK2KRdJOAlBJg==/lib/x86, /data/app/de.konzeptix.test.app-BROFUx3GSnQkL4K7pknnyw==/lib/x86, /data/app/de.konzeptix.test.app.test-uaWS_ap-9oK2KRdJOAlBJg==/base.apk!/lib/x86, /data/app/de.konzeptix.test.app-BROFUx3GSnQkL4K7pknnyw==/base.apk!/lib/x86, /system/lib]]
00:03:09.207 ▸ at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
00:03:09.211 ▸ at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
00:03:09.214 ▸ at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
00:03:09.216 ▸ ... 8 more
00:03:09.274 ▸ Time: 0.014
00:03:09.281 ▸ There was 1 failure:
00:03:09.287 ▸ 1) de.konzeptix.test.app.test.MainActivityTest.java
00:03:09.294 ▸ java.lang.ClassNotFoundException: de.konzeptix.test.app.test.MainActivityTest.java
00:03:09.301 ▸ at java.lang.Class.classForName(Native Method)
00:03:09.309 ▸ at java.lang.Class.forName(Class.java:453)
00:03:09.315 ▸ at android.support.test.internal.runner.TestLoader.doCreateRunner(TestLoader.java:72)
00:03:09.322 ▸ at android.support.test.internal.runner.TestLoader.getRunnersFor(TestLoader.java:104)
00:03:09.330 ▸ at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:789)
00:03:09.334 ▸ at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:539)
00:03:09.338 ▸ at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:382)
00:03:09.342 ▸ at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
00:03:09.346 ▸ Caused by: java.lang.ClassNotFoundException: Didn't find class "de.konzeptix.test.app.test.MainActivityTest.java" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/de.konzeptix.test.app.test-uaWS_ap-9oK2KRdJOAlBJg==/base.apk", zip file "/data/app/de.konzeptix.test.app-BROFUx3GSnQkL4K7pknnyw==/base.apk"],nativeLibraryDirectories=[/data/app/de.konzeptix.test.app.test-uaWS_ap-9oK2KRdJOAlBJg==/lib/x86, /data/app/de.konzeptix.test.app-BROFUx3GSnQkL4K7pknnyw==/lib/x86, /data/app/de.konzeptix.test.app.test-uaWS_ap-9oK2KRdJOAlBJg==/base.apk!/lib/x86, /data/app/de.konzeptix.test.app-BROFUx3GSnQkL4K7pknnyw==/base.apk!/lib/x86, /system/lib]]
00:03:09.354 ▸ at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
00:03:09.358 ▸ at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
00:03:09.361 ▸ at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
00:03:09.361 ▸ ... 8 more
00:03:09.363 ▸ FAILURES!!!
00:03:09.364 ▸ Tests run: 1, Failures: 1

我想Android日志中显示的内容会有所不同( adb push adb shell pm install )

有人可以向我解释一下,那里到底做了什么?

最佳答案

由于 faSTLane screengrab 将这两个应用程序安装到设备上,我无法清楚地看到安装和运行仪器测试的 Android Studio 过程有任何重大差异,我尝试使用 faSTLane screengrab use_tests_in_packages 的另一个选项而不是 use_tests_in_class,它转换为cli调用

$ /Users/administrator/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell am instrument --no-window-animation -w \
-e testLocale de_DE \
-e endingLocale en_US \
-e package de.konzeptix.test.app.test \
-e shot0 topsBtn -e shot1 articlesBtn -e shot2 eventsBtn -e shot3 galleriesBtn -e shot4 productsBtn -e shot5 faqBtn -e shot6 companyBtn -e shot7 contactsBtn \
de.konzeptix.test.app.test/android.support.test.runner.AndroidJUnitRunner

使用 -e 包而不是 -e 类。

出于某种奇怪的原因,这行得通。

关于gradle - java.lang.ClassNotFoundException : Didn't find class “xxx.xxx.MainActivityTest.java” on path: DexPathList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51596743/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com