本文整理汇总了Java中dalvik.system.DexClassLoader类的典型用法代码示例。如果您正苦于以下问题:Java DexClassLoader类的具体用法?Java DexClassLoader怎么用?Java DexClassLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DexClassLoader类属于dalvik.system包,在下文中一共展示了DexClassLoader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: injectBelowApiLevel14
import dalvik.system.DexClassLoader; //导入依赖的package包/类
@TargetApi(14)
private static void injectBelowApiLevel14(Context context, String str, String str2)
throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
PathClassLoader obj = (PathClassLoader) context.getClassLoader();
DexClassLoader dexClassLoader =
new DexClassLoader(str, context.getDir("dex", 0).getAbsolutePath(), str, context.getClassLoader());
dexClassLoader.loadClass(str2);
setField(obj, PathClassLoader.class, "mPaths",
appendArray(getField(obj, PathClassLoader.class, "mPaths"), getField(dexClassLoader, DexClassLoader.class,
"mRawDexPath")
));
setField(obj, PathClassLoader.class, "mFiles",
combineArray(getField(obj, PathClassLoader.class, "mFiles"), getField(dexClassLoader, DexClassLoader.class,
"mFiles")
));
setField(obj, PathClassLoader.class, "mZips",
combineArray(getField(obj, PathClassLoader.class, "mZips"), getField(dexClassLoader, DexClassLoader.class,
"mZips")));
setField(obj, PathClassLoader.class, "mDexs",
combineArray(getField(obj, PathClassLoader.class, "mDexs"), getField(dexClassLoader, DexClassLoader.class,
"mDexs")));
obj.loadClass(str2);
}
示例2: getDexClassLoader
import dalvik.system.DexClassLoader; //导入依赖的package包/类
public static DexClassLoader getDexClassLoader( Context context ){
File cacheFile = FileUtils.getCacheDir(context.getApplicationContext());
String internalPath = cacheFile.getAbsolutePath() + File.separator + "dynamic_dex.jar";
File desFile = new File(internalPath);
try {
if (!desFile.exists()) {
desFile.createNewFile();
FileUtils.copyFiles( context , "dynamic_dex.jar", desFile);
}
} catch (IOException e) {
e.printStackTrace();
}
//下面开始加载dex class
DexClassLoader dexClassLoader = new DexClassLoader(internalPath, cacheFile.getAbsolutePath(), null,context.getClassLoader() );
return dexClassLoader ;
}
示例3: loadLibrary
import dalvik.system.DexClassLoader; //导入依赖的package包/类
public void loadLibrary(String jarpath, Context context) {
this.context = context;
File jarfile = new File(jarpath);
if(!jarfile.exists())
throw new IllegalArgumentException("Could not find library: " + jarpath);
this.jarpath = jarpath;
File optimizedLibrarypath = context.getDir("dex", 0);
File cachedDex = new File(optimizedLibrarypath.getPath() + "/" + jarpath.replace("jar", "dex"));
Log.d(TAG, "Checking for cached version in " + optimizedLibrarypath.getAbsolutePath());
File files[] = optimizedLibrarypath.listFiles();
for (int i = 0;i < files.length; i++) {
Log.d(TAG, "File: " + files[i].getName());
if (files[i].getName().equals(jarfile.getName().replace("jar", "dex"))) {
Log.d(TAG, "A cached " + files[i].getName() + " exists in " + optimizedLibrarypath.getAbsolutePath() + ". Removing it");
files[i].delete();
}
}
dexClassLoader = new DexClassLoader(jarpath, optimizedLibrarypath.getAbsolutePath(),
null, context.getClassLoader());
}
示例4: createClassLoader
import dalvik.system.DexClassLoader; //导入依赖的package包/类
public ClassLoader createClassLoader() throws TGResourceException {
Context context = this.activity.getApplicationContext();
String optimizedDirectory = context.getDir("dex", Context.MODE_PRIVATE).getAbsolutePath();
List<String> fileNames = this.unpackPlugins(optimizedDirectory);
if(!fileNames.isEmpty()) {
return new DexClassLoader(this.createPath(fileNames), optimizedDirectory, this.createLibraryPath(), context.getClassLoader());
}
return null;
}
示例5: injectDexElements
import dalvik.system.DexClassLoader; //导入依赖的package包/类
/**
* 合并注入
*
* @param context
* @param patchFilePath 补丁所在文件夹(尽量是SD卡的路径, 否则会打开文件失败)
* @throws Exception
*/
public static void injectDexElements(Context context, String patchFilePath) throws Exception {
ClassLoader pathClassLoader = context.getClassLoader();
/**dex, 优化后的路径, 必须在要App data目录下, 否则会没有权限*/
File oDexFile = new File(context.getDir("odex", Context.MODE_PRIVATE).getAbsolutePath());
/**dex 补丁文件路径(文件夹)*/
File patchFile = new File(patchFilePath);
if (!patchFile.exists()) {
patchFile.mkdirs();
}
// 合并成一个数组
Object applicationDexElement = getDexElementByClassLoader(pathClassLoader);
for (File dexFile : patchFile.listFiles()) {
ClassLoader classLoader = new DexClassLoader(dexFile.getAbsolutePath(),// dexPath
oDexFile.getAbsolutePath(),// optimizedDirectory
null,
pathClassLoader
);
// 获取这个classLoader中的Element
Object classElement = getDexElementByClassLoader(classLoader);
//Log.e("TAG", classElement.toString());
applicationDexElement = combineArray(classElement, applicationDexElement);
}
// 注入到pathClassLoader中
injectDexElements(pathClassLoader, applicationDexElement);
}
示例6: init
import dalvik.system.DexClassLoader; //导入依赖的package包/类
public boolean init(File path) {
_path = path;
try {
File parentFile = path.getParentFile();
_classLoader = new DexClassLoader(_path.getAbsolutePath(), parentFile.getAbsolutePath(), null, getClass().getClassLoader());
_pluginPackage = new ZipFile(_path);
ZipEntry entry = _pluginPackage.getEntry("plugin.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(_pluginPackage.getInputStream(entry)));
String pluginClassName = reader.readLine();
reader.close();
Class<?> pluginClass = _classLoader.loadClass(pluginClassName);
_plugin = (XulPlugin) pluginClass.newInstance();
return true;
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}
示例7: DexLoader
import dalvik.system.DexClassLoader; //导入依赖的package包/类
public DexLoader(Context var1, String[] var2, String var3, String var4) {
Object var5 = var1.getClassLoader();
String var6 = var1.getApplicationInfo().nativeLibraryDir;
if(!TextUtils.isEmpty(var4)) {
var6 = var6 + File.pathSeparator + var4;
}
for(int var7 = 0; var7 < var2.length; ++var7) {
var5 = this.mClassLoader = new DexClassLoader(var2[var7], var3, var6, (ClassLoader)var5);
}
}
示例8: allMethods
import dalvik.system.DexClassLoader; //导入依赖的package包/类
/***
* hack all defined methods
**/
private static void allMethods() throws HackAssertionException {
ActivityThread_currentActivityThread = ActivityThread.method(
"currentActivityThread");
// ActivityThread_currentProcessName = ActivityThread.method(
// "currentProcessName");
AssetManager_addAssetPath = AssetManager.method("addAssetPath",
String.class);
Application_attach = Application.method("attach", Context.class);
ClassLoader_findLibrary = ClassLoader.method("findLibrary",
String.class);
if (LexFile != null && LexFile.getmClass() != null) {
LexFile_loadLex = LexFile.method("loadLex", String.class,
Integer.TYPE);
LexFile_loadClass = LexFile.method("loadClass", String.class,
ClassLoader.class);
LexFile_close = LexFile.method("close");
DexClassLoader_findClass = DexClassLoader.method("findClass",
String.class);
}
PackageParser$Component_getComponentName = PackageParser$Component.method("getComponentName", new Class[0]);
}
示例9: injectBelowApiLevel14
import dalvik.system.DexClassLoader; //导入依赖的package包/类
@TargetApi(14)
private static void injectBelowApiLevel14(Context context, String str, String str2)
throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
PathClassLoader obj = (PathClassLoader) context.getClassLoader();
DexClassLoader dexClassLoader =
new DexClassLoader(str, context.getDir("dex", 0).getAbsolutePath(), str, context.getClassLoader());
dexClassLoader.loadClass(str2);
setField(obj, PathClassLoader.class, "mPaths",
appendArray(getField(obj, PathClassLoader.class, "mPaths"), getField(dexClassLoader, DexClassLoader.class,
"mRawDexPath")
));
setField(obj, PathClassLoader.class, "mFiles",
combineArray(getField(obj, PathClassLoader.class, "mFiles"), getField(dexClassLoader, DexClassLoader.class,
"mFiles")
));
setField(obj, PathClassLoader.class, "mZips",
combineArray(getField(obj, PathClassLoader.class, "mZips"), getField(dexClassLoader, DexClassLoader.class,
"mZips")));
setField(obj, PathClassLoader.class, "mDexs",
combineArray(getField(obj, PathClassLoader.class, "mDexs"), getField(dexClassLoader, DexClassLoader.class,
"mDexs")));
obj.loadClass(str2);
}
示例10: useDexClassLoader2
import dalvik.system.DexClassLoader; //导入依赖的package包/类
public void useDexClassLoader2() {
DexClassLoader cDexClassLoader =
new DexClassLoader("/mnt/sdcard/Myplugdex.jar", "/data/data/com.example.icunqiu", null, this.getClass()
.getClassLoader());
Toast.makeText(getApplicationContext(), "ufiuhfu", 0).show();
try {
Class<?> class1 = cDexClassLoader.loadClass("com.plug.PlugImpl");
Object interfacePlug = class1.newInstance();
Toast.makeText(getApplicationContext()," ret+", 0).show();
//�ӿ��Dz���ʵ�����ģ�������������һ���ӿڵ����ñ���������ָ��һ�����ʵ������Ȼ�Ǹ���Ҫʵ�����Ǹ��ӿڵ�
InterfacePlug interfacePlug2=(InterfacePlug) interfacePlug;
int ret = interfacePlug2.function_02(12, 13);
Toast.makeText(getApplicationContext(), ret+"", 0).show();
} catch (Exception e) {
}
}
示例11: installInitPlugins
import dalvik.system.DexClassLoader; //导入依赖的package包/类
/**
* 安装初始的内置插件
*/
private static void installInitPlugins() {
HashMap<String, PluginManifest> installedList = getInstalledPlugin();
HashMap<String, Integer> defaultList = getDefaultPlugin();
for (String key : defaultList.keySet()) {
int installVersion = -1;
int defaultVersion = defaultList.get(key);
if (installedList.containsKey(key)) {
installVersion = installedList.get(key).getVersion();
}
ZeusPlugin plugin = getPlugin(key);
if (defaultVersion > installVersion) {
boolean ret = plugin.installAssetPlugin();
//提前将dex文件优化为odex或者opt文件
if (ret) {
try {
new DexClassLoader(PluginUtil.getAPKPath(key), PluginUtil.getDexCacheParentDirectPath(key), null, mBaseClassLoader.getParent());
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
}
示例12: loadDexClasses
import dalvik.system.DexClassLoader; //导入依赖的package包/类
private void loadDexClasses() {
cl = new DexClassLoader(getDexInternalStoragePath().getAbsolutePath(),
getOptimizedDexOutputPath().getAbsolutePath(),
null,
mContext.getClassLoader());
initialized = true;
Handler handler = new Handler(mContext.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
mDexLoadListener.onLoadSuccess();
}
});
}
示例13: getDex
import dalvik.system.DexClassLoader; //导入依赖的package包/类
public static DexClassLoader getDex(Context apps) {
ApplicationInfo info = apps.getApplicationInfo();
String dexPath=info.sourceDir;
String dexOutputDir=info.dataDir;
String libPath=info.nativeLibraryDir;
DexClassLoader dl= new DexClassLoader(dexPath, dexOutputDir,
libPath, apps.getClass().getClassLoader());
try {
Enumeration<URL> gaga = dl.getResources("com.example.mylib_test");
System.out.println(1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
DexFile df = new DexFile(dexOutputDir);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dl;
}
示例14: injectAboveEqualApiLevel14
import dalvik.system.DexClassLoader; //导入依赖的package包/类
private static synchronized Boolean injectAboveEqualApiLevel14(
String dexPath, String defaultDexOptPath, String nativeLibPath, String dummyClassName) {
Log.i(TAG, "--> injectAboveEqualApiLevel14");
PathClassLoader pathClassLoader = (PathClassLoader) DexInjector.class.getClassLoader();
DexClassLoader dexClassLoader = new DexClassLoader(dexPath, defaultDexOptPath, nativeLibPath, pathClassLoader);
try {
dexClassLoader.loadClass(dummyClassName);
Object dexElements = combineArray(
getDexElements(getPathList(pathClassLoader)),
getDexElements(getPathList(dexClassLoader)));
Object pathList = getPathList(pathClassLoader);
setField(pathList, pathList.getClass(), "dexElements", dexElements);
} catch (Throwable e) {
e.printStackTrace();
return false;
}
Log.i(TAG, "<-- injectAboveEqualApiLevel14 End.");
return true;
}
示例15: initSnsReader
import dalvik.system.DexClassLoader; //导入依赖的package包/类
public void initSnsReader() {
File outputAPKFile = new File(Config.EXT_DIR + "/wechat.apk");
if (!outputAPKFile.exists())
copyAPKFromAssets();
try {
Config.initWeChatVersion("6.3.13.64_r4488992");
DexClassLoader cl = new DexClassLoader(
outputAPKFile.getAbsolutePath(),
context.getDir("outdex", 0).getAbsolutePath(),
null,
ClassLoader.getSystemClassLoader());
Class SnsDetailParser = null;
Class SnsDetail = null;
Class SnsObject = null;
SnsDetailParser = cl.loadClass(Config.SNS_XML_GENERATOR_CLASS);
SnsDetail = cl.loadClass(Config.PROTOCAL_SNS_DETAIL_CLASS);
SnsObject = cl.loadClass(Config.PROTOCAL_SNS_OBJECT_CLASS);
snsReader = new SnsReader(SnsDetail, SnsDetailParser, SnsObject);
} catch (Throwable e) {
Log.e("wechatmomentstat", "exception", e);
}
}