本文整理匯總了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);
}
}