Appium 运行中签名报错

报错信息:


[ADB] Using 'zipalign.exe' from 'D:\xixiworkspace\android-sdk_r24.4.1-windows1\android-sdk-windows\build-tools\30.0.0-preview\zipalign.exe'
[debug] [ADB] C:\Users\AndyJee\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk' is already zip-aligned. Doing nothing
[debug] [ADB] Signing 'C:\Users\AndyJee\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk' with default cert
[debug] [ADB] Starting apksigner: D:\\javaenv\\bin\\java.exe -Xmx1024M -Xss1m -jar D:\\xixiworkspace\\android-sdk_r24.4.1-windows1\\android-sdk-windows\\build-tools\\30.0.0-preview\\lib\\apksigner.jar sign --key C:\\Users\\AndyJee\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-adb\\keys\\testkey.pk8 --cert C:\\Users\\AndyJee\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-adb\\keys\\testkey.x509.pem C:\\Users\\AndyJee\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-uiautomator2-server\\apks\\appium-uiautomator2-server-debug-androidTest.apk
[ADB] Cannot use apksigner tool for signing. Defaulting to sign.jar. Original error: 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
[ADB]   at java.lang.ClassLoader.defineClass1(Native Method)
[ADB]   at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
[ADB]   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[ADB]   at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
[ADB]   at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
[ADB]   at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
[ADB]   at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
[ADB]   at java.security.AccessController.doPrivileged(Native Method)
[ADB]   at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
[ADB]   at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
[ADB]   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
[ADB]   at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
[ADB]   at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
[ADB] Error: A JNI error has occurred, please check your installation and try again
[ADB] Exception in thread "main"
[debug] [ADB] Starting sign.jar: D:\\javaenv\\bin\\java.exe -jar C:\\Users\\AndyJee\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-adb\\jars\\sign.jar C:\\Users\\AndyJee\\AppData\\Roaming\\npm\\node_modules\\appium\\node_modules\\appium-uiautomator2-server\\apks\\appium-uiautomator2-server-debug-androidTest.apk --override
[UiAutomator2] Server packages are going to be (re)installed
[UiAutomator2] Full packages reinstall is going to be performed
[debug] [ADB] Uninstalling io.appium.uiautomator2.server

报错信息中分析,...sdk\\build-tools\\30.0.0-preview\\lib\\apksigner.jar 这个文件依赖较高版本的java环境,查看了一下build-tools这个目录下只有一个版本 30.0,下载低版本的build-tools文件,改成版本21.1.2这个版本即可。

build-tools下载地址: https://www.androiddevtools.cn/

image