如何在apk中捆绑UIAutomator

use*_*579 3 android apk android-uiautomator

我正在尝试创建一个应用程序,当单击按钮时启动UIAutomator.目前运行时问题是UiAutomator的NoclassDefFound - 我已经在构建路径中添加了uiautomator jar.我有什么指针可以解决这个问题?谢谢!

@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");
                }
        });
Run Code Online (Sandbox Code Playgroud)

top*_*uts 5

直接从Android应用程序调用UiAutomator方法是不可能的,但是你可以构建一个UiAutomator测试jar,将它推送到你的设备上,然后从你的应用程序运行jar(如果你有root).

请参阅创建UiAutomator测试用例以创建uiautomator测试,并在此处查看我的答案,了解如何从应用程序调用uiautomator.