use of dalvik.system.DexFile in project Headline by kb18519142009.
the class BaseApplication method getAllActivities.
/**
* 初始化 路由表
*/
private void getAllActivities() {
try {
DexFile dexFile = new DexFile(this.getPackageResourcePath());
Enumeration entries = dexFile.entries();
while (entries.hasMoreElements()) {
String entryName = (String) entries.nextElement();
// 开始匹配Activity
if (entryName.contains("activity") && entryName.contains("Activity")) {
// 通过反射获得Activity类
Class entryClass = Class.forName(entryName);
if (entryClass.isAnnotationPresent(Action.class)) {
Action action = (Action) entryClass.getAnnotation(Action.class);
this.mapping.put(action.value(), entryClass);
}
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
use of dalvik.system.DexFile in project flyway by flyway.
the class AndroidScanner method scanForClasses.
public Class<?>[] scanForClasses(Location location, Class<?> implementedInterface) throws Exception {
String pkg = location.getPath().replace("/", ".");
List<Class> classes = new ArrayList<Class>();
DexFile dex = new DexFile(context.getApplicationInfo().sourceDir);
Enumeration<String> entries = dex.entries();
while (entries.hasMoreElements()) {
String className = entries.nextElement();
if (className.startsWith(pkg)) {
Class<?> clazz = classLoader.loadClass(className);
if (Modifier.isAbstract(clazz.getModifiers())) {
LOG.debug("Skipping abstract class: " + className);
continue;
}
if (!implementedInterface.isAssignableFrom(clazz)) {
continue;
}
try {
ClassUtils.instantiate(className, classLoader);
} catch (Exception e) {
throw new FlywayException("Unable to instantiate class: " + className);
}
classes.add(clazz);
LOG.debug("Found class: " + className);
}
}
return classes.toArray(new Class<?>[classes.size()]);
}
use of dalvik.system.DexFile in project cucumber-jvm by cucumber.
the class DexClassFinderTest method beforeEachTest.
@Before
public void beforeEachTest() throws IOException {
dexFile = new DexFile("notImportant");
dexClassFinder = new DexClassFinder(dexFile);
}
use of dalvik.system.DexFile in project atlas by alibaba.
the class BundleArchiveRevision method findClass.
Class<?> findClass(String className, ClassLoader cl) throws ClassNotFoundException {
try {
Class<?> clazz = null;
if (AtlasHacks.LexFile != null && AtlasHacks.LexFile.getmClass() != null) {
if (dexClassLoader == null) {
File libDir = new File(RuntimeVariables.androidApplication.getFilesDir().getParentFile(), "lib");
dexClassLoader = new DexClassLoader(bundleFile.getAbsolutePath(), revisionDir.getAbsolutePath(), libDir.getAbsolutePath(), cl) {
@Override
public String findLibrary(String name) {
String path = super.findLibrary(name);
if (TextUtils.isEmpty(path)) {
String fileName = System.mapLibraryName(name);
File soFile = findSoLibrary(fileName);
if (soFile != null && soFile.exists()) {
return soFile.getAbsolutePath();
}
try {
return (String) AtlasHacks.ClassLoader_findLibrary.invoke(Framework.getSystemClassLoader(), name);
} catch (Exception e) {
e.printStackTrace();
}
return null;
} else {
return path;
}
}
};
}
clazz = (Class<?>) AtlasHacks.DexClassLoader_findClass.invoke(dexClassLoader, className);
return clazz;
}
if (isDexOpted() == false) {
optDexFile();
}
if (dexFile == null) {
// loadDex(new File(revisionDir, BUNDLE_ODEX_FILE));
optDexFile();
}
clazz = dexFile.loadClass(className, cl);
return clazz;
} catch (IllegalArgumentException e) {
} catch (InvocationTargetException e) {
} catch (Exception e) {
if (e instanceof ClassNotFoundException) {
//do nothing
} else if (e instanceof DexLoadException) {
throw (DexLoadException) e;
} else {
Log.e("Framework", "Exception while find class in archive revision: " + bundleFile.getAbsolutePath(), e);
}
}
return null;
}
use of dalvik.system.DexFile in project atlas by alibaba.
the class BundleArchiveRevision method optDexFile.
public synchronized void optDexFile() {
if (isDexOpted()) {
return;
}
if (AtlasHacks.LexFile != null && AtlasHacks.LexFile.getmClass() != null) {
//yunos
// TODO: need also cover logic of filelocks for YunOS.
new DexClassLoader(bundleFile.getAbsolutePath(), revisionDir.getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
isDexOptDone = true;
return;
}
File odexFile = new File(revisionDir, BUNDLE_ODEX_FILE);
long START = 0;
START = System.currentTimeMillis();
try {
if (AtlasFileLock.getInstance().LockExclusive(odexFile) == false) {
Log.e("Framework", "Failed to get file lock for " + bundleFile.getAbsolutePath());
}
if (dexFile == null) {
dexFile = com.taobao.android.runtime.RuntimeUtils.loadDex(RuntimeVariables.androidApplication, bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0);
// dexFile = DexFile.loadDex(bundleFile.getAbsolutePath(), odexFile.getAbsolutePath(), 0);
}
//9月份版本明天发布先不集成
// isDexOptDone = checkDexValid(dexFile);
isDexOptDone = true;
} catch (IOException e) {
AtlasMonitor.getInstance().trace(AtlasMonitor.DEXOPT_FAIL, location, AtlasMonitor.DEXOPT_FAIL_MSG, FileUtils.getDataAvailableSpace());
if (odexFile.exists()) {
odexFile.delete();
}
Log.e("Framework", "Failed optDexFile '" + bundleFile.getAbsolutePath() + "' >>> ", e);
} finally {
AtlasFileLock.getInstance().unLock(odexFile);
}
Log.e("Framework", "bundle archieve dexopt bundle " + bundleFile.getAbsolutePath() + " cost time = " + (System.currentTimeMillis() - START) + " ms");
return;
}
Aggregations