Sunday, July 30, 2023

UiAutomatorViewer isn't working with higher java versions.

 

I was getting this error when tried with my default Java 11;

./uiautomatorviewer -Djava.ext.dirs=/Users/yumani/Library/Android/sdk/tools/lib/x86_64:/Users/yumani/Library/Android/sdk/tools/lib is not supported. Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit

The problem seems to be caused by the usage of the -Djava.ext.dirs option, which is not supported in newer versions of Java. 

Then, I used use -classpath option to set the classpath and got this error

yumani@Yumanis-MacBook-Pro bin % ./uiautomatorviewer -classpath /Users/yumani/Library/Android/sdk/tools/lib/x86_64:/Users/yumani/Library/Android/sdk/tools/lib -Djava.ext.dirs=/Users/yumani/Library/Android/sdk/tools/lib/x86_64:/Users/yumani/Library/Android/sdk/tools/lib is not supported. Use -classpath instead. Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

I am on Java11,  tried different options in the net such as upgratig sdk-tools, downloading swt.jar.

Non worked for me in macOS Ventura.

The web advise that worked was downgrading to jdk 1.8.

So I installed jdk 1.8, updated in .bash_profile, commented out my older version (because I want to switch back to it when I am not using the UiAutomatorViewer.

source ~/.bash_profile 

yumani@Yumanis-MacBook-Pro sdk % tools/bin/uiautomatorviewer -classpath /Users/yumani/Library/Android/sdk/tools/lib/x86_64/swt.jar






How to identify the main actvity from the AndroidManifest.xml

 When you setup applium capacbilities giving the app package and app activity, you have to give the main activity as the app activity.

Here is how you identify the main activity from AndroidManifest.xml when it has multiple activities.

  • Locate the AndroidManifest.xml:

The AndroidManifest.xml file is located in the app folder of your Android project. The typical path is app/src/main/AndroidManifest.xml.

  • Open the AndroidManifest.xml:

Use a text editor or an XML editor to open the AndroidManifest.xml file.

  • Search for <activity> tags:

Inside the AndroidManifest.xml, look for <activity> tags. Each <activity> tag represents an activity (screen) of the Android application.

  • Find the Main Activity:

The AppActivity is usually the main activity of the app. It is the entry point of the application, and its intent filter is often set to respond to the android.intent.action.MAIN and android.intent.category.LAUNCHER actions.

  • Look for Intent Filters:

Inside the <activity> tags, check for <intent-filter> tags. The AppActivity should have an <intent-filter> that includes the android.intent.action.MAIN and android.intent.category.LAUNCHER actions.

  • Extract the AppActivity Name:

Extract the value of the android:name attribute from the <activity> tag that has the <intent-filter> with the android.intent.action.MAIN and android.intent.category.LAUNCHER actions. The value of android:name attribute will be the AppActivity.

<activity

    android:name=".ui.MainActivity"  <!-- This is the AppActivity -->

    android:label="@string/app_name">

    <intent-filter>

        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />

    </intent-filter>

</activity>


In this example, the AppActivity is .ui.MainActivity.


Featured

Selenium - Page Object Model and Action Methods

  How we change this code to PageObjectModel and action classes. 1 2 3 driver . findElement ( By . id ( "userEmail" )). sendKeys (...

Popular Posts