realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.45k stars 1.75k forks source link

Error Converting Bytecode to Dex since upgrade to Realm 0.88.2 #2499

Closed deibid closed 8 years ago

deibid commented 8 years ago

`

Bugs: I've been using Realm for my last two projects and i really like it. It's awesome..

Now, i'm upgrading the version from 0.87.5 to 0.88.2 and im getting the following errors at build time

Error:Error converting bytecode to dex: Cause: com.android.dex.DexException: Multiple dex files define Lio/realm/RealmCache$Callback;

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

I've tried to clean the project and invalidating cache/ restart and all the other tricks, but i cant get it to work.

_My build.gradle (Project) file is the following: _

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-beta6'
        classpath 'com.google.gms:google-services:2.0.0-beta6'
        classpath "io.realm:realm-gradle-plugin:0.88.2"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

My build.gradle (Module:app) file is the following:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.doce18.davidazar.doce18"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    //Realm.io related stuff
//    compile 'io.realm:realm-android:0.87.5'
    compile 'com.github.thorbenprimke:realm-recyclerview:0.9.12'

// all other libs here...

}

I've tried changing the apply plugin: 'realm-android' tag to the Project's build.gradle file and didnt work either.

Goal

A successful build

Version of Realm and tooling

Realm version(s): ?

0.88.2

Android Studio version: ?

1.5.1

Which Android version and device: ?

HTC M8 Android 6.0

zaki50 commented 8 years ago

Hi @deibid

I'll try to reproduce this issue on my macine.

One question. Are you using any library projects which uses Realm(except for realm-recyclerview)?

deibid commented 8 years ago

Thanks..

Not that I know of..

I'm basically using the AWS SDK, Google play services and Glide with GlideTransforms.

I tried to comment out the Realm-RecyclerView dependency, thinking it might be redeclaring Realm, but of course, the build fails.

Looks like the issue is present when multiple dependencies try to declare the same class.

emanuelez commented 8 years ago

@deibid Can you please provide the full list of your dependencies?

deibid commented 8 years ago

dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.2.0' compile 'com.android.support:design:23.2.0' compile 'com.android.support:cardview-v7:23.2.0' compile 'com.android.support:recyclerview-v7:23.2.0'

//Google Play Services
compile 'com.google.android.gms:play-services-gcm:8.4.0'

//Realm.io related stuff

compile 'com.github.thorbenprimke:realm-recyclerview:0.9.12'

//Image Loading libs
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'jp.wasabeef:glide-transformations:2.0.0'

/* Amazon Web Services Related Libraries*/
compile 'com.amazonaws:aws-android-sdk-core:2.2.10'
compile 'com.amazonaws:aws-android-sdk-cognito:2.2.10'
compile 'com.amazonaws:aws-android-sdk-s3:2.2.10'
compile 'com.amazonaws:aws-android-sdk-lambda:2.2.10'
compile 'com.amazonaws:aws-android-sdk-sns:2.2.10'

}

*sorry for bad formatting, can't seem to make it work from mobile

emanuelez commented 8 years ago

And I assume you remove the realm-android line when you update to 0.88.2, correct?

deibid commented 8 years ago

You mean the compile 'io.realm:realm-android:0.87.5' one from the build.gradle ( Module: app ) ? Yeah, I removed it. I'll edit my last comment to remove it from this thread too.

emanuelez commented 8 years ago

Well, it looks like the realm-recyclerview library depends on an old version of Realm:

https://github.com/thorbenprimke/realm-recyclerview/blob/master/library/build.gradle#L25

Some investigation is needed to figure out if such conflict can arise.

deibid commented 8 years ago

I see.. That makes sense.

So, for now, is it better to just wait before jumping to the next version or is there something we can do to integrate all of this together ?

emanuelez commented 8 years ago

I will try replicating the issue and see what can be done about it

emanuelez commented 8 years ago

Well, it looks like since the realm-recyclerview library depends on Realm and already imports it to the project, it means that:

I think the only thing we can do now is to ask the library developer to support Realm 0.88+

deibid commented 8 years ago

I always thought that the realm-RecyclerView was officially supported by Realm.io. I'll issue a bug at the other site.

Thanks

zaki50 commented 8 years ago

Can we use this https://docs.gradle.org/current/userguide/dependency_management.html#sub:exclude_transitive_dependencies to exclude transitive dependency from realm-recyclerview?