我正在使用android studio 2.1.2,调试设备android 4.4.2api19,build env:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
}

我已尝试重新打开项目、使缓存无效、禁用InstantRun,但仍会出现以下错误:
06-24 01:15:08.302 27320-27320/org.linphone E/InstantRun: Could not find slices in APK; aborting.
06-24 01:15:08.322 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.322 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.322 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.media.session.MediaController', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.322 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.widget.Toolbar', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.332 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.app.ActivityManager$TaskDescription', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.332 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.332 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.342 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.app.SharedElementCallback', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.342 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.app.assist.AssistContent', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.352 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.view.SearchEvent', referenced from method org.linphone.LinphoneLauncherActivity.access$super
06-24 01:15:08.352 27320-27320/org.linphone E/dalvikvm: Could not find class 'android.os.PersistableBundle', referenced from method org.linphone.LinphoneLauncherActivity.access$super

有人能帮我吗?

最佳答案

在阅读许多类似的问题时,我发现可以通过启用multidex,credits到this answer from Bharath Kumar来修复它。他还发布了一些有用的链接,我建议阅读。至少它对我有用(准确地说:我现在只剩下其中的一个错误,而它以前是几百个)!
简而言之:启用multidex只需在gradle defaultconfig中添加multiDexEnabled true,并添加这个依赖项compile 'com.android.support:multidex:1.0.1'
最后,通过将这段代码添加到应用程序类中来安装multidex:

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

当然,另一个选择是防止64K方法限制,这样就不再需要多索引了。您可以通过减少gradle文件中(未使用的)依赖项的数量,或者使用更具体的依赖项(wittyurchin在this answer中提供了一个很好的google play服务示例)。
但是,如果您确实需要多索引,则可能会遇到一些问题,如我发现的问题:
1)在构建目标API设备时,Instant Run被禁用(从Android Studio运行应用程序时,您将看到弹出的错误消息)。
2)如果使用Robolectric进行单元测试,则可能无法再运行测试。您可以通过扩展前面的MultiDex.install(this);代码来解决这个问题。与其自己解释一切,不如更容易检查问题,并通过here回答sschuberth。

另外,似乎我不一定需要compile 'com.android.support:multidex:1.0.1'来让多索引工作,但是,我已经看到很多回复说这是必需的。如果有人对此有更多的建议,请做我的客人!

10-05 21:01
查看更多