Realm android,RealmTransformer似乎没有被应用

时间:2016-12-14 23:16:25

标签: java android realm

我是新手。

我用:

  • Android studio 2.2.3
  • Gradle:2.14.1
  • Realm-plugin:“classpath”io.realm:realm-gradle-plugin:2.2.1“”

但是当我调用Realm.init(context)时它会引发异常;在onCreate of my Activity。

日志:

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)

我的班级:

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模块级别:

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'
}

事先感谢您的帮助。

2 个答案:

答案 0 :(得分:6)

Jack无法使用Gradle中的Transform API。

因此,依赖于Transform API的Realm-Transformer不能与Jack一起使用。

使用Retrolambda而不是Jack for Java 8功能支持。

答案 1 :(得分:0)

您需要将其添加到您的d build.gradle文件中。 :

SELECT a,b,cpn FROM `betmatches` WHERE `status`='paid' GROUP BY `cpn`,a,b

然后做:

  

完成这两项更改后,只需刷新您的gradle依赖项即可。如果您要从v.88之前的版本进行升级,则可能还需要清理您的gradle项目(./gradlew clean)以删除任何延迟的先前安装。

可以在Realm网站上找到here的说明。