Java – Realm android, RealmTransformer seems to have no application

Realm android, RealmTransformer seems to have no application… here is a solution to the problem.

Realm android, RealmTransformer seems to have no application

I’m a newbie.

I use:

  • Android Studio 2.2.3
  • Level: 2.14.1
  • Realm plugin: “classpath” io.realm:realm-gradle-plugin:2.2.1″

But when I call Realm.init(context) it throws an exception; In the onCreate of my activity.

Log:

12-14 16:40:51.096 3541-3541/? E/AndroidRuntime: FATAL EXCEPTION: main
                                             Process: *.demo, PID: 3541
                                             java.lang.ExceptionInInitializerError: RealmTransformer doesn't seem to be applied. Please update the project configuration to use the Realm Gradle plugin. See https://realm.io/news/android-installation-change/
                                                 at io.realm.RealmConfiguration.<clinit>(RealmConfiguration.java:77)
                                                 at io.realm.RealmConfiguration$Builder.initializeBuilder(RealmConfiguration.java:414)
                                                 at io.realm.RealmConfiguration$Builder.<init>(RealmConfiguration.java:402)
                                                 at io.realm.Realm.init(Realm.java:188)
                                                 at *.demo. MainActivity.onCreate(MainActivity.java:21)
                                                 at android.app.Activity.performCreate(Activity.java:6237)
                                                 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                 at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                 at android.os.Looper.loop(Looper.java:148)
                                                 at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

My class:

import io.realm.Realm;

public class MainActivity extends AppCompatActivity {

@Override
    protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

Realm.init(this); crashing line
   }
}

Build.gradle module level:

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

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "*.demo"
        minSdkVersion 10
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner     "android.support.test.runner.AndroidJUnitRunner"
        jackOptions {
            enabled true
        }
         Enabling multidex support.
        multiDexEnabled true
   }
   buildTypes {
       release {
          minifyEnabled false
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      }
  }

compileOptions {
       targetCompatibility 1.8
       sourceCompatibility 1.8
   }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
   })
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:multidex:1.0.1'

compile 'com.github.pwittchen:reactivenetwork:0.7.0'
    testCompile 'junit:junit:4.12'
}

Thank you in advance for your help.

Solution

Jack does not use the transformation API in Gradle.

Therefore, Realm-Transformers that rely on the Transform API cannot be used with Jack.

Use Retrolambda instead of Jack to support Java 8 features.

Related Problems and Solutions