无法将 Android 应用上传到设备(过时的 dexed jar)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25493310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:29:55  来源:igfitidea点击:

Can't upload Android app to device (stale dexed jars)

androidandroid-studio

提问by Guilherme

I am using Android Studio to develop this app, and today when I tried to upload it to my device to test I got a popup window saying:

我正在使用 Android Studio 开发这个应用程序,今天当我尝试将它上传到我的设备进行测试时,我收到一个弹出窗口,上面写着:

Installation failed since the device possibly has stale dexed jars that don't match the current version (dexopt error). In order to proceed, you have to uninstall the existing application.

WARNING: Uninstalling will remove the application data!

Do you want to uninstall the existing application?

安装失败,因为设备可能具有与当前版本不匹配的过时 dexed jar(dexopt 错误)。为了继续,您必须卸载现有的应用程序。

警告:卸载将删除应用程序数据!

您要卸载现有的应用程序吗?

It gave two options, OK or Cancel. Upon hitting OK, the following message showed up in the Run tab:

它提供了两个选项,确定或取消。点击“确定”后,“运行”选项卡中会显示以下消息:

DEVICE SHELL COMMAND: pm uninstall my.bundle.id
Unknown failure

DEVICE SHELL COMMAND: pm uninstall my.bundle.id
Unknown failure

The app seems to be uninstalled, the is no trace of it under Manage Applications.
I am unable to upload the app. I tried cleaning the project and rebuilding, but it didn't work.

该应用程序似乎已被卸载,在“管理应用程序”下没有任何痕迹。
我无法上传应用程序。我尝试清理项目并重建,但没有奏效。

What can I do?

我能做什么?

采纳答案by Guilherme

I discovered that the dex file was getting larger than the buffer, even though it contained less than 64k methods. Then I enabled ProGuard and it helped a lot reducing the dex file size.

我发现 dex 文件变得比缓冲区大,即使它包含的方法少于 64k。然后我启用了 ProGuard,它大大减少了 dex 文件的大小。

THe application dex-method-countshelps a lot to debug your dex file, by checking not only the number of methods, but to what package they belong

dex-method-counts应用程序对调试 dex 文件有很大帮助,不仅可以检查方法的数量,还可以检查它们属于哪个包

回答by Alexandru Pele

I have also encountered this problem in Android Studio, from version 2.0 Preview 6 all the way up to 2.0 Beta 3 and none of the solutions mentioned here worked for me.

我在 Android Studio 中也遇到过这个问题,从 2.0 Preview 6 一直到 2.0 Beta 3,这里提到的解决方案都不适合我。

Turned up it had nothing to do with Instant Run. All I had to do was to increase the AVD's Internal Storage until the following notification disappeared. I also had to perform a data wipe after changing the values.

结果发现它与 Instant Run 无关。我所要做的就是增加 AVD 的内部存储,直到以下通知消失。更改值后,我还必须执行数据擦除。

enter image description here

在此处输入图片说明

回答by dalizhang

I disabled Instant run for this project, and problem solved.

我为这个项目禁用了 Instant run,问题解决了。

Maybe it's a bug in the instant run feature of Android studio 2.0 preview.

可能是Android studio 2.0预览版即时运行功能的一个bug。

Instant Runis a new feature introduced in Android Studio 2.0.

Instant Run是 Android Studio 2.0 中引入的一项新功能。

ps: in case you don't find Instant run, its in:

ps:如果你没有找到 Instant run,它在:

Android Studio --> Preferences --> Build, execution, deploy --> Instant run.

or you can search for it in the preferences tab.

或者您可以在首选项选项卡中搜索它。

回答by Walter Torricos

Go to AVD Manager, then in the action section of your device select wipe data. This worked for me, hope it helps....

转到 AVD 管理器,然后在设备的操作部分选择擦除数据。这对我有用,希望它有帮助......

回答by Murat

This helped me for the emulator: Close Emulator. Tools > AVD Manager > Select Emulator Settings > Wipe Data > Cold Boot.. Now Install App.

这对我的模拟器有帮助:关闭模拟器。工具> AVD 管理器> 选择模拟器设置> 擦除数据> 冷启动.. 现在安装应用程序。

Reference

参考

回答by ghoulfolk

I found out my problem was caused by old SDK Build Tools version, which was causing the Clean to fail. I upgraded my SDK Build Tools to the newest version and after that cleaning worked, and I no longer received the stale dexed jars error. Hopefully this will help someone else struggling with this issue.

我发现我的问题是由旧的 SDK Build Tools 版本引起的,这导致 Clean 失败。我将我的 SDK 构建工具升级到最新版本,在清理工作之后,我不再收到陈旧的 dexed jars 错误。希望这会帮助其他人在这个问题上挣扎。

回答by Rene Juuse

This worked for me:

这对我有用:

In Android Studio this can be done by clicking on Build > Clean Project. SysadminTips

在 Android Studio 中,这可以通过单击Build > Clean Project来完成。系统管理员提示

回答by Anupriya

When your dex file gets larger then buffer size( i.e. contains more than 65k methods) then this error occurs. You can avoid this error in two ways: 1.) Remove unused code with ProGuard - Configure the ProGuard settings for your app to run ProGuard and ensure you have shrinking enabled for release builds. Enabling shrinking ensures you are not shipping unused code with your APKs.

当您的 dex 文件变得大于缓冲区大小(即包含超过 65k 个方法)时,就会发生此错误。您可以通过两种方式避免此错误:1.) 使用 ProGuard 删除未使用的代码 - 为您的应用配置 ProGuard 设置以运行 ProGuard,并确保您已为发布版本启用收缩。启用收缩可确保您的 APK 不会附带未使用的代码。

2.) You can configure your app for multidex support. Refer this link to use it: https://developer.android.com/tools/building/multidex.html

2.) 您可以配置您的应用程序以支持多索引。请参阅此链接以使用它:https: //developer.android.com/tools/building/multidex.html

For multidex support I override this method in my application class:

对于 multidex 支持,我在我的应用程序类中覆盖了这个方法:

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

and modify my build.gradle like this:

并像这样修改我的 build.gradle:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 21

             // Enabling multidex support.
             multiDexEnabled true
         }
}

dependencies {
    compile 'com.android.support:multidex:1.0.0'
}

Hope it helps!

希望能帮助到你!

EDITS: Took out the text explanation from the code.

编辑:从代码中取出文本解释。

回答by user3582891

In my project I got past this by being more specific about which portions of Google Play Services I was linking with. In particular, I changed

在我的项目中,我通过更具体地说明我正在链接的 Google Play 服务的哪些部分来解决这个问题。特别是,我改变了

dependencies {
    ...
    compile 'com.google.android.gms:play-services:8.4.0'
}

to

dependencies {
    ...
    compile 'com.google.android.gms:play-services-maps:8.4.0'
}

in my app module's build.gradle, since all I was really using was the maps API.

在我的应用程序模块的 build.gradle 中,因为我真正使用的是地图 API。

回答by Jorge Casariego

In my case was because my emulator was full of apps. I saw how much space the emulator had and was almost nothing so I deleted some apps and with this my problem was resolved

就我而言,是因为我的模拟器充满了应用程序。我看到模拟器有多少空间,几乎什么都没有,所以我删除了一些应用程序,这样我的问题就解决了