Android(安卓)Studio创建Xposed Module项目的正确姿势。
Android Studio创建Xposed Module的正确姿势。
创建步骤:
1.创建一个没有activity的工程。
2.修改AndroidMenifest.xml。
<?xml version="1.0" encoding="utf-8"?>
增加和xposed组件有关的三个参数,xposedmodule(必须设置未true),
xposedminversion xposed要求的最低版本,
xposeddescription 模块描述,显示在如下图所示。
3.配置XposedBridgeApi.jar
XposedBridgeApi.jar是编译Module所需要的,运行不需要啊不需要,这块一定要注意。估计是Xposed App里已经集成了这个jar包。
如果选择compile,就会报下面的错误。
错误内容是:
“IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation”
官方文档的说法是:
Make sure that the API classes are not included (but only referenced) in your compiled APK, otherwise you will get an IllegalAccessError.
下载地址:http://forum.xda-developers.com/xposed/xposed-api-changelog-developer-news-t2714067
下载XposedBridgeApi-54.jar,在app里新建lib文件夹,放进去(不放在libs文件夹里官方也有解释,Files in the libs (with “s”) folder are automatically included by Eclipse, so don’t put the API file there.)。
在Android Studio选择“Project”视图,在jar包上右键“Add As Library”。
之后关键的一步来了。打开“Project Structure”,在“Dependencies”,把XposedBridgeApi.jar设置成“provided”
修改完之后的打开build.gradle检查一下:
dependencies {compile fileTree(dir: 'libs', include: ['*.jar'])compile 'junit:junit:4.12'compile 'com.android.support:appcompat-v7:23.1.1'provided files('lib/XposedBridgeApi-54.jar')}
4.在app/src的main文件夹里创建模块接口。
第4步和第5步一定要在main文件夹内,否则会出现ClassNotFound的错误。
模块接口内容:
public class Tutorial implements IXposedHookLoadPackage {public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable { XposedBridge.log("Loaded app: " + lpparam.packageName);}}
代码很简单,就是把所有启动过的包名打印出来。
XposedBridge.log 是Xposed的log模块接口,log输出到/data/data/de.robv.android.xposed.installer/log/debug.log里。
5.在app/src的main文件夹里创建assets文件夹,新建xposed_init文件,文件里加上xposed模块的入口类
com.maosheng.xtestmodule.Tutorial
6.编译安装。在App的模块里就能看到编写的模块了,勾选打开。
7.Xposed的log Tag是“Xposed”,在logcat可以看到。
Loading Xposed (for Zygote)...Loading modules from /data/app/ de.robv.android.xposed.mods.tutorial-1.apkLoading class com.maosheng.xtestmodule.TutorialLoaded app: com.android.systemuiLoaded app: com.android.settings
参考资料:
官方教程:https://github.com/rovo89/XposedBridge/wiki/Development-tutorial
官网:http://repo.xposed.info/module/de.robv.android.xposed.installer
apk:http://dl-xda.xposed.info/modules/de.robv.android.xposed.installer_v33_36570c.apk
源码:https://github.com/rovo89/XposedInstaller
更多相关文章
- Android多线程(二)消息处理机制---Handler、Message、Looper源码原
- Android应用自动化测试-提纲
- android自定义dialog弹出框、透明背景
- 发现3 .js与Android和英特尔XDK
- (转)Unable to get view server version from device emulator-5
- 【Android(安卓)Training UI】创建自定义Views(Lesson 2 - 自定
- Android: Project ... is missing required source folder: 'gen
- android sdcard的使用
- Android(安卓)29 创建文件夹失败