Android Studio创建Xposed Module的正确姿势。

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/mosenyang/article/details/50907036

Android Studio创建Xposed Module的正确姿势。

创建步骤:

1.创建一个没有activity的工程。

2.修改AndroidMenifest.xml。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.robv.android.xposed.mods.tutorial"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="15" />
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <meta-data
        android:name="xposedmodule"
        android:value="true" />
    <meta-data
        android:name="xposeddescription"
        android:value="Easy example of maosheng" />
    <meta-data
        android:name="xposedminversion"
        android:value="30" />
</application>
</manifest>

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

增加和xposed组件有关的三个参数,xposedmodule(必须设置未true),
xposedminversion xposed要求的最低版本,
xposeddescription 模块描述,显示在如下图所示。
xposed desc

3.配置XposedBridgeApi.jar

XposedBridgeApi.jar是编译Module所需要的,运行不需要啊不需要,这块一定要注意。估计是Xposed App里已经集成了这个jar包。
如果选择compile,就会报下面的错误。

错误内容是:

“IllegalAccessError: Class ref in pre-verified class resolved to unexpected  implementation” 

 
 
  • 1

官方文档的说法是:

Make sure that the API classes are not included (but only referenced) in your compiled APK, otherwise you will get an IllegalAccessError.

 
 
  • 1

下载地址: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')
}

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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);
}
}

 
 
  • 1
  • 2
  • 3
  • 4
  • 5

代码很简单,就是把所有启动过的包名打印出来。

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

 
 
  • 1

6.编译安装。在App的模块里就能看到编写的模块了,勾选打开。
xposed desc

7.Xposed的log Tag是“Xposed”,在logcat可以看到。

Loading Xposed (for Zygote)...
Loading modules from /data/app/ de.robv.android.xposed.mods.tutorial-1.apk
Loading class com.maosheng.xtestmodule.Tutorial
Loaded app: com.android.systemui
Loaded app: com.android.settings

 
 
  • 1
  • 2
  • 3
  • 4
  • 5

参考资料:

官方教程: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值