DexClassLoader
DexClassLoader加载自己写的第三方jar包,例如金山毒霸需要加载ksremote.jar。
现在将DexClassLoader加载jar包成果分享一下。
1.新建Android工程,封装功能java类。
2.选中需要导出的文件夹,右键选中“Export”->"Java(Jar file)"导出jar文件。
3.使用dx工具将jar包转换为android 字节码。
命令:dx --dex --Output=xx.jar hello.jar
4.将dx工具处理的xx.jar拷贝到工程raw目录下。
5.在工程主Activity的onCreate函数中读取raw下的文件,并存储在当前应用目录。
我的例子代码:
InputStream inputStream = getResources().openRawResource(
R.raw.mtnbinder);
dexInternalStoragePath = new File(
getDir(APP_JAR, Context.MODE_PRIVATE), DEX_NAME);
if (!dexInternalStoragePath.exists()) {
try {
dexInternalStoragePath.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FileOutputStream fileOutputStream = new FileOutputStream(
dexInternalStoragePath);
CopyFile.copyFile(inputStream, fileOutputStream);
6.使用DexClassLoader调用jar包。
我的例子代码:
final File optimizedDexOutputPath = getDir(APP_JAR,
Context.MODE_PRIVATE);
try {
DexClassLoader classLoader = new DexClassLoader(
dexInternalStoragePath.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(), null,
getClassLoader());
// com.mtn.binder.HookIPhoneSubInfo
Class class1 = classLoader
.loadClass("com.mtn.binder.HookIPhoneSubInfo");
Method method = class1.getMethod("hook", new Class[] {});
method.invoke(class1, new Object[] {});
运行之后,就可以看到调用jar包成功。
DexClassLoader的更多相关文章
- [原创]Andorid DexClassLoader的创建过程解析(基于5.0)
做Android插件框架时,经常会用到dex的动态加载,就要直接或间接的使用DexClassLoader,在new DexClassLoader的时候Android系统做了很多工作,下面我们详细分析一 ...
- Android 使用DexClassLoader要执行其他apk方法
Android在apk文件dex文件是java编译出来.class次打包,当然在打包之前会利用自己的协议做一些数据处理,比如优化函数表和变量表.在java程序中是使用classloader来载入这些编 ...
- 类装载器DexClassLoader (android内核剖析)
在java环境中,有个概念叫做"类装载器",其作用是动态装载Class文件.标准的java SDK中有一个ClassLoader类,借助它可以装载 想要的Class文件,每个Cla ...
- Android类装载器DexClassLoader的简单使用-----制作android插件的前奏
声明:此篇文章借鉴<android内核剖析>整理得来. 一.装载器简介 “类装载器”(ClassLoader),顾名思义,就是用来动态装载class文件的.标准的Java SDK中有个Cl ...
- DexClassLoader和PathClassLoader
Android的ClassLoader体系 在Android中可以跟java一样实现动态加载jar,但是Android使用Dalvik VM,不能直接加载java打包jar的byte code,需要通 ...
- DexClassLoader和PathClassLoader载入Dex流程
0x00 在上一篇文章apk安装和优化原理,在最后我们分析了DexClassLoader和PathClassLoader的构造函数的不同. PathClassLoader最后调用的是new DexFi ...
- DexClassLoader和PathClassLoader类载入机制
0x00 在DexClassLoader和PathClassLoader载入Dex流程一文中,我们分析了dex文件怎样形成了DexFile结构体.本文中解说类载入机制,实际上就是生成ClassObje ...
- Android插件化(二):使用DexClassLoader动态载入assets中的apk
Android插件化(二):使用DexClassLoader动态载入assets中的apk 简单介绍 上一篇博客讲到.我们能够使用MultiDex.java载入离线的apk文件.须要注意的是,apk中 ...
- DexClassLoader动态加载分析
转载自:http://www.blogfshare.com/dexclassloader.html 看到原来有把原始的dex文件加密保存,然后解密后使用DexClassLoader加载文件的方法,就来 ...
随机推荐
- python标准库介绍——16 shutil模块详解
``shutil`` 实用模块包含了一些用于复制文件和文件夹的函数. [Example 2-4 #eg-2-4] 中使用的 ``copy`` 函数使用和 Unix 下 ``cp`` 命令基本相同的方式 ...
- 独立成分分析(Independent component analysis, ICA)
作者:桂. 时间:2017-05-22 12:12:43 链接:http://www.cnblogs.com/xingshansi/p/6884273.html 前言 今天群里冒出这样一个问题:群里谁 ...
- c++中带返回值函数没写return能通过编译但运行时会出现奇怪问题
c++中带返回值函数没写return能通过编译但运行时会出现奇怪问题 例如: string myFunc(){ theLogics(); } 发现调用: myFunc(); 崩溃. 但调用: cout ...
- How to set JAVA environment variables in Linux or CentOS
How to set JAVA environment variables JAVA_HOME and PATH in Linux After installing new java (jdk or ...
- Spring里的FactoryBean和BeanFactory有啥区别?
分别看这俩文章就知道了 Spring的FactoryBean使用 Spring加载xml配置文件的方式 ApplicationContext
- Maven pom.xml 报 Missing artifact jdk.tools:jdk.tools:jar:1.7
linux中用eclipse 新建maven project,pom.xml中报Missing artifact jdk.tools:jdk.tools:jar:1.7 解决方法: 在pom.xml中 ...
- linux 双显卡问题。。。
bumblebee的作用是禁用nvidia独立显卡,需要使用独显时,使用”optirun 程序名“手动开启nvidia来运行需要加速的程序,如optirun vmware. 打开N卡设置: optir ...
- 修改mysql root账户登录密码
打开mysql.exe(如果你配置了path的话,打开cmd即可)键入: mysqladmin -u root -p password [你的新密码][回车] 然后会要求你输入你当前的密码,就修改成功 ...
- 使用matplot做图--sin图像
# _*_ coding:utf-8 _*_ import numpy as np import matplotlib.pyplot as plt x = np.arange(-5, 5, 0.1) ...
- druid使用
https://blog.csdn.net/weinichendian/article/details/78503469