【问题标题】:Android studio many error: Could not find class 'android.XXX'Android工作室很多错误:找不到类'android.XXX'
【发布时间】:2016-10-26 04:19:24
【问题描述】:

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

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

谁能帮帮我?

【问题讨论】:

  • 谢谢你们,我再次禁用了 InstantRun 来解决这个问题,非常感谢你们的帮助。

标签: android android-studio linphone


【解决方案1】:

在阅读许多类似的问题时,我发现它可以通过启用 Multidex 来解决,感谢 this answer from Bharath Kumar。他还发布了一些我推荐阅读的有用链接。至少它对我有用(准确地说:我现在只剩下其中一个错误,而之前有数百个)!

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

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

当然,另一种选择是防止 64K 方法限制,因此您不再需要 MultiDex。您可以通过减少 Gradle 文件中(未使用的)依赖项的数量来做到这一点,或者使用更具体的依赖项(wittyurchin 在this answer 中提供了一个很好的 google play-services 示例)。

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

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

2) 如果您使用 Robolectric 进行单元测试,您可能无法再运行测试。您可以通过扩展之前的 MultiDex.install(this); 代码来解决此问题。与其自己解释一切,不如通过here检查问题和sschuberth的回答会更容易。

...

ps。看来我不一定需要compile 'com.android.support:multidex:1.0.1' 才能让 MultiDex 工作,但是,我看到很多建议说它是必需的。如果有人对此有更多建议,请成为我的客人!

【讨论】:

    【解决方案2】:

    我遇到了几乎相同的配置问题(和 Android API19-4.4 调试设备)。

    概述在我的案例中修复错误的步骤。 (基于建议here,缩小和proguard规则):

    1. 更新了 gradle 版本(只需在 File->settings->Build,Execution, Deployment->Build Tools->Gradle ::(RightPanel) Project-level settings ->Use default gradle wrapper 中设置默认选项)

      如果你必须使用特定版本的 gradle,你可以尝试跳过这一步

    2. 清理项目 + 重建项目(如果您也想重新启动 Android Studio,可能会这样做)
    3. 从模块(应用程序)中删除依赖项build.gradle -- 确保复制依赖项值以在下一步中恢复
    4. 同步/Gradle 构建,以获取错误(只是一个安全保护步骤,很有趣,但有时出于某种原因,即使配置发生更改,Android Studio 也是独立的)
    5. 按照步骤 3 中的说明在同一模块 (app) 中添加依赖项build.gradle `

      如果你想知道为什么步骤 3、4、5-> 有人指出 here 包含依赖项后的 gradle 更新可能会导致导致这些错误的问题`

    6. 最后也是最重要的:收缩代码并使用progaurd规则官方解释here

      由于我是 Android Studio 的新手,感觉我的项目虽然是一个非常小的应用程序,但可能会因包含多个实验性库 + 如此多的 cmets(以及内部的非活动代码)而导致 64K 膨胀? (nopeIguess),非法引用(可能!);在阅读@Pkuijpers 的答案后,只是一个直观的猜测(谢谢!)。老实说,我不想包含 multiDex,因为在阅读了官方文档之后,我确定我的应用程序不是 PokemonGo 或 NFS 或大到足以符合 multidex 的条件。

    为我解决了,唷!作为副产品,我还看到了 Android 资源监视器中更好的内存利用率!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2021-05-04
      • 2015-05-25
      • 2018-02-20
      • 2016-03-01
      • 1970-01-01
      相关资源
      最近更新 更多