本文整理汇总了Java中mirror.dalvik.system.VMRuntime类的典型用法代码示例。如果您正苦于以下问题:Java VMRuntime类的具体用法?Java VMRuntime怎么用?Java VMRuntime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VMRuntime类属于mirror.dalvik.system包,在下文中一共展示了VMRuntime类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: interpretDex2Oat
import mirror.dalvik.system.VMRuntime; //导入依赖的package包/类
/**
* Optimize the dex in interpret mode.
*
* @param dexFilePath dex file path
* @param oatFilePath oat file path
* @throws IOException
*/
public static void interpretDex2Oat(String dexFilePath, String oatFilePath) throws IOException {
final File oatFile = new File(oatFilePath);
if (!oatFile.exists()) {
oatFile.getParentFile().mkdirs();
}
final List<String> commandAndParams = new ArrayList<>();
commandAndParams.add("dex2oat");
// for 7.1.1, duplicate class fix
if (Build.VERSION.SDK_INT >= 24) {
commandAndParams.add("--runtime-arg");
commandAndParams.add("-classpath");
commandAndParams.add("--runtime-arg");
commandAndParams.add("&");
}
commandAndParams.add("--dex-file=" + dexFilePath);
commandAndParams.add("--oat-file=" + oatFilePath);
commandAndParams.add("--instruction-set=" + VMRuntime.getCurrentInstructionSet.call());
if (Build.VERSION.SDK_INT > 25) {
commandAndParams.add("--compiler-filter=quicken");
} else {
commandAndParams.add("--compiler-filter=interpret-only");
}
final ProcessBuilder pb = new ProcessBuilder(commandAndParams);
pb.redirectErrorStream(true);
final Process dex2oatProcess = pb.start();
StreamConsumer.consumeInputStream(dex2oatProcess.getInputStream());
StreamConsumer.consumeInputStream(dex2oatProcess.getErrorStream());
try {
final int ret = dex2oatProcess.waitFor();
if (ret != 0) {
throw new IOException("dex2oat works unsuccessfully, exit code: " + ret);
}
} catch (InterruptedException e) {
throw new IOException("dex2oat is interrupted, msg: " + e.getMessage(), e);
}
}