Android Studio许多错误:找不到类"android.XXX" [英] Android studio many error: Could not find class 'android.XXX'

查看:180
本文介绍了Android Studio许多错误:找不到类"android.XXX"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android Studio 2.1.2,调试设备android 4.4.2 API19,构建环境:

I'm using Android Studio 2.1.2, debug device android 4.4.2 API19, build env:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
}

我已经尝试过重新打开项目,使缓存无效,禁用InstantRun ,但是我仍然不断收到以下错误消息:

I have tried reopen the project, invalidate caches, disable instantRun, but I still keep getting those error as below:

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来解决此问题,这要归功于

While reading through many similar problems, I found out it might be fixed by enabling Multidex, credits to this answer from Bharath Kumar. He also posted some useful links I reccomend to read. At least it worked for me (to be precise: I'm left with only 1 of those errors now, while it were hundreds before)!

简而言之:只需在 gradle defaultConfig 中添加multiDexEnabled true并添加此依赖项compile 'com.android.support:multidex:1.0.1',即可启用multidex. 最后,通过将以下代码添加到Application类中来安装Multidex:

In short: enabling multidex can be done by simply adding multiDexEnabled true in your gradle defaultConfig and adding this dependency compile 'com.android.support:multidex:1.0.1'. Finally, install Multidex by adding this piece of code to your Application class:

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

当然,另一个选择是防止64K方法限制,因此您不再需要MultiDex.您可以通过减少Gradle文件中(未使用的)依赖项的数量来做到这一点,或者使用更具体的依赖项(wittyurchin在

Of course another option is to prevent the 64K method limit, so you don't need MultiDex anymore. You can do this by decreasing the number of (unused) dependencies in your Gradle file, or use more specific dependencies (a nice example for google play-services is provided by wittyurchin in this answer).

但是,如果您确实需要Multidex,那么您可能会遇到一些问题,例如我发现的问题:

1)在构建到目标API设备时,即时运行被禁用(从Android Studio运行应用时,您会看到错误消息弹出).

1) Instant run is disabled while building to target API devices (you'll see the error message popping up when running your app from Android Studio).

2)如果您使用Robolectric进行单元测试,则可能将无法再运行测试.您可以通过扩展MultiDex.install(this);代码来解决此问题.与其亲自解释所有内容,不如检查问题并通过

2) If you're using Robolectric for unittesting, you'll probably won't be able to run the tests anymore. You can fix this problem by extending the MultiDex.install(this); code from earlier. Instead of explaining everything myself, it'll be easier to check the issue, and answer of sschuberth over here.

...

ps.似乎不一定需要compile 'com.android.support:multidex:1.0.1'来运行MultiDex,但是,我看到许多建议说它是必需的.如果有人对此有更多建议,请成为我的客人!

ps. it seems I don't necessarily need compile 'com.android.support:multidex:1.0.1' to have MultiDex working, however, I've seen many reccomendations that say it IS required. If anyone got more advice on this, be my guest!

这篇关于Android Studio许多错误:找不到类"android.XXX"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆