3

I am trying to create an application which launchs UIAutomator when a button is clicked. Currently the runtime issue is NoclassDefFound for UiAutomator - I already added uiautomator jar within the build path. Any pointer how I can resolve the issue? Thanks!

@Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);     

        Button clickMe = (Button) findViewById(R.id.button1);
        clickMe.setOnClickListener(new OnClickListener () {
                public void onClick(View arg0) {
                    Log.i("Hello", "Prior to clicking");

                    UiObject clickBtn = new UiObject(new UiSelector().description("Apps"));
                    try {
                        clickBtn.click();
                    } catch (UiObjectNotFoundException e) {
                        Log.i("Hello", "Error is catched");
                    }

                    Log.i("Hello", "Button is clicked");
                }
        });
user2456579
  • 31
  • 1
  • 4

1 Answers1

7

It's not possible to call UiAutomator methods that directly from an android Application, however you can build a UiAutomator Test jar, push it onto your device, and run the jar from your application (if you have root).

See Creating UiAutomator test cases to create a uiautomator test and see my answer here for how to call uiautomator from an application.

Community
  • 1
  • 1
tophernuts
  • 389
  • 9
  • 14