macOS系统在终端执行Java项目时报如下错:
具体为:
1 org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. 2 Please check the server log for more details. 3 Original error: An unknown server-side error occurred while processing the command. 4 Original error: Cannot verify the signature of '/var/folders/sw/b411gncn4cq2f16rvkst35kc0000gn/T/2021125-26019-1gzi67z.7852/ 5 appium-uiautomator2-server-v4.19.0.apk'. 6 Original error: Error: A JNI error has occurred, please check your installation and try again 7 Exception in thread "main" java.lang.UnsupportedClassVersionError: 8 com/android/apksigner/ApkSignerTool has been compiled by a more recent version of the Java Runtime (class file version 53.0), 9 this version of the Java Runtime only recognizes class file versions up to 52.0 10 at java.lang.ClassLoader.defineClass1(Native Method) 11 at java.lang.ClassLoader.defineClass(ClassLoader.java:763) 12 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) 13 at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) 14 at java.net.URLClassLoader.access$100(URLClassLoader.java:74) 15 at java.net.URLClassLoader$1.run(URLClassLoader.java:369) 16 at java.net.URLClassLoader$1.run(URLClassLoader.java:363) 17 at java.security.AccessController.doPrivileged(Native Method) 18 at java.net.URLClassLoader.findClass(URLClassLoader.java:362) 19 at java.lang.ClassLoader.loadClass(ClassLoader.java:424) 20 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) 21 at java.lang.ClassLoader.loadClass(ClassLoader.java:357) 22 at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
核心的报错信息为:
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/apksigner/ApkSignerTool has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
…… 也是各种百度、各种查找原因,最后查看此文得到解决思路:【jar】Java Runtime recognizes class file versions up to 52.0
1、52.0和53.0 是什么意思?
—— 具体版本以及对应的java版本:
49 = Java 5 50 = Java 6 51 = Java 7 52 = Java 8 53 = Java 9 54 = Java 10 55 = Java 11 56 = Java 12 57 = Java 13 58 = Java 14
因此,上述报错的意思是:使用了Java版本9(53.0)编译了代码,而当前的版本是Java8(52.0)
所以,需要降版本,那么,怎么降呢?……
2、继续往上看第4行的报错:
Original error: Cannot verify the signature of '/var/folders/sw/b411gncn4cq2f16rvkst35kc0000gn/T/2021125-26019-1gzi67z.7852/appium-uiautomator2-server-v4.19.0.apk'.
—— 即android 的com/android/apksigner/ApkSignerTool进行 appium-uiautomator2-server-v4.16.0.apk 包signer处理时提示版本问题
根据参考文章的提示,
“进入文件/opt/androidsdk/android-sdk-linux/build-tools/, 依赖的是 30.0.0-preview 此时安装的android-sdk的版本是30,通过FQ重新下载了版本29”
我也前往Android SDK目录查看文件及其路径,发现我的也是 30.0.0-preview !所以需要更换低一点的 build-tools !!! 因此,重装一个低版本的Android SDK。
3、 重装了一个低版本的Android SDK(android-sdk-r23-macosx,原本是r24)之后,又报新的错:
1 org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. 2 Original error: An unknown server-side error occurred while processing the command. 3 Original error: Cannot verify the signature of '/var/folders/sw/b411gncn4cq2f16rvkst35kc0000gn/T/2021126-94555-107z0f9.k27k/
appium-uiautomator2-server-v4.19.0.apk'.
Original error: Could not find 'apksigner.jar' in
["/Library/android-sdk-r23-macosx/platform-tools/apksigner.jar",
"/Library/android-sdk-r23-macosx/emulator/apksigner.jar",
"/Library/android-sdk-r23-macosx/cmdline-tools/latest/bin/apksigner.jar",
"/Library/android-sdk-r23-macosx/tools/apksigner.jar",
"/Library/android-sdk-r23-macosx/tools/bin/apksigner.jar",
"/Library/android-sdk-r23-macosx/apksigner.jar",
"/Library/android-sdk-r23-macosx/build-tools/23.0.1/apksigner.jar",
"/Library/android-sdk-r23-macosx/build-tools/23.0.1/lib/apksigner.jar"].
Do you have Android Build Tools installed at '/Library/android-sdk-r23-macosx'? 4 Build info: version: 'unknown', revision: 'unknown', time: 'unknown' 5 System info: host: 'crgtiOSCI.local', ip: 'fe80:0:0:0:1455:c69a:4de1:af22%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_201' 6 Driver info: driver.version: AndroidDriver 7 remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command.
Original error: Cannot verify the signature of '/var/folders/sw/b411gncn4cq2f16rvkst35kc0000gn/T/2021126-94555-107z0f9.k27k/
appium-uiautomator2-server-v4.19.0.apk'.
Original error: Could not find 'apksigner.jar' in
["/Library/android-sdk-r23-macosx/platform-tools/apksigner.jar",
"/Library/android-sdk-r23-macosx/emulator/apksigner.jar",
"/Library/android-sdk-r23-macosx/cmdline-tools/latest/bin/apksigner.jar",
"/Library/android-sdk-r23-macosx/tools/apksigner.jar",
"/Library/android-sdk-r23-macosx/tools/bin/apksigner.jar",
"/Library/android-sdk-r23-macosx/apksigner.jar",
"/Library/android-sdk-r23-macosx/build-tools/23.0.1/apksigner.jar",
"/Library/android-sdk-r23-macosx/build-tools/23.0.1/lib/apksigner.jar"].
Do you have Android Build Tools installed at '/Library/android-sdk-r23-macosx'? 8 at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/_appium-base-driver@7.4.1@appium-base-driver/lib/protocol/errors.js:804:9) 9 at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/_appium-base-driver@7.4.1@appium-base-driver/lib/protocol/protocol.js:380:37) 10 Build info: version: 'unknown', revision: 'unknown', time: 'unknown' 11 System info: host: 'crgtiOSCI.local', ip: 'fe80:0:0:0:1455:c69a:4de1:af22%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_201'
更新了之后,build-tools出现了一系列的的版本号?有些里面有'apksigner.jar',有些没有。
4、重新跑,又报新的错……
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session.
Please check the server log for more details.
Original error: An unknown server-side error occurred while processing the command.
Original error: Error executing adbExec. Original error: 'Command '/Library/android-sdk-r23-macosx/platform-tools/adb -P 5037 -s 66J0218C21003454 install -r /var/folders/sw/b411gncn4cq2f16rvkst35kc0000gn/T/2021126-86279-1u3qq29.yylv/appium-uiautomator2-server-v4.19.0.apk' timed out after 20000ms'. Try to increase the 20000ms adb execution timeout represented by 'uiautomator2ServerInstallTimeout' capability Build info: version: 'unknown', revision: 'unknown', time: 'unknown' System info: host: 'crgtiOSCI.local', ip: 'fe80:0:0:0:1455:c69a:4de1:af22%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_201' Driver info: driver.version: AndroidDriver remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command '/Library/android-sdk-r23-macosx/platform-tools/adb -P 5037 -s 66J0218C21003454 install -r /var/folders/sw/b411gncn4cq2f16rvkst35kc0000gn/T/2021126-86279-1u3qq29.yylv/appium-uiautomator2-server-v4.19.0.apk' timed out after 20000ms'. Try to increase the 20000ms adb execution timeout represented by 'uiautomator2ServerInstallTimeout' capability at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/_appium-base-driver@7.4.1@appium-base-driver/lib/protocol/errors.js:804:9)
——有查到一个原因说是 appium版本太高导致的,不知道是不是。试了再说。
5、更换 appium版本 (从1.20.2降到1.17.1)
使用命令:sudo cnpm install -g appium@1.17.1 --force (很快哦!)
如果不加 --force 命令的话,可能会失败,如下图中红框上面的ERR报错,提示需要手动去删除原来appium版本的安装目录文件夹,所以加 --force比较方便啦。
安装成功:
6、最后再次终端执行命令:java -jar target/XXXX-1.0-SNAPSHOT.jar ,可终于成功运行起来啦!!!
【Reference】
1、【jar】Java Runtime recognizes class file versions up to 52.0