我想动态添加.jar。所以我做了一个演示。但我不知道如何更新DexClassLoader。我不知道如何添加第一个参数。
final File optimizedDexOutputPath = new File("" + File.pathSeparator + "test.jar");
//PackageManager pm = getPackageManager();
String dexOutputDir = getApplicationInfo().dataDir;
DexClassLoader dexClassLoader = new DexClassLoader("", dexOutputDir, null, getClassLoader());我已经将动态文本设置为test.jar(成为dex),并在项目中创建了一个新的文件夹‘.jar’,并将text.jar放入其中。
你能帮我看看我做错了什么吗?
发布于 2015-04-16 22:24:57
动态加载jar的代码应该如下所示:
//get the path to your .jar as a String
String jarPath = this.getApplicationContext().getFilesDir().getAbsolutePath();
jarPath += File.pathSeparator + "test" + File.pathSeparator + "test.jar";
//get a path to the directory you want to store odexs in as a String
String optimizedDir = this.getApplicationContext().getDir("odex", MODE_PRIVATE).getAbsolutePath();
//finally, call DexClassLoader
DexClassLoader dcl = new DexClassLoader( jarPath, optimizedDir, null, getClassLoader() );上面假设您已经在应用程序的私有文件区域中创建了一个名为"test“的目录,并在该目录中放置了test.jar。您可以创建此目录,并可能在应用程序首次启动时将test.jar从应用程序的资产区域复制到此目录中。
发布于 2016-03-15 20:51:16
尝试以下代码:
// dexPath is the absolute path of your **DEX** file
ClassLoader loader = context.getClassLoader();
dexLoader = new dalvik.system.DexClassLoader(**dexPath**, dexOutputDir, null, loader);https://stackoverflow.com/questions/29673074
复制相似问题