本文整理汇总了Java中dalvik.system.DexFile类的典型用法代码示例。如果您正苦于以下问题:Java DexFile类的具体用法?Java DexFile怎么用?Java DexFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DexFile类属于dalvik.system包,在下文中一共展示了DexFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadClass
import dalvik.system.DexFile; //导入依赖的package包/类
/**
* Try to load a class. This will search all defined classes, all loaded jars and the parent class loader.
*
* @param name the name of the class to load
* @param resolve ignored
* @return the class
* @throws ClassNotFoundException if the class could not be found in any of the locations
*/
@Override
public Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException {
Class<?> loadedClass = findLoadedClass(name);
if (loadedClass == null) {
for (DexFile dex : dx) {
loadedClass = dex.loadClass(name, parent);
if (loadedClass != null) {
break;
}
}
if (loadedClass == null) {
loadedClass = parent.loadClass(name);
}
}
return loadedClass;
}
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:26,代码来源:AndroidClassLoader.java
示例2: loadClass
import dalvik.system.DexFile; //导入依赖的package包/类
public static Class<?> loadClass(DexFile dexFile, String className, ClassLoader classLoader) throws ClassNotFoundException {
try {
Log.i(SharedClassesSettings.TAG, "Loading class " + className);
// Try the default class loader
return Class.forName(className);
}
catch (ClassNotFoundException ex) {
try {
// Try the given class loader
return classLoader.loadClass(className);
}
catch (ClassNotFoundException ex2) {
// We have no other choice than using the original class loading
Log.w(SharedClassesSettings.TAG, "Could not intercept class loading");
return dexFile.loadClass(className, classLoader);
}
}
}
示例3: loadDex
import dalvik.system.DexFile; //导入依赖的package包/类
public synchronized PatchClassLoader loadDex(){
if (classLoader == null){
try {
AtlasFileLock.getInstance().LockExclusive(odexFile);
dexFile = (DexFile) RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("loadDex",Context.class,String.class, String.class, int.class, boolean.class).invoke(
RuntimeVariables.sDexLoadBooster,RuntimeVariables.androidApplication, file.getAbsolutePath(), odexFile.getAbsolutePath(), 0, true);
if(dexFile!=null){
classLoader = new PatchClassLoader(sourceClassLoader,this);
}
} catch (Throwable e) {
e.printStackTrace();
}finally {
AtlasFileLock.getInstance().unLock(odexFile);
return classLoader;
}
}else{
return classLoader;
}
}
示例4: checkDexValid
import dalvik.system.DexFile; //导入依赖的package包/类
public boolean checkDexValid(DexFile odexFile) throws IOException {
if (DexReleaser.isArt()) {
String applicationName = KernalConstants.RAW_APPLICATION_NAME;
try {
Enumeration<String> enumeration = odexFile.entries();
while (enumeration.hasMoreElements()) {
if (enumeration.nextElement().replace("/", ".").equals(applicationName)) {
return true;
}
}
return false;
} catch (Throwable e) {
e.printStackTrace();
return false;
}
}
return true;
}
示例5: loadDex
import dalvik.system.DexFile; //导入依赖的package包/类
static public DexFile loadDex(Context context, String sourcePathName, String outputPathName,
int flags) throws Exception {
if(Build.VERSION.SDK_INT<=15) {
return DexFile.loadDex(sourcePathName,outputPathName,flags);
}else{
DexFile dexFile = DexFile.loadDex(context.getApplicationInfo().sourceDir,null,0);
try {
int cookie = (int)openDexFile.invoke(null,sourcePathName,outputPathName,flags);
mFileName.set(dexFile,sourcePathName);
mCookie.set(dexFile,cookie);
} catch (Exception e) {
throw e;
}
return dexFile;
}
}
示例6: optPatchDexFile
import dalvik.system.DexFile; //导入依赖的package包/类
private void optPatchDexFile() {
File debugBundleDir = new File(RuntimeVariables.androidApplication.getExternalFilesDir("debug_storage"), location);
File patchFile = new File(debugBundleDir,"patch.zip");
if(patchFile.exists()){
try {
// patchDexFileForDebug = AndroidRuntime.getInstance().loadDex(RuntimeVariables.androidApplication,
// patchFile.getAbsolutePath(), new File(debugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
//兼容7。0 动态部署过后不同classloader下对classcast
File internalDebugBundleDir = new File(new File(RuntimeVariables.androidApplication.getFilesDir(),"debug_storage"),location);
internalDebugBundleDir.mkdirs();
patchDexFileForDebug= (DexFile)RuntimeVariables.sDexLoadBooster.getClass().getDeclaredMethod("loadDex", Context.class, String.class, String.class, int.class, boolean.class).invoke(
RuntimeVariables.sDexLoadBooster,RuntimeVariables.androidApplication, patchFile.getAbsolutePath(), new File(internalDebugBundleDir,"patch.dex").getAbsolutePath(), 0,true);
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}
示例7: getClasses
import dalvik.system.DexFile; //导入依赖的package包/类
@Override
public Set<Class<?>> getClasses(String packageName) {
Set<Class<?>> classes = new HashSet<Class<?>>();
try {
DexFile dex = new DexFile(getContext().getApplicationInfo().sourceDir);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Enumeration<String> entries = dex.entries();
while (entries.hasMoreElements()) {
String entry = entries.nextElement();
if (entry.toLowerCase().startsWith(packageName.toLowerCase()))
classes.add(classLoader.loadClass(entry));
}
} catch (Exception e) {
Gdx.app.error("Errorororor", e.toString());
}
return classes;
}
示例8: install
import dalvik.system.DexFile; //导入依赖的package包/类
private static void install(ClassLoader loader, List<File> additionalClassPathEntries) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, IOException {
int extraSize = additionalClassPathEntries.size();
Field pathField = MultiDex.findField(loader, "path");
StringBuilder path = new StringBuilder((String) pathField.get(loader));
String[] extraPaths = new String[extraSize];
File[] extraFiles = new File[extraSize];
ZipFile[] extraZips = new ZipFile[extraSize];
DexFile[] extraDexs = new DexFile[extraSize];
ListIterator<File> iterator = additionalClassPathEntries.listIterator();
while (iterator.hasNext()) {
File additionalEntry = (File) iterator.next();
String entryPath = additionalEntry.getAbsolutePath();
path.append(':').append(entryPath);
int index = iterator.previousIndex();
extraPaths[index] = entryPath;
extraFiles[index] = additionalEntry;
extraZips[index] = new ZipFile(additionalEntry);
extraDexs[index] = DexFile.loadDex(entryPath, entryPath + ".dex", 0);
}
pathField.set(loader, path.toString());
MultiDex.expandFieldArray(loader, "mPaths", extraPaths);
MultiDex.expandFieldArray(loader, "mFiles", extraFiles);
MultiDex.expandFieldArray(loader, "mZips", extraZips);
MultiDex.expandFieldArray(loader, "mDexs", extraDexs);
}
示例9: loadClasses
import dalvik.system.DexFile; //导入依赖的package包/类
public void loadClasses() throws IOException,
ClassNotFoundException,
IllegalAccessException,
InstantiationException {
DexFile dexFile = DexFile.loadDex(this.jarpath, File.createTempFile("opt", "dex", this.context.getCacheDir()).getPath(),
0);
String className = "";
for(Enumeration<String> classNames = dexFile.entries(); classNames.hasMoreElements();
className = classNames.nextElement()) {
if(!className.isEmpty()) {
//Remove partial classes <class>$1..
if(className.contains("$"))
className = className.substring(0, className.indexOf("$"));
this.loadClass(className);
}
}
}
示例10: addDexFile
import dalvik.system.DexFile; //导入依赖的package包/类
/**
* Multi-dex is a thing. Does that literally mean multiple dex files? apks?
* I have no idea, but if so you can add more here.
* @param path The path to a dex file (usually an apk)
*/
public void addDexFile(String path)
{
mResolver = new NestedResolver();
try
{
DexFile df = new DexFile(path);
for (Enumeration<String> iter = df.entries(); iter.hasMoreElements(); )
{
addClass(iter.nextElement());
}
}
catch (Exception ex)
{
Log.e(TAG, "Failed to load or parse dex file. This is fatal.");
ex.printStackTrace();
}
mResolver.resolve(this);
mResolver = null;
}
示例11: install
import dalvik.system.DexFile; //导入依赖的package包/类
private static void install(ClassLoader loader, List<File> additionalClassPathEntries) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, IOException {
int extraSize = additionalClassPathEntries.size();
Field pathField = MultiDex.findField(loader, "path");
StringBuilder path = new StringBuilder((String) pathField.get(loader));
String[] extraPaths = new String[extraSize];
File[] extraFiles = new File[extraSize];
ZipFile[] extraZips = new ZipFile[extraSize];
DexFile[] extraDexs = new DexFile[extraSize];
ListIterator<File> iterator = additionalClassPathEntries.listIterator();
while (iterator.hasNext()) {
File additionalEntry = (File) iterator.next();
String entryPath = additionalEntry.getAbsolutePath();
path.append(':').append(entryPath);
int index = iterator.previousIndex();
extraPaths[index] = entryPath;
extraFiles[index] = additionalEntry;
extraZips[index] = new ZipFile(additionalEntry);
extraDexs[index] = DexFile.loadDex(entryPath, entryPath + ShareConstants.DEX_SUFFIX, 0);
}
pathField.set(loader, path.toString());
MultiDex.expandFieldArray(loader, "mPaths", extraPaths);
MultiDex.expandFieldArray(loader, "mFiles", extraFiles);
MultiDex.expandFieldArray(loader, "mZips", extraZips);
MultiDex.expandFieldArray(loader, "mDexs", extraDexs);
}
示例12: install
import dalvik.system.DexFile; //导入依赖的package包/类
private static void install(ClassLoader loader, List<File> additionalClassPathEntries,
File optimizedDirectory)
throws IllegalArgumentException, IllegalAccessException,
NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException {
Field pathListField = RocooUtils.findField(loader, "pathList");
Object dexPathList = pathListField.get(loader);
Field dexElement = RocooUtils.findField(dexPathList, "dexElements");
Class<?> elementType = dexElement.getType().getComponentType();
Method loadDex = RocooUtils.findMethod(dexPathList, "loadDexFile", File.class, File.class);
loadDex.setAccessible(true);
Object dex = loadDex.invoke(null, additionalClassPathEntries.get(0), optimizedDirectory);
Constructor<?> constructor = elementType.getConstructor(File.class, boolean.class, File.class, DexFile.class);
constructor.setAccessible(true);
Object element = constructor.newInstance(new File(""), false, additionalClassPathEntries.get(0), dex);
Object[] newEles = new Object[1];
newEles[0] = element;
RocooUtils.expandFieldArray(dexPathList, "dexElements", newEles);
}
示例13: install
import dalvik.system.DexFile; //导入依赖的package包/类
private static void install(ClassLoader loader, List<File> additionalClassPathEntries,
File optimizedDirectory)
throws IllegalArgumentException, IllegalAccessException,
NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, ClassNotFoundException {
Field pathListField = findField(loader, "pathList");
Object dexPathList = pathListField.get(loader);
Field dexElement = findField(dexPathList, "dexElements");
Class<?> elementType = dexElement.getType().getComponentType();
Method loadDex = findMethod(dexPathList, "loadDexFile", File.class, File.class, ClassLoader.class, dexElement.getType());
loadDex.setAccessible(true);
Object dex = loadDex.invoke(null, additionalClassPathEntries.get(0), optimizedDirectory, loader, dexElement.get(dexPathList));
Constructor<?> constructor = elementType.getConstructor(File.class, boolean.class, File.class, DexFile.class);
constructor.setAccessible(true);
Object element = constructor.newInstance(new File(""), false, additionalClassPathEntries.get(0), dex);
Object[] newEles = new Object[1];
newEles[0] = element;
expandFieldArray(dexPathList, "dexElements", newEles);
}
示例14: makeDexElement
import dalvik.system.DexFile; //导入依赖的package包/类
/**
* Make dex element
*
* @see <a
* href="https://android.googlesource.com/platform/libcore-snapshot/+/ics-mr1/dalvik/src/main/java/dalvik/system/DexPathList.java">DexPathList.java</a>
* @param pkg archive android package with any file extensions
* @param dexFile
* @return dalvik.system.DexPathList$Element
*/
private static Object makeDexElement(File pkg, DexFile dexFile) throws Exception {
if (sDexElementClass == null) {
sDexElementClass = Class.forName("dalvik.system.DexPathList$Element");
}
if (sDexElementConstructor == null) {
sDexElementConstructor = sDexElementClass.getConstructors()[0];
}
Class<?>[] types = sDexElementConstructor.getParameterTypes();
switch (types.length) {
case 3:
if (types[1].equals(ZipFile.class)) {
// Element(File apk, ZipFile zip, DexFile dex)
ZipFile zip = new ZipFile(pkg);
return sDexElementConstructor.newInstance(pkg, zip, dexFile);
} else {
// Element(File apk, File zip, DexFile dex)
return sDexElementConstructor.newInstance(pkg, pkg, dexFile);
}
case 4:
default:
// Element(File apk, boolean isDir, File zip, DexFile dex)
return sDexElementConstructor.newInstance(pkg, false, pkg, dexFile);
}
}
示例15: expandDexPathList
import dalvik.system.DexFile; //导入依赖的package包/类
public static boolean expandDexPathList(ClassLoader cl,
String[] dexPaths, DexFile[] dexFiles) {
try {
int N = dexPaths.length;
Object[] elements = new Object[N];
for (int i = 0; i < N; i++) {
String dexPath = dexPaths[i];
File pkg = new File(dexPath);
DexFile dexFile = dexFiles[i];
elements[i] = makeDexElement(pkg, dexFile);
}
fillDexPathList(cl, elements);
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}