简体   繁体   English

Appium 脚本为 android 应用程序抛出“线程“主”中的异常 java.lang.NoClassDefFoundError: org/objectweb/asm/Type”

[英]Appium script throws “Exception in thread ”main“ java.lang.NoClassDefFoundError: org/objectweb/asm/Type” for android application

Please find my code below and help me to get out of the exception请在下面找到我的代码并帮助我摆脱异常

I am using Appium version 1.17.1,cglib3.3.0 jar,java-client-7.3.0 jar,Selenium-java-3.141.59 with project as java project我正在使用 Appium 版本 1.17.1,cglib3.3.0 jar,java-client-7.3.0 jar,Selenium-java-3.141.59 项目为 Z93F7425A07423D2C2C2C89644F1

Please find the below code请找到以下代码

HybridBase.java HybridBase.java

  public class HybridBase {

        public static AndroidDriver<AndroidElement> capabilities(String device) throws MalformedURLException
        {
            AndroidDriver<AndroidElement> driver;
            File f = new File("src");
            File fs = new File(f,"ApiDemos-debug.apk");
            DesiredCapabilities cap=new DesiredCapabilities();

            if(device.equals("real")){
                cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android"); 
            }
            else if(device.equals("emulator")){
                cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android");
            }
            cap.setCapability(MobileCapabilityType.UDID, "3200f0fdb4e8753b");

        //  cap.setCapability(MobileCapabilityType.UDID, "3200f0fdb4e8753b");
            cap.setCapability(MobileCapabilityType.FULL_RESET, false);
        cap.setCapability(MobileCapabilityType.NO_RESET, true);

            cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
            driver=new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
            return driver;


        }

    }

Basic.java基本款.java

public class Basic extends HybridBase {

    public static void main(String[] args) throws MalformedURLException {
        // TODO Auto-generated method stub

        AndroidDriver<AndroidElement> driver = capabilities("real");

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


        HomePage h = new HomePage(driver);

        // driver.findElementByXPath("//android.widget.TextView[@content-desc='Preference']").click();
        //driver.findElementByXPath("//android.widget.TextView[@text='Preference']").click();

        h.preferences.click();

        Preferences p =new Preferences(driver);

        //driver.findElementByXPath("//android.widget.TextView[@text='3. Preference dependencies']").click();

        p.dependencies.click();
        driver.findElementById("android:id/checkbox").click();
        driver.findElementByXPath("(//android.widget.RelativeLayout)[2]").click();
        driver.findElementByClassName("android.widget.EditText").sendKeys("Karthi");
        driver.findElementsByClassName("android.widget.Button").get(1).click();
    }

}

HomePage.java首页.java

public class HomePage {

    public HomePage(AppiumDriver driver) {
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);
        // PageFactory.initElements(driver, this);
    }

    @AndroidFindBy(xpath = "//android.widget.TextView[@text='Preference']")
    public WebElement preferences;

}

Preferences.java首选项.java

public class Preferences {

    public Preferences(AppiumDriver driver) {
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);
        // PageFactory.initElements(driver, this);
    }

    @AndroidFindBy(xpath = "//android.widget.TextView[@text='3. Preference dependencies']")
    public WebElement dependencies;

}

Result: Application gets opened but not performing any actions and throws the below Exception结果:应用程序打开但未执行任何操作并引发以下异常

Getting the following Exception获得以下异常

Jun 12, 2020 8:35:55 AM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/Type
    at net.sf.cglib.core.TypeUtils.parseType(TypeUtils.java:184)
    at net.sf.cglib.core.KeyFactory.<clinit>(KeyFactory.java:72)
    at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:72)
    at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52)
    at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33)
    at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:222)
    at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$0(AppiumFieldDecorator.java:220)
    at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:105)
    at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62)
    at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:160)
    at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
    at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
    at pageobjects.HomePage.<init>(HomePage.java:15)
    at Basic.main(Basic.java:19)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 14 more

Please help me to get out of the above exception.请帮助我摆脱上述异常。

Thanks in Advance提前致谢

This issue occurs due to the incompatible jar. try to use the latest jar from the below  link,

https://github.com/cglib/cglib/releases 
http://download.forge.ow2.org/asm/
http://download.forge.ow2.org/

References
https://github.com/appium/appium/issues/9699

I got the solution for the above problem by adding asm-6.1 jar and added cglib-3.2.6 jar instead of cglib-3.3.0 jar我通过添加 asm-6.1 jar 并添加 cglib-3.2.6 jar 而不是 cglib-3.3.0 Z68995FCBF432492D40484D04A9D2

Link for cglib jar - https://github.com/cglib/cglib/releases Link for asm-6.1 jar - http://download.forge.ow2.org/asm/ Link for cglib jar - https://github.com/cglib/cglib/releases Link for asm-6.1 jar - http://download.forge.ow2.org/asm/

Please feel free to contact if any clarifications needed...如果需要任何澄清,请随时联系...

This might be due to unavailability of asm jar .这可能是由于asm jar不可用。 It can be downloaded from the below link,可以从以下链接下载,

http://download.forge.ow2.org/asm/ http://download.forge.ow2.org/asm/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 一旦我运行我的Appium脚本,线程“main”java.lang.NoClassDefFoundError中的异常 - Exception in thread “main” java.lang.NoClassDefFoundError once I run my Appium script Java在主线程java.lang.NoClassDefFoundError中引发异常 - Java Throws exception in thread main java.lang.NoClassDefFoundError “线程”main“中的异常 java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing” - “Exception in thread ”main“ java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing” 线程“main”中的异常java.lang.NoClassDefFoundError:org / reactivestreams / Publisher? - Exception in thread “main” java.lang.NoClassDefFoundError: org/reactivestreams/Publisher? 线程“main”中的异常 java.lang.NoClassDefFoundError: org/jsoup/Jsoup - Exception in thread "main" java.lang.NoClassDefFoundError: org/jsoup/Jsoup 线程“main”中的异常 java.lang.NoClassDefFoundError: org/hamcrest/Matchers - Exception in thread "main" java.lang.NoClassDefFoundError: org/hamcrest/Matchers 线程“ main”中的异常java.lang.NoClassDefFoundError:org / mockito / Mockito - Exception in thread “main” java.lang.NoClassDefFoundError: org/mockito/Mockito 线程“main”中的异常java.lang.NoClassDefFoundError:org / json / JSONObject - Exception in thread “main” java.lang.NoClassDefFoundError: org/json/JSONObject 线程“ main”中的异常java.lang.NoClassDefFoundError:org / javatuples / Unit - Exception in thread “main” java.lang.NoClassDefFoundError: org/javatuples/Unit Spark和Cassandra Java应用程序:线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / spark / sql / Dataset - Spark and Cassandra Java application: Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/spark/sql/Dataset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM