当前位置: 首页>>代码示例>>Java>>正文


Java BaseDexClassLoader类代码示例

本文整理汇总了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);
  }
}
 
开发者ID:facebook,项目名称:SoLoader,代码行数:20,代码来源:SoLoader.java

示例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");
       }
   }
 
开发者ID:opensensorhub,项目名称:osh-android,代码行数:36,代码来源:Dexter.java

示例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);
}
 
开发者ID:opensensorhub,项目名称:osh-android,代码行数:10,代码来源:Dexter.java

示例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;
}
 
开发者ID:opensensorhub,项目名称:osh-android,代码行数:11,代码来源:Dexter.java

示例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");
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:6,代码来源:SystemClassLoaderAdder.java

示例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");
}
 
开发者ID:facebook,项目名称:buck,代码行数:6,代码来源:SystemClassLoaderAdder.java


注:本文中的dalvik.system.BaseDexClassLoader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。