本文整理汇总了Java中dalvik.system.BaseDexClassLoader类的典型用法代码示例。如果您正苦于以下问题:Java BaseDexClassLoader类的具体用法?Java BaseDexClassLoader怎么用?Java BaseDexClassLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BaseDexClassLoader类属于dalvik.system包,在下文中一共展示了BaseDexClassLoader类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getClassLoaderLdLoadLibrary
import dalvik.system.BaseDexClassLoader; //导入依赖的package包/类
public static String getClassLoaderLdLoadLibrary() {
final ClassLoader classLoader = SoLoader.class.getClassLoader();
if (!(classLoader instanceof BaseDexClassLoader)) {
throw new IllegalStateException(
"ClassLoader "
+ classLoader.getClass().getName()
+ " should be of type BaseDexClassLoader");
}
try {
final BaseDexClassLoader baseDexClassLoader = (BaseDexClassLoader) classLoader;
final Method getLdLibraryPathMethod =
BaseDexClassLoader.class.getMethod("getLdLibraryPath");
return (String) getLdLibraryPathMethod.invoke(baseDexClassLoader);
} catch (Exception e) {
throw new RuntimeException("Cannot call getLdLibraryPath", e);
}
}
示例2: loadFromAssets
import dalvik.system.BaseDexClassLoader; //导入依赖的package包/类
public static void loadFromAssets(Context context, String fileName) throws Exception {
//File optimized = context.getCodeCacheDir();
File optimized = new File(optimizedDirectory);
optimized = context.getDir(optimized.toString(), Context.MODE_PRIVATE);
optimized = new File(optimized, fileName);
optimized.mkdir();
File work = context.getDir(workDirectory, Context.MODE_PRIVATE);
work = new File(work, fileName);
InputStream inputDex = context.getAssets().open(fileName);
FileOutputStream outputDex = new FileOutputStream(work);
byte[] buf = new byte[0x1000];
while (true) {
int r = inputDex.read(buf);
if (r == -1)
break;
outputDex.write(buf, 0, r);
}
outputDex.close();
inputDex.close();
ClassLoader localClassLoader = Dexter.class.getClassLoader();
BaseDexClassLoader classLoader = new DexClassLoader(work.getAbsolutePath(), optimized.getAbsolutePath(), null, localClassLoader);
if(localClassLoader instanceof BaseDexClassLoader) {
Object existing = getDexClassLoaderElements((BaseDexClassLoader) localClassLoader);
Object incoming = getDexClassLoaderElements(classLoader);
Object joined = joinArrays(incoming, existing);
setDexClassLoaderElements((BaseDexClassLoader) localClassLoader, joined);
} else {
throw new UnsupportedOperationException("Class loader not supported");
}
}
示例3: setDexClassLoaderElements
import dalvik.system.BaseDexClassLoader; //导入依赖的package包/类
private static void setDexClassLoaderElements(BaseDexClassLoader classLoader, Object elements) throws Exception {
Class<BaseDexClassLoader> dexClassLoaderClass = BaseDexClassLoader.class;
Field pathListField = dexClassLoaderClass.getDeclaredField("pathList");
pathListField.setAccessible(true);
Object pathList = pathListField.get(classLoader);
Field dexElementsField = pathList.getClass().getDeclaredField("dexElements");
dexElementsField.setAccessible(true);
dexElementsField.set(pathList, elements);
}
示例4: getDexClassLoaderElements
import dalvik.system.BaseDexClassLoader; //导入依赖的package包/类
private static Object getDexClassLoaderElements(BaseDexClassLoader classLoader) throws Exception {
Class<BaseDexClassLoader> dexClassLoaderClass = BaseDexClassLoader.class;
Field pathListField = dexClassLoaderClass.getDeclaredField("pathList");
pathListField.setAccessible(true);
Object pathList = pathListField.get(classLoader);
Field dexElementsField = pathList.getClass().getDeclaredField("dexElements");
dexElementsField.setAccessible(true);
Object dexElements = dexElementsField.get(pathList);
return dexElements;
}
示例5: getDexPathList
import dalvik.system.BaseDexClassLoader; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private Object getDexPathList(BaseDexClassLoader classLoader)
throws NoSuchFieldException, IllegalAccessException {
return getField(classLoader, BaseDexClassLoader.class, "pathList");
}
示例6: getDexPathList
import dalvik.system.BaseDexClassLoader; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private Object getDexPathList(BaseDexClassLoader classLoader)
throws NoSuchFieldException, IllegalAccessException {
return Reflect.getField(classLoader, BaseDexClassLoader.class, "pathList");
}