Closed zhangbaogithub closed 5 years ago
验证了一下,好像是so文件的问题,我换成atlas-demo中的远程bundle so文件之后就没有这个问题。想请问一下,这个问题怎么排查?
bundle中的 DemoApplication 不是真正的application。 不要拿这个DemoApplication的context去做任何实际的动作。 代码51行自己查下。
没有调用DemoApplication的context,只是在AndroidManifest里面注册了一下,这是整个DemoApplication的代码
public class DemoApplication extends Application { @Override public void onCreate() { super.onCreate(); Atlas.getInstance().setClassNotFoundInterceptorCallback(new ClassNotFoundInterceptorCallback() { @Override public Intent returnIntent(Intent intent) { final String className = intent.getComponent().getClassName(); final String bundleName = AtlasBundleInfoManager.instance().getBundleForComponet(className);
if (!TextUtils.isEmpty(bundleName) && !AtlasBundleInfoManager.instance().isInternalBundle(bundleName)) {
//远程bundle
Activity activity = ActivityTaskMgr.getInstance().peekTopActivity();
File remoteBundleFile = new File(activity.getExternalCacheDir(), "lib" + bundleName.replace(".", "_") + ".so");
String path = "";
if (remoteBundleFile.exists()) {
path = remoteBundleFile.getAbsolutePath();
} else {
Toast.makeText(activity, " 远程bundle不存在,请确定 : " + remoteBundleFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
return intent;
}
PackageInfo info = activity.getPackageManager().getPackageArchiveInfo(path, 0);
try {
Atlas.getInstance().installBundle(info.packageName, new File(path));
} catch (BundleException e) {
Toast.makeText(activity, " 远程bundle 安装失败," + e.getMessage(), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
activity.startActivities(new Intent[]{intent});
}
return intent;
}
});
}
}
调试一下吧。 看起来是peekTopActivity 返回空了。 demo的代码写得不够严谨。 ActivityTaskMgr里面是弱持有activity的。
peekTopActivity不为空,并且activity.getPackageManager()这里也不为空,就是activity.getPackageManager().getPackageArchiveInfo(path, 0)执行这个的时候会返回空
PackageInfo info = activity.getPackageManager().getPackageArchiveInfo(path, 0); 执行这个方法得到的info为null,下面是报错信息: java.lang.NullPointerException: Attempt to read from field 'java.lang.String android.content.pm.PackageInfo.packageName' on a null object reference at com.sdk.sh.atlastestdemo.DemoApplication$1.returnIntent(DemoApplication.java:51) at android.taobao.atlas.runtime.InstrumentationHook.fallBackToClassNotFoundCallback(InstrumentationHook.java:459) at android.taobao.atlas.runtime.InstrumentationHook.execStartActivityInternal(InstrumentationHook.java:417) at android.taobao.atlas.runtime.InstrumentationHook.execStartActivity(InstrumentationHook.java:297) at android.app.Activity.startActivityForResult(Activity.java:4391) at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:67) at android.app.Activity.startActivityForResult(Activity.java:4335) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:720) at android.app.Activity.startActivity(Activity.java:4697) at android.app.Activity.startActivity(Activity.java:4665) at com.sdk.sh.atlastestdemo.MainActivity$onCreate$1.onClick(MainActivity.kt:17) at android.view.View.performClick(View.java:5646) at android.view.View$PerformClick.run(View.java:22459) at android.os.Handler.handleCallback(Handler.java:761) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6531) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)