Please edit the question if needed.
I am Using android UiAutomator.
UiAutomation run perfectly , but I want use java reflection on UiAutomator.jar (Which internally contain claasses.dex)
So problem is that java reflection API use some.jar file (which contain xyz.class
instead of .dex
)
So how can access this .dex file from UiAutomationTest.jar
I am using this tool which convert .dex
to .jar( which contain .class
files)
Link : how to use DEXtoJar
I need it programatically. -
Now i am unable to load UiAutomator.jar into memory ( for getting .dex file from jar then again convert to claasses.dex to classes.jar-)
so it is givng following error.
Code snip I am using.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Here I am placed my UiAutomationTest.jar which produce from UiAutomation ant build tool.
String sourceDir = Environment.getExternalStorageDirectory().toString()+"/UiAutomationTest.jar"; //getApplicationInfo().sourceDir;
try {
DexFile dexFile = new DexFile(sourceDir); // Exception propagate from here.
} catch (IOException e) {
e.printStackTrace();
}
//exploreJar(); // For exploring jar from dex.
}
Logcat message:
07-31 15:50:18.339: E/dalvikvm(19748): Dex cache directory isn't writable: /data/dalvik-cache
07-31 15:50:18.339: W/System.err(19748): java.io.IOException: unable to open DEX file
07-31 15:50:18.339: W/System.err(19748): at dalvik.system.DexFile.openDexFile(Native Method)
07-31 15:50:18.339: W/System.err(19748): at dalvik.system.DexFile.<init>(DexFile.java:78)
07-31 15:50:18.339: W/System.err(19748): at com.example.dextestproject.MainActivity.onCreate(MainActivity.java:35)
07-31 15:50:18.349: W/System.err(19748): at android.app.Activity.performCreate(Activity.java:5008)
07-31 15:50:18.349: W/System.err(19748): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-31 15:50:18.349: W/System.err(19748): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2026)
07-31 15:50:18.349: W/System.err(19748): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2087)
07-31 15:50:18.349: W/System.err(19748): at android.app.ActivityThread.access$600(ActivityThread.java:133)
07-31 15:50:18.349: W/System.err(19748): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
07-31 15:50:18.349: W/System.err(19748): at android.os.Handler.dispatchMessage(Handler.java:99)
07-31 15:50:18.349: W/System.err(19748): at android.os.Looper.loop(Looper.java:137)
07-31 15:50:18.349: W/System.err(19748): at android.app.ActivityThread.main(ActivityThread.java:4803)
07-31 15:50:18.349: W/System.err(19748): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 15:50:18.349: W/System.err(19748): at java.lang.reflect.Method.invoke(Method.java:511)
07-31 15:50:18.349: W/System.err(19748): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
07-31 15:50:18.349: W/System.err(19748): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
07-31 15:50:18.359: W/System.err(19748): at dalvik.system.NativeStart.main(Native Method)