android : Error converting byte to dex

流过昼夜 提交于 2019-11-27 07:55:40

Okay. I don't know how but this worked.

First I cleaned the project and then, running the project made everything go alright.

Inshort, First Clean and then Run.

Edit First Clean and then Make Project also works.

In My case, I First Clean the project then i press Make Project button as below image, then it start working. Rebuild doesn't work for me.

And I also updating Google Repository is must.

KCKH

In my case, I put

apply plugin: 'com.google.gms.google-services'

at the bottom of build.gradle file and set multiDexEnabled true in defaultConfig. Then just run and it works.

If you are applying any plugins. Then, in your module Gradle file (usually the app/build.gradle),make sure you add the apply plugin line at the bottom of the file to enable the Gradle plugin.

e.g.

I met the same problem,and i clean project ,some other problems causeed can not clean,so i manually delete dir 'build' ,so it can can clean Ok,then run it ok for me.

I found in my case, this issue was caused by an improper configuration of build.gradle. I had two different versions of com.google.firebase. Once the versions were the same, the issue was solved

I met the same problem.
First delete build folder from project location (You can access it via android studio or using explorer), then build the project.

In my case the problem was because of capital letters in some packages.

Just restart your AS, then Rebuild your app!

After I upgraded to Android Studio 2.1, the next time I rebooted, I was asked to upgrade to JDK 1.8. After I upgraded to JDK 1.8, that's when my AS project had trouble compiling. I followed all of the suggestions in this page, but to no avail. Finally, I decided to check the version of JDK that my project was using, and to my surprise, it somehow was pointing to JDK 1.8!

Moral of the story: If compileSdkVersion<=23, double check that your project is using JDK1.7 as follows:

  • Right Mouse on top level module
  • Project STructure => JDK Location

In my case, this was due to my library not being configured as 'android'. E.g. apply plugin:'java' instead of apply plugin:'com.android.library'

Check you build.gradle (Module: your app).

All com.google.android.gms libraries must use the exact same version specification (mixing versions can lead to runtime crashes).

For example: If you have com.google.firebase:firebase-ads:9.6.1 and com.google.android.gms:play-services-basement:10.0.1

You have to change the firebase version to: 10.0.1

Please add this block inside android in build.gradle

dexOptions { preDexLibraries = false }

Before:

compile 'com.google.android.gms:play-services-location:10.0.1'
compile 'com.google.android.gms:play-services-auth:10.0.1'
compile 'com.google.firebase:firebase-database:10.2.0'
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-messaging:10.2.0'

After:

compile 'com.google.android.gms:play-services-location:10.2.0'
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'com.google.firebase:firebase-database:10.2.0'
compile 'com.google.firebase:firebase-core:10.2.0'
compile 'com.google.firebase:firebase-messaging:10.2.0'

Finally got resolved.

My project used an external library with heterogeneous Java compatibility versions in my build.gradle files (1.7 and 1.8). I fixed it by using the same version for the lib and for the app project. In my case for both :

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }

If you bring in to the code same library from 2 different sources that will cause the error.

This problem is mainly in gradle or in misversioned libraries, including, from libraries, when both define the same class. Expand and check, imported external libraries...

You cannot have two same classes to be exported to one place, or code, therefore, dexer does not know which one should be used...

For some reasons, @ChintanSoni's answer didn't worked. I tried deleting the build folder manually but couldn't delete some files since they were being used by some process. Cleaning and re-building the project didn't help so I opened task manager, selected JAVA(TM) Platform SE binary and pressed on 'End task`.

Then I tried to run the project once again and it started compiling fine.

Terranology
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile fileTree(include: 'Parse-*.jar', dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile 'com.android.support:cardview-v7:23.2.0'
    compile 'com.android.support:design:24.0.0-alpha1'
    compile "com.google.firebase:firebase-invites:9.2.0"
    compile "com.google.firebase:firebase-ads:9.2.0"
    compile 'com.google.firebase:firebase-database:9.2.0'
    compile 'com.google.firebase:firebase-core:9.2.0'
}

I add the com.google.firebase:firebase-core:9.2.0 line and choose the same version (9.2.0) for all firebase libraries and the issue was solved.

If you have multiple projects, make sure you are not adding a dependency multiple times, I needed to exclude the other project's dependency like this:

compile(project(':OtherProject-SDK')) {
    compile.exclude module: 'play-services-gcm'
    compile.exclude module: 'play-services-location'
    compile.exclude module: 'support-v4'
    compile.exclude module: 'okhttp'
}

Just clean and retry solved for me.

Try installing via :app:installDebug. If it works then it is related to Android Studio's caches. I removed .gradle/ folder inside my project and it works.

For me was very easy. Just add:

//noinspection GradleDependency,GradleCompatible implementation 'com.google.android.gms:play-services-auth:11.0.4'

... and the magic happens.

I had the same problem and it is caused by not same version of google analytics and firebase. I used 'com.google.gms:google-services:3.1.0' and then add these dependencies:

compile 'com.google.android.gms:play-services-gcm:10.2.6'
compile 'com.google.firebase:firebase-crash:10.0.1'

So change firebase version to 10.2.6 fix this problem.

compile 'com.google.android.gms:play-services-gcm:10.2.6'
compile 'com.google.firebase:firebase-crash:10.2.6'
Felipe Costa

This question have many answers but, if you not solved your error yet, this could work:

Sometimes we import different versions from google products/APIs so, try to organize your gradle file to solve the: Mixing versions warning

I had the same problem and realised that the two separate jar files I had in my app/libs folder had the same packages as sub dependencies, which caused the conflict.

I've noticed this can happen (sometimes) when editing java files while Android Studio is building.

I solved this by manually deleting the build folder and running agin.

In case it helps someone, in my case I was using a custom package in release mode instead of in debug mode.

I just changed the package from "release" to "debug" and it worked.

Thing that worked for me.

  1. Go to android folder of your app.
  2. Run ./gradlew clean
safna salam

First, build -> clean project -> rebuild it again.

If its not working, then in your build.gradle, set the multiDexEnabled as true

eg:

defaultConfig {
    applicationId "com.example.myapplication"
    minSdkVersion 21
    targetSdkVersion 27
    multiDexEnabled true
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!