rovo89 / XposedBridge

The Java part of the Xposed framework.
3.91k stars 1.1k forks source link

Creating xposed module result to java.lang.NullPointerException: src == null Error #94

Closed wejdan closed 8 years ago

wejdan commented 8 years ago

I have decided to learn to write modules for xposed framework. I have written this code


package de.robv.android.xposed.mods.mainPK;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class main implements IXposedHookLoadPackage {
    public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable {
        XposedBridge.log("TestMod: " + lpparam.packageName);
    }
}

However the code dose not work and when I look into the logcat I see this error

E/Xposed  (  606): java.lang.NullPointerException: src == null
E/Xposed  (  606):  at java.lang.System.arraycopy(System.java:192)
E/Xposed  (  606):  at java.lang.String._getChars(String.java:825)
E/Xposed  (  606):  at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:148)
E/Xposed  (  606):  at java.lang.StringBuilder.append(StringBuilder.java:216)
E/Xposed  (  606):  at de.robv.android.xposed.mods.mainPK.main.handleLoadPackage(main.java:9)
E/Xposed  (  606):  at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:34)
E/Xposed  (  606):  at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:61)
E/Xposed  (  606):  at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:106)
E/Xposed  (  606):  at de.robv.android.xposed.XposedBridge$4.afterHookedMethod(XposedBridge.java:285)
E/Xposed  (  606):  at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:752)
E/Xposed  (  606):  at android.app.LoadedApk.<init>(<Xposed>)
E/Xposed  (  606):  at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1795)
E/Xposed  (  606):  at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1757)
E/Xposed  (  606):  at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1729)
E/Xposed  (  606):  at android.app.ContextImpl.createPackageContextAsUser(ContextImpl.java:2204)
E/Xposed  (  606):  at android.app.ContextImpl.createPackageContext(ContextImpl.java:2185)
E/Xposed  (  606):  at android.content.ContextWrapper.createPackageContext(ContextWrapper.java:677)
E/Xposed  (  606):  at android.app.ActivityThread.installProvider(ActivityThread.java:5012)
E/Xposed  (  606):  at android.app.ActivityThread.installContentProviders(ActivityThread.java:4634)
E/Xposed  (  606):  at android.app.ActivityThread.installSystemProviders(ActivityThread.java:5220)
E/Xposed  (  606):  at com.android.server.am.ActivityManagerService.installSystemProviders(ActivityManagerService.java:10016)
E/Xposed  (  606):  at com.android.server.SystemServer.startOtherServices(SystemServer.java:492)
E/Xposed  (  606):  at com.android.server.SystemServer.run(SystemServer.java:285)
E/Xposed  (  606):  at com.android.server.SystemServer.main(SystemServer.java:186)
E/Xposed  (  606):  at java.lang.reflect.Method.invoke(Native Method)
E/Xposed  (  606):  at java.lang.reflect.Method.invoke(Method.java:372)
E/Xposed  (  606):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
E/Xposed  (  606):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
E/Xposed  (  606):  at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:134)

I use cyanogenmod 12.1

rovo89 commented 8 years ago

According to the crash log, you call StringBuilder.append(), but I don't see that in your code. Are you sure you compiled and test exactly the code you posted above?

wejdan commented 8 years ago

yes I am sure

rovo89 commented 8 years ago

OK, then please upload the APK and I'll have a look.

wejdan commented 8 years ago

TestMod.zip

rovo89 commented 8 years ago

It seems that the problem is that you have compiled the Xposed API into your APK instead of just referencing it. I don't know that this would have such effects, but it's definitely the wrong way. Please follow these instructions closely to avoid that: https://github.com/rovo89/XposedBridge/wiki/Using-the-Xposed-Framework-API

Apart from that, please don't place your classes in de.robv.... but use your own namespace.

DVDAndroid commented 8 years ago

@wejdan Try to set Gradle version to 1.3.0

rovo89 commented 8 years ago

Well, I had actually decompiled the APK, removed the Xposed API classes and compiled it again. Then it started to work... Unless apktool/smali/baksmali produce "better" dex files, I still think that this is the issue.

rovo89 commented 8 years ago

The issue here seems to have been that the Xposed API has been compiled into the APK. Since Xposed v84, there's a warning about this, and future versions of Xposed will prevent such a module from being loaded at all.