错误日志1:
Using WebView from more than one process at once with the same data directory is not supported
项目中开启了两个进程:
com.xxx.app.test 和 com.xxx.app.test.pushcore
错误原因:
Android P行为变更,不可多进程使用同一个目录webView,需要为不同进程webView设置不同目录
解决办法:
Android 9 prohibit sharing WebView data directory among multiple processes
add below code in your mainApplication file
public void onCreate() {
...
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
String processName = getProcessName(this);
String packageName = this.getPackageName();
if (!packageName.equals(processName)) {
WebView.setDataDirectorySuffix(processName);
}
}
}
private String getProcessName(Context context) {
if (context == null) return null;
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (processInfo.pid == android.os.Process.myPid()) {
return processInfo.processName;
}
}
return null;
}
错误日志2:Failed to load WebView provider: No WebView installed
public class MyWebView extends WebView {
@Override
public void setOverScrollMode(int mode) {
try {
super.setOverScrollMode(mode);
} catch (Exception e) {
if (e.getMessage() != null && e.getMessage().contains("Failed to load WebView provider: No WebView installed")) {
e.printStackTrace();
} else {
throw e;
}
}
}
}
本文详细阐述了在Android P及以上版本中,由于行为变更导致的WebView在同一数据目录下被多个进程使用的限制,并提供了在com.xxx.app.test和com.xxx.app.test.pushcore进程中解决此问题的方法,包括创建进程专属的数据目录和相关代码示例。
6007

被折叠的 条评论
为什么被折叠?



