手把手教你ranorex_android源碼instrument


 

話說ranorex能把android程序看的透徹,關鍵是在潛伏,他使用instrumentation,在每個界面(activity)裏面,準確的說是onresume,也就是頁面顯示的時候,都給安裝了個鉤子(hook),等到界面不顯示了,也就是pause了,就去掉這個hook,所以ranorex才能對android程序的界面元素一清二楚。

 

好吧,我說說具體步驟:

 

 

 

instrumentation處理源文件:

1.      在源文件工程中引用:ranorex.jar,位置在:C:\安裝目錄\Ranorex 4.1\Bin\ RxEnv\Android\

 

001.png

 

 

2.      給所有的activity加上代碼:

@Override

public void onResume()

{

 super.onResume();

 com.ranorex.android.RanorexAndroidAutomation.Hook(this);

}

 

@Override

public void onPause()

{

 super.onPause();

 com.ranorex.android.RanorexAndroidAutomation.UnHook(this);

}

 

@Override

public boolean dispatchKeyEvent(android.view.KeyEvent event)

{

 com.ranorex.android.RanorexAndroidAutomation.Key(event);

 return super.dispatchKeyEvent(event);

}

 

 

 

3.      添加權限

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.INJECT_EVENTS" />

 

002.png

 

這個意思是隻有系統應用程序纔可以使用這個權限,在程序中插入事件,絕對不是幹好事的。^_^

不用搭理他,project-clean一下,報錯就消失了,編譯能通過的。

 

 

4.      添加版本號

幫助中說明:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

 package="YOUR PACKAGE"

 android:versionCode="YOUR CODE VERSION"

 android:versionName="YOUR VERSION NAME (RxInstrumented$<RANOREX-VERSION>)">

原文:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.amem"

    android:versionCode="1"

    android:versionName="1.0" >

修改爲:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.amem"

    android:versionCode="1"

    android:versionName="1.0(RxInstrumented$4.1.5)>" >

 

 

版本號查看方法:

003.png

 

 

好了,這就搞定了,編譯成apk就可以用來測試了。

 

其實在deploy的時候,勾選上instrument就工具就自動幫你搞定了,是不是有點崩潰,這篇文章白看了。^_^

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章