Dex缓存目录不可写:/ data / dalvik-cache

时间:2014-07-31 10:38:48

标签: java android jar uiautomator android-uiautomator

如果需要,请编辑问题。

我正在使用android UiAutomator

UiAutomation运行完美,但我想在UiAutomator.jar上使用java反射(内部包含claasses.dex)

问题是java 反射 API使用some.jar文件(包含xyz.class而不是.dex

那么如何从UiAutomationTest.jar

访问这个.dex文件

我正在使用此工具将.dex转换为.jar(包含.class个文件) 链接:how to use DEXtoJar

我以编程方式需要它。 -

现在我无法将UiAutomator.jar加载到内存中(从jar获取.dex文件然后再次转换为claasses.dex到classes.jar-)

所以它会出现以下错误。

我正在使用的代码片段。

    @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消息:

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)

1 个答案:

答案 0 :(得分:2)

我从这里了解到Is there a way to get the class names in a given classes.dex file?

你应该使用:

File f = new File(Environment.getExternalStorageDirectory()+"/classes.zip");
File tmp = new File(Environment.getExternalStorageDirectory()+"/classes.odex");

DexFile dexfile = DexFile.loadDex(f.getAbsolutePath(), tmp.getAbsolutePath(), 0);

而不是:

DexFile dexfile = new DexFile(f);