Skip to content

Commit b658362

Browse files
committed
[tinker] FIX: classloader in base context was not replaced.
1 parent 145d80e commit b658362

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tinker-android/tinker-android-loader/src/main/java/com/tencent/tinker/loader/NewClassLoaderInjector.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ private static void doInject(Application app, ClassLoader classLoader) throws Th
119119
Thread.currentThread().setContextClassLoader(classLoader);
120120

121121
final Context baseContext = (Context) findField(app.getClass(), "mBase").get(app);
122+
try {
123+
findField(baseContext.getClass(), "mClassLoader").set(baseContext, classLoader);
124+
} catch (Throwable ignored) {
125+
// There's no mClassLoader field in ContextImpl before Android O.
126+
// However we should try our best to replace this field in case some
127+
// customized system has one.
128+
}
129+
122130
final Object basePackageInfo = findField(baseContext.getClass(), "mPackageInfo").get(baseContext);
123131
findField(basePackageInfo.getClass(), "mClassLoader").set(basePackageInfo, classLoader);
124132

0 commit comments

Comments
 (0)