前天准备发包了,测试完毕,打好正式签名包,装到手机上,运行不起来。
网上查了大量资料,都没有解决方案。
log显示如下:
04-26 10:07:57.727 1538-1538/? I/MultiDex: VM with version 2.1.0 has multidex support
04-26 10:07:57.728 1538-1538/? I/MultiDex: install
04-26 10:07:57.728 1538-1538/? I/MultiDex: VM has multidex support, MultiDex support library is disabled.
04-26 10:07:57.771 1538-1553/? D/BitmapCache.initDiskCache(L:101): create disk cache success
04-26 10:07:57.850 1805-1844/? W/WindowAnimator: Failed to dispatch window animation state change.
android.os.DeadObjectException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.view.IWindow$Stub$Proxy.onAnimationStopped(IWindow.java:534)
at com.android.server.wm.WindowAnimator.updateWindowsLocked(WindowAnimator.java:289)
at com.android.server.wm.WindowAnimator.animateLocked(WindowAnimator.java:681)
at com.android.server.wm.WindowAnimator.access$000(WindowAnimator.java:53)
at com.android.server.wm.WindowAnimator$1.doFrame(WindowAnimator.java:123)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:672)
at android.view.Choreographer.doFrame(Choreographer.java:605)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:846)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.os.HandlerThread.run(HandlerThread.java:61)
at com.android.server.ServiceThread.run(ServiceThread.java:46)
04-26 10:07:57.851 1805-1844/? I/Timeline: Timeline: App_transition_ready time:823509261
04-26 10:07:57.856 1805-1844/? I/Timeline: Timeline: App_transition_ready time:823509265
04-26 10:07:57.889 1538-1538/? I/System.out: imid = null
04-26 10:07:57.992 1538-1538/? D/AndroidRuntime: Shutting down VM
后来调试发现,去掉混淆才可以运行,但是研究MultiDex发现跟混淆没有关系,而是只要获取java.vm.version的版本号是>=2.1就直接结束了安装。
private static final boolean IS_VM_MULTIDEX_CAPABLE = isVMMultidexCapable(System.getProperty("java.vm.version"));
public static void install(Context context)
{
Log.i("MultiDex", "install");
if (IS_VM_MULTIDEX_CAPABLE) {
Log.i("MultiDex", "VM has multidex support, MultiDex support library is disabled.");
return;
}
static boolean isVMMultidexCapable(String versionString)
{
boolean isMultidexCapable = false;
if (versionString != null) {
Matcher matcher = Pattern.compile("(\\d+)\\.(\\d+)(\\.\\d+)?").matcher(versionString);
if (matcher.matches()) {
try {
int major = Integer.parseInt(matcher.group(1));
int minor = Integer.parseInt(matcher.group(2));
isMultidexCapable = (major > 2) || ((major == 2) && (minor >= 1));
}
catch (NumberFormatException localNumberFormatException)
{
}
}
}
Log.i("MultiDex", new StringBuilder().append("VM with version ").append(versionString).append((isMultidexCapable) ? " has multidex support" : " does not have multidex support").toString());
return isMultidexCapable;
}
今天早上上班,打开studio ,提示需要升级Gradle版本到2.1.0(原来是2.0.0),然后升级以后,再打包测试了一下,一切又恢复正常了。
然后这个问题是跟Gradle的版本有关,至此这个问题算是解决了。