利用XposedBridge框架开发,对系统接口进行Hook。编译出的xposed模块,在系统启动加载时失败,报错误如下:
Loading modules from /data/app/com.alta.audiopolicyloader-1.apk
I/Xposed ( 58): Loading class com.alta.audiopolicyloader.AudioPolicyLoader
W/dalvikvm( 58): Class resolved by unexpected DEX: Lcom/alta/audiopolicyloader/AudioPolicyLoader;(0xadaf9900):0xa6923000 ref [Lde/robv/android/xposed/IXposedHookLoadPackage;] Lde/robv/android/xposed/IXposedHookLoadPackage;(0xada60f68):0xa6da3000
W/dalvikvm( 58): (Lcom/alta/audiopolicyloader/AudioPolicyLoader; had used a different Lde/robv/android/xposed/IXposedHookLoadPackage; during pre-verification)
I/dalvikvm( 58): Failed resolving Lcom/alta/audiopolicyloader/AudioPolicyLoader; interface 1356 'Lde/robv/android/xposed/IXposedHookLoadPackage;'
W/dalvikvm( 58): Link of class 'Lcom/alta/audiopolicyloader/AudioPolicyLoader;' failed
I/Xposed ( 58): java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
I/Xposed ( 58): at dalvik.system.DexFile.defineClassNative(Native Method)
I/Xposed ( 58): at dalvik.system.DexFile.defineClass(DexFile.java:222)
I/Xposed ( 58): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:215)
I/Xposed ( 58): at dalvik.system.DexPathList.findClass(DexPathList.java:322)
I/Xposed ( 58): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
I/Xposed ( 58): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
I/Xposed ( 58): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
I/Xposed ( 58): at de.robv.android.xposed.XposedBridge.loadModule(XposedBridge.java:421)
I/Xposed ( 58): at de.robv.android.xposed.XposedBridge.loadModules(XposedBridge.java:386)
I/Xposed ( 58): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:120)
I/Xposed ( 58): at dalvik.system.NativeStart.main(Native Method)
模块用Gradle进行编译的,build.gradle文件是手动编写的。
【问题原因】:本模块中编译以来的XposedBridge.jar包,在系统运行的时候已经加载,与本模块中打包进去的XposedBridge接口 发生冲突。
【解决方法】:修改build.gradle文件,将对XposedBridge.jar的依赖关系由compile改为provided,如下:
dependencies {
provided files('libs/XposedBridgeApi-54.jar')
compile 'com.android.support:appcompat-v7:19.1.0'
}
导致该问题发生的原因,也是自己疏忽了Xposed installer在加载时,已经将XposedBridge加载完毕。因此,基于该框架开发时,只需要编译时依赖,运行时不需要。
切记,gradle之所以提供compile和provided两种jar包依赖方式,原是有此类考量的。