Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError: io.realm.RealmConfiguration$Builder after gradle plugin update #1832

Closed
RuiMochila opened this issue Nov 25, 2015 · 20 comments

Comments

@RuiMochila
Copy link

I'm trying Android Studio 2.0 preview, the app was working great, then I wanted to try the Instant Run feature so AS asked me to update the gradle plugin and the build tools to 23.0.2, after the update I can't run the app, I'm getting a java.lang.NoClassDefFoundError: io.realm.RealmConfiguration$Builder when trying to initialise Realm.
I've tried cleaning and rebuilding the project.
I have multidex enabled, if that's relevant.

@RuiMochila
Copy link
Author

Also worth noting that going back to Android Studio 1.5, but still using buildToolsVersion '23.0.2' and 'com.android.tools.build:gradle:2.0.0-alpha1' I am able to run the app successfully.

@kneth
Copy link
Member

kneth commented Nov 26, 2015

I finally upgraded to Android Studio 2.0 preview. I created a small app, and I can't reproduce your issue.

My build.gradle files are:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

and

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "net.zigzak.as20"
        minSdkVersion 15
        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'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'io.realm:realm-android:0.85.0'
}

In my activity's onCreate() I do

    RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(getApplicationContext()).build();
    Realm realm = Realm.getInstance(realmConfiguration);
    realm.beginTransaction();
    Person person = realm.createObject(Person.class);
    realm.commitTransaction();

How does my app differ from yours?

@lukcz
Copy link

lukcz commented Nov 26, 2015

I had similar issue - switching gradle plug-in from classpath 'com.android.tools.build:gradle:1.5'
to classpath 'com.android.tools.build:gradle:2.0.0-alpha1' helped.

@kneth
Copy link
Member

kneth commented Nov 30, 2015

@ROUGHBOY Thanks for sharing.
@RuiMochila Is it fine to stay at 2.0.0-alpha1?

@kneth kneth closed this as completed Dec 4, 2015
@kneth kneth removed the Pending label Dec 4, 2015
@cuchas
Copy link

cuchas commented Dec 23, 2015

Hi guys, I'm still having this problem. I'm using com.android.tools.build:gradle:2.0.0-alpha3 . Is really the plugin a problem?

@cuchas
Copy link

cuchas commented Dec 23, 2015

To let you know I tried 2.0.0-alpha(1, 2, 3). It happened in all versions. @kneth

@kneth kneth reopened this Dec 28, 2015
@kneth
Copy link
Member

kneth commented Dec 28, 2015

@eduardocucharro Can you share a small app which demonstrate the issue?

@kneth kneth added the Pending label Dec 28, 2015
@cuchas
Copy link

cuchas commented Dec 29, 2015

I've taken a look to other issues and everything points to a multidex problem @kneth ! I started developing to lollipop and it was ok until I tried Jelly Bean. :)

@kneth
Copy link
Member

kneth commented Jan 4, 2016

@eduardocucharro Thanks for the update.

@kneth kneth removed the Pending label Jan 4, 2016
@tajchert
Copy link

tajchert commented Feb 2, 2016

I have same problem with 'com.android.tools.build:gradle:2.0.0-alpha9' - I cannot run as I get "XYZ is not part of the schema for this Realm."
I cannot go to alpha4 (or lower) as I get "plugin is too old" message (AS canary build 2.0 Preview 9).

Problem seems to occur when I add any other object to exisiting one, example:

public class Foo extends RealmObject {
   private Baa baa;
}

public class Baa extends RealmObject {
}

Or same with RealmList.

@cmelchior
Copy link
Contributor

Are you still seeing this problem with 2.0.0-beta3 ?

@avenwu
Copy link

avenwu commented Feb 26, 2016

Similar exception while using 2.0.0-beta5

java.lang.IllegalAccessError: Method 'void io.realm.Realm.checkIfValid()' is inaccessible to class 'io.realm.UserInfoRealmProxy' (declaration of 'io.realm.UserInfoRealmProxy' appears in /data/data/package name/files/instant-run/dex/slice-slice_9_7c81990a9272e50f79d25c2c16b10bad810e7cd5-classes.dex)

@cmelchior
Copy link
Contributor

@avenwu That problem is because of Instant Run. It should apparently be fixed in beta6. You can see more here: #2139

Since we haven't been able to reproduce this issue and it should apparently be fixed in beta6, I'll close this issue now. Feel free to reopen if you see it again using beta6 and above

@avenwu
Copy link

avenwu commented Feb 27, 2016

@cmelchior thx for your reply

@ciarancumiskey
Copy link

Hi, I've come across this problem too, but I'm calling:
realmConfig = new RealmConfiguration.Builder(getActivity().getApplicationContext()).build();
in the onCreate() method of a Fragment.

I've seen Gradle get mentioned, I'm currently using:
classpath 'com.android.tools.build:gradle:2.1.2'

@kneth
Copy link
Member

kneth commented Jul 1, 2016

As I recall, this was related to Instant Run. Since Instant Run and Android Studio are moving targets at the moment, we will need to know what version of Android Studio you are using.

@ciarancumiskey
Copy link

Hi kneth, I've since switched off Instant Run and now my app works fine. I'm using Android Studio 2.1.2.

@kneth
Copy link
Member

kneth commented Jul 4, 2016

@Hakosuka Great to hear that it works now. Looking at the change log for Android Studio for the last few preview releases, Instant Run is still work-in-progress :-(

@centerback
Copy link

I recently updated Android Studio from 1.5 to 2.1.2.
My project does not use Realm, and i got the same error. Switching off Instant Run solved the issue.
Go to Settings > Build > InstantRun

@hassanabidpk
Copy link

@centerback Just encountered the same problem and did what you suggested. It is working fine! Thanks

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants