ximsfei / Android-skin-support

Android-skin-support is an easy dynamic skin framework to use for Android, Only one line of code to integrate it. Android 换肤框架, 极低的学习成本, 极好的用户体验. "一行"代码就可以实现换肤, 你值得拥有!!!
MIT License
6.42k stars 1.08k forks source link

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String u.a.h.c.d()' on a null object reference #421

Open jhwsx opened 4 years ago

jhwsx commented 4 years ago

大神,这个报错能帮忙看一下吗?

Process Name: 'com.abc'
Thread Name: 'main'
Back traces starts.
java.lang.ExceptionInInitializerError
    at skin.support.content.res.SkinCompatUserThemeManager.get(SkinCompatUserThemeManager.java:124)
    at skin.support.content.res.SkinCompatResources.getSkinColor(SkinCompatResources.java:129)
    at skin.support.content.res.SkinCompatResources.getColor(SkinCompatResources.java:233)
    at com.abc.base.BaseAppCompatActivity.j0(BaseAppCompatActivity.java:3)
    at com.abc.base.BaseAppCompatActivity.onCreate(BaseAppCompatActivity.java:6)
    at com.abc.ui.call.AnswerCallActivity.onCreate(AnswerCallActivity.java)
    at android.app.Activity.performCreate(Activity.java:7142)
    at android.app.Activity.performCreate(Activity.java:7133)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1219)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2999)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3124)
    at android.app.ActivityThread.-wrap11(ActivityThread.java:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:192)
    at android.app.ActivityThread.main(ActivityThread.java:6890)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:875)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String u.a.h.c.d()' on a null object reference
    at skin.support.content.res.SkinCompatUserThemeManager.startLoadFromSharedPreferences(SkinCompatUserThemeManager.java:64)
    at skin.support.content.res.SkinCompatUserThemeManager.<init>(SkinCompatUserThemeManager.java:53)
    at skin.support.content.res.SkinCompatUserThemeManager.<clinit>(SkinCompatUserThemeManager.java:39)
    ... 19 more
Back traces ends.

在 mapping.txt 中,没有找到 'java.lang.String u.a.h.c.d() 对应的代码。 使用的版本是 4.0.5

ximsfei commented 4 years ago

反编译apk,看下这个java.lang.String u.a.h.c.d()是啥呢

jhwsx commented 4 years ago

定位到是在这里, QQ图片20201118105934 对应的源码是在,

public class SkinPreference {
    private static final String FILE_NAME = "meta-data";

    private static final String KEY_SKIN_NAME = "skin-name";
    private static final String KEY_SKIN_STRATEGY = "skin-strategy";
    private static final String KEY_SKIN_USER_THEME = "skin-user-theme-json";
    private static SkinPreference sInstance;
    private final Context mApp;
    private final SharedPreferences mPref;
    private final SharedPreferences.Editor mEditor;

    public static void init(Context context) {
        if (sInstance == null) {
            synchronized (SkinPreference.class) {
                if (sInstance == null) {
                    sInstance = new SkinPreference(context.getApplicationContext());
                }
            }
        }
    }

    public static SkinPreference getInstance() {
        return sInstance;
    }

    private SkinPreference(Context applicationContext) {
        mApp = applicationContext;
        mPref = mApp.getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
        mEditor = mPref.edit();
    }

    public SkinPreference setSkinName(String skinName) {
        mEditor.putString(KEY_SKIN_NAME, skinName);
        return this;
    }

    public String getSkinName() {
        return mPref.getString(KEY_SKIN_NAME, "");
    }

    public SkinPreference setSkinStrategy(int strategy) {
        mEditor.putInt(KEY_SKIN_STRATEGY, strategy);
        return this;
    }

    public int getSkinStrategy() {
        return mPref.getInt(KEY_SKIN_STRATEGY, SkinCompatManager.SKIN_LOADER_STRATEGY_NONE);
    }

    public SkinPreference setUserTheme(String themeJson) {
        mEditor.putString(KEY_SKIN_USER_THEME, themeJson);
        return this;
    }

    public String getUserTheme() {
        return mPref.getString(KEY_SKIN_USER_THEME, "");
    }

    public void commitEditor() {
        mEditor.apply();
    }
}

推测是由于某种原因 SkinPreference 没有完成初始化。另外说一下我们的场景,我们这个页面是从后台弹出的,是替换来电的页面,不知道跟这个有没有关系。

84% 集中的设备是 vivo 8.1.0。

现在的对策是:自己再调用一下 SkinPreference.init(this);,等线上之后看一下效果。