IOException: Failed to find byte code when upgrade to Android Studio 3.1

爱⌒轻易说出口 提交于 2019-11-30 07:52:34

There is an issue, which they promise to fix in 3.2. Until then you probably have to roll back to Android Studio 3.0 if you don't want to turn off instant run. Why they don't want to release a hotfix for this, I don't know. Seems to be a pretty important bug.

See:

I suggest voting for the issue, maybe this will motivate them to release the fix sooner.

Just as @Malcolm said, this is an Android Studio 3.1 issue.

If you don't want to revert Android Studio 3.1 to 3.0, you can disable Instant Run.

If you don't want to revert Android Studio 3.1 to 3.0, and do need Instant Run, you can edit build.gradle and gradle-wrapper.properties like below:

  1. com.android.tools.build:gradle:3.1.0

    -> com.android.tools.build:gradle:3.0.1

  2. distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip

    -> distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip

Disabling Instant Run worked for me

if you get unexpected/weird/stupid errors like this it's most probably because of

Instant run

disable it and try again

Firstly go to build menu and clean project. After cleaning rebuild the project.

If doesn't work then, Try to add this line in build gradle file:

 defaultConfig {
       multiDexEnabled true  
   }

For dependency:

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

I had the same issue, after disabling instant run.. The app was crashing at runtime and threw a noClassDefFound error.. In my case I was using the forEach lambda function of Java 8 on Hashmap instead of kotlin one..

A post here and similar question here describes this. You have to use parentheses around the key and value. eg:

dataSet.forEach { (header, dataList) ->    }

This will ensure to use the kotlin function.

You ned to try clean and rebuild the project. If the problem still persist, remove the .gradle folder inside your project. Last, if none works, Use File-> Invalidate Caches/Restart.. from Android Studio menu.

As @Malcolm said, the issue is related to Android Studio 3.1.

It is still happening on Android Studio 3.1.2 if I try to run on a device with Android 5.1 while Instant Run enabled.

Invalidating caches, clearing / rebuilding project didn't work for me.

The issue was solved when I've switched to a device with Android 7.0 but I think Android 6.0+ would also work. If you are able to switch the device, give it a try. No need to disable Instant Run.

Downgrade the gradle build tool from com.android.tools.build:gradle:3.1.1 to com.android.tools.build:gradle:3.0.1 works for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!