我正在嘗試通過 DexClassLoader嘗試加載外部庫的項目。這2.3工作得很好:可惜Android Honeycomb上的DexClassLoader
public class FormularDisplayLoader {
public final static String PATH ="/data/data/at.mSystem.client/files/mSystem_Client_FormularLibrary.jar";
private DexClassLoader classLoader;
public FormularDisplayLoader(Context context){
this.context = context;
this.classLoader = new DexClassLoader("/data/data/at.mSystem.client/
files/mSystem_Client_FormularLibrary.jar",
context.getFilesDir().getAbsolutePath(),
null,
FormularDisplayLoader.class.getClassLoader());
}
public View getDisplay(String className) throws ErrorCodeException{
try {
Class c = classLoader.loadClass(className);
Method m = c.getMethod("getDisplay", Context.class);
View ret = (View) m.invoke(c.newInstance(), context);
return ret;
} catch (Exception e) {
e.printStackTrace();
throw new
ErrorCodeException(FormularErrorCode.NO_DISPLAY_AVAILABLE_FOR_FORMULAR);
}
}
}
,試圖端口這個應用蜂窩時(因爲該應用程序的 實際目標有片劑)的DexClassLoader拋出 例外:
02-23 09:30:58.221: ERROR/dalvikvm(8022): Can't open dex cache '/data/
dalvik-cache/
[email protected]@[email protected]@[email protected]':
No such file or directory
02-23 09:30:58.221: INFO/dalvikvm(8022): Unable to open or create
cache for /data/data/at.mSystem.client/files/
mSystem_Client_FormularLibrary.jar (/data/dalvik-cache/
[email protected]@[email protected]@[email protected])
02-23 09:30:58.231: WARN/System.err(8022):
java.lang.ClassNotFoundException:
at.mSystem.client.formular.contract.ContractListFormularDisplay in
loader [email protected]
02-23 09:30:58.241: WARN/System.err(8022): at
dalvik.system.DexClassLoader.findClass(DexClassLoader.java:240)
02-23 09:30:58.241: WARN/System.err(8022): at
java.lang.ClassLoader.loadClass(ClassLoader.java:548)
02-23 09:30:58.261: WARN/System.err(8022): at
java.lang.ClassLoader.loadClass(ClassLoader.java:508)
02-23 09:30:58.261: WARN/System.err(8022): at
at.mSystem.client.system.formularmodule.formular.FormularDisplayLoader.getDisplay(FormularDisplayLoader.java:
35)
看起來DexClassLoader忽略了第二個參數 (dexOutputDir),因爲在我的示例中context.getFilesDir()。getAbsolutePath()的值爲 「/ data/data/ at.mSystem.client/files」。
你有什麼想法如何解決?或者這是一種 蜂窩錯誤?
感謝,
羅蘭
我沒有答案,但只是想讓你知道我遇到了同樣的問題。 – gotosleep 2011-03-31 20:04:34
我在Android的問題跟蹤器上打開了一張票:http://code.google.com/p/android/issues/detail?id=15893 – gotosleep 2011-03-31 21:08:25
當您提交它時,Google的某個人說:「是的,內部錯誤3439372.預定對於即將發佈的Honeycomb維護版本「 – 2011-09-15 17:37:21