python+appium自动化脚本启动时报错的问题

运行报错

在自动连接封装完成后,尝试启动appium的时候报了一堆的错,如下:

class Start_appium():
    def __init__(self,platformName="Android"):
        self.server = Server()
        apk_name = common.Pubilc_class().read_file_apk()[0]
        self.caps = {
            "platformName": platformName,
            "udid": f"{self.server.start_devices_id()}",
            "platformVersion": f"{self.server.start_devices_Version()}",
            "appPackage": self.server.start_apk_package(apk_name),
            "appActivity": self.server.start_apk_activity(),
            "noReset": True
        }
    def server_start(self):
        print(self.caps)
        self.driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub',self.caps)


if __name__ == '__main__':
    s = Start_appium()
    s.server_start()
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Cannot verify the signature of 'E:\node-v12.16.3-win-x64\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.27.0.apk'. Original error: Error: A JNI error has occurred, please check your installation and try again
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
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)

Stacktrace:
UnknownError: An unknown server-side error occurred while processing the command. Original error: Cannot verify the signature of 'E:\node-v12.16.3-win-x64\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v4.27.0.apk'. Original error: Error: A JNI error has occurred, please check your installation and try again
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
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)

    at getResponseForW3CError (E:\node-v12.16.3-win-x64\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
    at asyncHandler (E:\node-v12.16.3-win-x64\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:380:37)

进程已结束,退出代码1

错误猜测

在谷歌搜索报错的时候回答皆都只提到了签名错误,翻译也是说的签名错误,给出的解决办法是重新安装appium

尝试解决

尝试了重新安装appium,无界面版与桌面版都重装了最新的,没有解决问题,尝试了重新安装新版的sdk,因为使用的是14版的ADT,重装sdk后未解决问题

定位问题

这个时候我重新看了下报错,报错的重点不是签名未验证,而是

线程“main”中的异常 java.lang.UnsupportedClassVersionError: com/android/apksigner/ApkSignerTool 已由 Java 运行时的更新版本(类文件版本 53.0)编译,此版本的 Java 运行时仅识别类文件版本至 52.0
在 

而我的adb版本确实是29.0.6的版本

 去到指定目录中查看发现build-tools中存在高版本30.0.0-preview怀疑是我的环境变量没有指定到具体的版本,而是指定到路径造成的冲突


解决方法

注意:删除或配置环境变量后请一定重启appium!

环境变量具体到版本:%ANDROID_HOME%\build-tools\29.0.3

或者直接删除高版本:

删除过高版本的文件夹30.0.0-previewpython+appium自动化脚本启动时报错的问题_第1张图片

 再次运行

我选择了直接删除掉30.0.0的文件夹,目前也用不上

再次运行后终于正常了,退出代码0

python+appium自动化脚本启动时报错的问题_第2张图片

 

你可能感兴趣的:(python,python,自动化,java)