Preface
As you can see the description on Android Developer Site, you can extend MonkeyRunner by writing java programming language and integrate to an Jar file and create more capacities for your control purpose. In following section, using 21 steps to guide you how to create a monkeyrunner extension JAR file.
How to create a Jar component for MonkeyRunner?
Before we start to know how to create a Jar Component for MonkeyRunner, there're something you need to do in advance. The J2SDK installation on your computer is required and you need to know how to program Java based program. Eclipse is an option, however it's very useful. Android SDK installation is required.
Here I'll show you an example by using Eclipse to create a Jar component for MonkeyRunner Extension.
1. Using Eclipse to create a Java Project through File->New->Java Project. Fill the project name.
2. Press Next button.
4. Tap "Add External JARs..." button.
5. Add Jar files - Pick chimpchat.jar, guavalib.jar, jython.jar, and monkeyrunner.jar in the folder - /android_sdk_folder/tools/lib/.
6. Press Finish button.
7. Fill the package name - com.android.monkeyrunner.
8. Fill the class name.
9. Press Finish button.
10. If you need to initial some variable for monkeyrunner runtime environment, you can implement a interface named Predicate
11. In this example, I create three static methods for interacting with Android device. They're tap, PressButton, and saveScreenToFile respectively. These functions are to trigger a touch event, and a button event, and to save run-time screen to a file. In order to implement these function to communicate with Android device, we need to import MonkyDevice and MonkeyImage classes. The usage is similar with what you wrote on monkeyrunner console to control Android devices. The difference is that you need to use Python Object class for given parameters. For instance, to invoke a touch event, you can use touch method in MonkeyDevice class. But you need to give a value which is belong to the type of PyObject. Hence, we declare a PyObject variable and assign two integer and one string as their values that is needed by declared PyObject variable. For given parameters, the two integer values are used to assign where to touch and the string value is used to assign which action we're going to use for touch event (E.g. DOWN, UP, or DOWN_AND_UP). Note that, you can not use int as integer's type in PyObject's initialization. To assign an integer value to PyObject class, the type of PyInteger Object is needed. To assign a string value to PyObject class, the type of PyString Object is needed.
12. The Eclipse is very useful for developing MonkeyRunner Extension Jar file, because you can see the tip when your mouse move cursor to the method. Hence, you can know what type and you should use and how many parameters you should provide for particular method.
13. Start to export your wrote files to a Jar file for MonkeyRunner after you finish the coding work.
14. Move mouse to project name on Eclipse and right click the mouse.
15. Click Export option.
16. Select JAR file and press Next button.
17. Select the files which are going to be exported and press Next button.
18. Press Next Button.
19. If you don't have a MANIFEST file existed already, you can select option of "Generate the manifest file" and press Browser button to select where to store the MANIFEST file. You can give a name like MANIFEST.MF and place in root folder of project. If you have a MANIFEST file already, you can select option - Use existing manifest from workspace and select your own file.
20. Press Finish button.
21. Edit the MANIFEST file you used at last step and add a command - MonkeyRunnerStartupRunner: com.android.monkeyrunner.monkeyrunnerExt to MANIFEST file. The string of MonkeyRunnerStartupRunner: is followed by full package name of your class. Finally, save your modified MANIFEST file to your JAR file.
How to import your own Jar file for MonkeyRunner?
Copy your Jar file to /android-sdk_folder/tools/lib before running monkeyrunner.bat. Double click monkeyrunner.bat at the folder of android-sdk/tools/ to bring up a MonkeyRunner console as follows. And import the necessary class and your own class as follows. Then you can use your own class to do something on MonkeyRunner run-time environment.
Reference
http://developer.android.com/tools/help/monkeyrunner_concepts.html#Plugins
Sir, I am having problems with the last part of your (well described) process, the problem is that monkeyrunner refuses to import monkeyrunnerExt saying this package is not signed.
回覆刪除tried repeating this process building it as Android app, but i couldn't find the way to create a Jar file and signing it.
Hope u can help.
Best Regards
Raul Jacinto
作者已經移除這則留言。
刪除Greeting, do you follow all the steps aforementioned and have the same class name - monkeyrunnerExt with package name com.android.monkeyrunner? To sign this class is unnecessary.It's a Java application rather than a Android app. You should create a Jar file and don't need to sign it. The monkeyrunner plugin would be run with Monkeyrunner environment on a PC or NB. Is it helpful. Any question you can post here again. Good Luck.
回覆刪除Thx for your demo about it.
回覆刪除So when i'm import my class, it was show more problem:
>monkeyrunner.bat -plugin MonKeyRunnerExt_001.jar
>>> from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
>>> from com.duy.monkeyrunner import monkeyrunnerExt as ME
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named duy
MF file info:
Manifest-Version: 1.0
monkeyrunner: com.duy.monkeyrunner.monkeyrunnerExt
Or:
>>> from com.android.monkeyrunner import monkeyrunnerExt as ME
Traceback (most recent call last):
File "", line 1, in
ImportError: cannot import name monkeyrunnerExt
MF file info:
Manifest-Version: 1.0
monkeyrunner: com.android.monkeyrunner.monkeyrunnerExt
Mypackage
-----
*.jar/com/android/monkeyrunner/monkeyrunnerExt.class
----
My code:
----
package com.android.monkeyrunner;
import org.python.core.PyInteger;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
import com.android.monkeyrunner.MonkeyDevice;
import com.android.monkeyrunner.MonkeyImage;
import com.google.common.base.Predicate;
//import javax.sql.rowset.Predicate;
public class monkeyrunnerExt implements Predicate{
public static void tap(MonkeyDevice device, int x, int y){
PyObject[] args = {
new PyInteger(x),
new PyInteger(y),
new PyString("DOWN_AND_UP")
};
String[] str = null;
device.touch(args, str);
}
public static void PressButton(MonkeyDevice device, String keyCode){
PyObject[] args = {
new PyString(keyCode),
new PyString("DOWN_AND_UP"),
new PyString("")
};
device.press(args, null);
}
public static void saveScreenToFile(MonkeyDevice device, String fileName){
MonkeyImage snapShot = device.takeSnapshot();
PyObject[] obj = {
new PyString(fileName),
new PyString("png")
};
String[] str = null;
snapShot.writeToFile(obj, str);
}
@Override
public boolean apply(PythonInterpreter arg0) {
// TODO Auto-generated method stub
return false;
}
}
----
Plz help me look this :)
--
thx you
Did you copy the jar file to yourSDKpath/tools/lib/?
回覆刪除您好,最近在研究monkeyrunner來到您的blog,感覺受益良多,謝謝
回覆刪除我照著以上的步驟去執行,在最後也產生了MonkeyRunnerExt.jar
可是在執行com.android.monkeyrunner import monkeyrunnerExt時出現錯誤:
Traceback (most recent call last):
File "", line 1, in
java.lang.SecurityException: sealing violation: can't seal package com.android.monkeyrunner: already loaded
...
..
java.lang.SecurityException: java.lang.SecurityException: sealing violation: can't seal package com.android.monkeyrunner: already loaded
想跟您請教怎麼解決這個問題,謝謝
您好,問題已經解決了
刪除真是不好意思,謝謝^^
很快就能解決了, 很厲害喔.
刪除How did you solve is the issue:
刪除Traceback (most recent call last):
File "", line 1, in
java.lang.SecurityException: sealing violation: can't seal package com.android.monkeyrunner: already loaded
...
..
java.lang.SecurityException: java.lang.SecurityException: sealing violation: can't seal package com.android.monkeyrunner: already loaded
There is a problem with:
刪除package com.android.monkeyrunner
it should be named something different, e.g.:
package com.my.test.monkeyhelper
that solves the issue
作者已經移除這則留言。
回覆刪除Muğla
回覆刪除Samsun
Eskişehir
Sakarya
Kars
NTH
Mardin
回覆刪除istanbul
Çanakkale
Antep
Elazığ
J08B
https://titandijital.com.tr/
回覆刪除denizli parça eşya taşıma
sinop parça eşya taşıma
artvin parça eşya taşıma
antep parça eşya taşıma
3MHUE2
ankara evden eve nakliyat
回覆刪除malatya evden eve nakliyat
antep evden eve nakliyat
giresun evden eve nakliyat
kayseri evden eve nakliyat
EQV
5C23F
回覆刪除Yalova Lojistik
Ardahan Parça Eşya Taşıma
Ordu Evden Eve Nakliyat
Balıkesir Parça Eşya Taşıma
Urfa Lojistik
F7A27
回覆刪除Kırıkkale Lojistik
Batman Evden Eve Nakliyat
Aydın Şehir İçi Nakliyat
Erzurum Evden Eve Nakliyat
Keçiören Parke Ustası
Pursaklar Boya Ustası
Çerkezköy Cam Balkon
Batıkent Fayans Ustası
İzmir Lojistik
89E32
回覆刪除Pursaklar Parke Ustası
Sivas Evden Eve Nakliyat
Elazığ Şehir İçi Nakliyat
Bitcoin Nasıl Alınır
Kırşehir Lojistik
Mardin Parça Eşya Taşıma
Samsun Parça Eşya Taşıma
Malatya Parça Eşya Taşıma
NWC Coin Hangi Borsada
2CA35
回覆刪除primobolan for sale
parabolan
order halotestin
order parabolan
buy sustanon
buy steroids
sarms for sale
buy clenbuterol
buy boldenone
5C76A
回覆刪除Muğla Şehirler Arası Nakliyat
İstanbul Parça Eşya Taşıma
Bitlis Şehir İçi Nakliyat
Kocaeli Lojistik
Tokat Evden Eve Nakliyat
Muğla Şehir İçi Nakliyat
Kütahya Evden Eve Nakliyat
Mardin Parça Eşya Taşıma
Bonk Coin Hangi Borsada
7E05B
回覆刪除binance %20 komisyon indirimi
1C908
回覆刪除sivas parasız sohbet
sohbet odaları
manisa seslı sohbet sıtelerı
istanbul canlı sohbet sitesi
bitlis yabancı canlı sohbet
mobil sesli sohbet
erzincan sesli sohbet sitesi
kadınlarla görüntülü sohbet
elazığ muhabbet sohbet
B7271
回覆刪除chat sohbet
yozgat bedava görüntülü sohbet sitesi
yalova görüntülü sohbet yabancı
rastgele görüntülü sohbet
mobil sohbet sitesi
sesli sohbet sesli chat
Ardahan Telefonda Kızlarla Sohbet
telefonda kızlarla sohbet
manisa yabancı görüntülü sohbet siteleri
63ECD
回覆刪除Mith Coin Hangi Borsada
Mexc Borsası Güvenilir mi
Binance'de Kaldıraç Var mı
Binance Hesap Açma
Snapchat Takipçi Satın Al
Bitcoin Hesap Açma
Twitter Beğeni Hilesi
Binance Referans Kodu
Threads Yeniden Paylaş Satın Al
4C62E
回覆刪除Tiktok İzlenme Satın Al
Görüntülü Sohbet
Binance Referans Kodu
Telegram Abone Satın Al
Nexa Coin Hangi Borsada
Binance Komisyon Ne Kadar
Linkedin Beğeni Hilesi
Binance Madencilik Nasıl Yapılır
Youtube İzlenme Satın Al
C0831
回覆刪除Yalıhüyük
Çermik
Tufanbeyli
Havran
Eruh
Tefenni
Çat
Baklan
Yayladağı