Environment construction for running monkeyrunner script in eclipse (4)

The monkeyrunner script is written in Python syntax, but it is actually interpreted and executed through Jython. Jython is a java implementation of Python. It interprets Python code into bytecode on Java virtual machine and executes it. This practice allows you to inherit a Java type in Python and call any Java API.

This document is mainly about running monkeyrunner script in eclipse environment. The required environment and tools are as follows: win7 OS, JDK, eclipse, SDK, python, Jython, simulator or real machine device.

In the first two chapters, we configured the Android development environment in eclipse and built the monkeyrunner environment. The above tools are basically available. Jython is in SDK \ tools \ lib. Therefore, in this document, we only need to integrate monkeyrunner and python into eclipse, so that we can debug and run the monkeyrunner script in eclipse later.

1. Pydev plug-in installation

On the install page, click the Add button to enter the add repository page.

On the add repository page, enter the name and address of the plug-in you want to obtain. The address must be entered correctly. Since we want to obtain pydev, enter the download address with the name of pydev and the address of pydev here:

https://dl.bintray.com/fabioz/pydev/5.1.2/

Click OK to enter pydev loading page:

After pydev is loaded successfully, select pydev to download.

After that, follow the prompts on the page to the next step, and finally finish the download and installation.

2. Jython development environment configuration

In the window preferences pydev Python interpreter, create a new Python interpreter, select your python.exe path, and click OK.

Follow the prompts on the page. After loading, start configuring the Jython environment.

In the window preferences pydev Jython interpreter, create a new Jython. Select SDK \ tools \ jython-standard-2.5.3.jar and click OK.

If the loading result is as follows:

Then copy the entire lib file in Python to tools \ Lib in the directory of jython-standard-2.5.3.jar in the SDK, create a new Jython again, and add the jython-standard-2.5.3.jar path. Or select proceed anyway.

After loading, click Apply OK to complete Jython's environment configuration.

3. Monkeyrunner development environment configuration

Now that we have configured the Jython development environment, we can create a Jython project. However, we have not completed the monkeyrunner configuration, so the current Jython project can not easily develop monkeyrunner.

In fact, building the monkeyrunner development environment is to add the packages we need to Jython's pythonpath for us to reference directly.

In the window preference pydev Jython interpreter, click the "new jar / zips" button on the right and start selecting the jar package you need under \ tools \ lib under your SDK. Here are the jar packages we need this time: hierarchyviewer2.jar, hierarchyviewer2lib.jar, monkeyrunner.jar and chimpchat.jar. Add these jar packages in turn.

Finally, the successfully loaded page is as follows:

So far, the environment configuration of monkeyrunner has been completed.

4. Jython project creation

After the environment is built, we can build a new Jython project. Let's create a Jython project.

In file, create a new project and select pydev project.

Fill in the project name as required, select Jython as the project type, and click finish.

After the project is created, click to select the project, right-click to create a pydev module. After the project is created, you can write a python program.

Now, we copy the script written in monkeyrunner directly to eclipse and create a new pydev module, including package guide, device connection, APP installation and app startup:

In fact, to execute this code, you need monkeyrunner.bat provided by Android, so you can't run the program as usual. Therefore, next, you need to configure the operation of monkeyrunner script in eclipse.

5. Run monkeyrunner script in eclipse

Select run external tools external tools configurations from the menu bar,

Add relevant configuration information, as shown in the following figure:

Note: the above configuration is only for test02.py. If there is a new pydev package, change the configuration of working directory and arguments at the same time.

After the simulator starts, you can run the pydev module just created.

On the simulator, we can see the automatic installation and startup of the app. This indicates that the environment has been configured successfully. After that, you can edit the monkeyrunner script in eclipse and run it.

6. Running monkeyrunner script in eclipse, problems and Solutions

Run the moneyrunner script in eclipse and report an error: the software in your host has suspended an established connection

resolvent:

1. Kill the process adb.exe, 1) check the adb.exe process number XXX: tasklist | findstr adb.exe, 2) kill the process: taskkill / F / T / im XXX

2. Then restart eclipse,

3. Open adb.exe to connect the device 1) open CMD 2) connect the simulator: ADB connect IP

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>