Environment for running Monkeyrunner scripts in Eclipse (4) _android

Source: Internet
Author: User
Tags in python

The Monkeyrunner script is written using the Python syntax, but it actually interprets execution through Jython. Jython is a Python Java implementation that interprets Python code as bytecode on a Java virtual machine and executes it, allowing you to inherit a Java type in Python and invoke any Java API.

This document is primarily implemented to run Monkeyrunner scripts in the eclipse environment. The required environment and tools are as follows: Win7 OS, JDK, Eclipse, SDK, Python, Jython, emulator, or True machine device.

In the first two chapters, we made the configuration of the Android development environment in Eclipse, monkeyrunner the environment. The above tools are basically already available, among them, Jython in Sdk\tools\lib. So in this document, we just 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 plugin you want to get, where the address must be typed correctly. Because we want to get pydev, so here enter the name of Pydev, address for pydev download address:

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

After clicking the OK button, enter the Pydev loading page:

After the Pydev load succeeds, select Pydev to download.

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

2.Jython Development Environment Configuration

Window-preferences-pydev-python interpreter, the new Python interpreter, the path to select your Python.exe, click OK.

Following the page prompts, after loading completes, the configuration of the Jython environment begins.

Window-preferences-pydev-jython interpreter, the new one Jython, the path chooses Sdk\tools\ jython-standalone-2.5.3.jar, click OK.

If the load results are as follows:

Then copy the entire LIB file in Python to the directory of Jython-standalone-2.5.3.jar in the SDK Tools\lib, and again a new Jython, Add the Jython-standalone-2.5.3.jar path. or directly choose proceed anyways.

When the load is complete, click Apply-ok to complete the Jython environment configuration.

3.Monkeyrunner Development Environment Configuration

So far we have configured the Jython development environment, and we can create a Jython project. But we have not completed the Monkeyrunner configuration, so the current Jython project is not very convenient to develop Monkeyrunner.

In fact, building monkeyrunner development environment is to add the package we need to the Jython pythonpath inside, to facilitate our direct reference.

In Window-preference-pydev-jython interpreter, click on the "New jar/zips" button on the right and start selecting the Jar package you need to use below the \tools\lib below your SDK. Here is the jar package we need this time: Hierarchyviewer2.jar, Hierarchyviewer2lib.jar, Monkeyrunner.jar, Chimpchat.jar, add these jar packs in turn.

The last page to load successfully is as follows:

So far, Monkeyrunner's environment configuration is complete.

4.Jython Project Creation

After the environment is finished, we can create a new Jython project. Below we create a Jython project.

In file, new project, and select Pydev project.

According to the requirements, fill in the project name and select the type of item for Jython, click Finish.

When the project is new, click the selected item, right-click, new Pydev Module, and when you're done, you can write a Python program.

Now, we copy the script written in Monkeyrunner directly into Eclipse, the new Pydev module, which includes a guide package, a connection device, an app installed, a startup app:

From Com.android.monkeyrunner import Monkeyrunner,monkeydevice 
device=monkeyrunner.waitforconnection ()
Device.installpackage (' f:\\qq_374.apk ') 
device.startactivity (component= "com.tencent.mobileqq/.activity"). Splashactivity ")

Actually executing this code requires the Monkeyrunner.bat provided by Android, so you can't run the program as usual, so then configure the run of the Monkeyrunner script in Eclipse.

Run Monkeyrunner script in 5.Eclipse

Select Run-external tools-external Tools configurations in the menu bar,

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

Note: The above configuration is for test02.py only, and if a new Pydev Package is available, change the configuration of working directory and arguments at the same time.

Once the simulator is started, you can then run the newly created Pydev module.

On the simulator, we can see the automatic installation and startup of the app. This means that the environment has been configured successfully, and then you can edit the Monkeyrunner script in Eclipse and run it.

6.eclipse running Monkeyrunner script, problem and solution

Run Moneyrunner script in Eclipse, error: Software in your host aborted an established connection

Workaround:

1. Kill Process Adb.exe,
1 view 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, connect the equipment
1) Open cmd
2 Connection Simulator:adb connect IP

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.