Realm-java: Compile-time error "unreachable statement"

Created on 11 Aug 2016  Â·  6Comments  Â·  Source: realm/realm-java

Goal

I want to use Realm in separated android-library module

Expected Results

I expect my project to compile.

Actual Results

:model:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
Note: Processing module MyDiaryModule
C:\Users\Alexandr\AndroidStudioProjects\MyDiary\my-diary-android\model\build\generated\source\kapt\debug\io\realm\MyDiaryModuleMediator.java:102: error: unreachable statement
            if (iterator.hasNext()) {
            ^
C:\Users\Alexandr\AndroidStudioProjects\MyDiary\my-diary-android\model\build\generated\source\kapt\debug\io\realm\MyDiaryModuleMediator.java:130: error: unreachable statement
            if (iterator.hasNext()) {
            ^
2 errors
:model:compileDebugJavaWithJavac FAILED

Steps & Code to Reproduce

see code samples

Code Sample

root build.gradle

buildscript {
    ext.kotlin_version = '1.0.3'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        classpath "io.realm:realm-gradle-plugin:1.1.1"
    }
}

build.gradle of "model" module

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'realm-android'

android {
    compileSdkVersion rootProject.ext.androidCompileSdkVersion
    buildToolsVersion rootProject.ext.androidBuildToolsVersion

    ...
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

kapt {
    generateStubs = true
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    provided "io.reactivex:rxjava:${rxJavaVersion}"

    compile "com.google.code.gson:gson:${gsonVersion}"
    provided "org.threeten:threetenbp:${threetenbpVersion}"

    testCompile 'junit:junit:4.12'
}
repositories {
    mavenCentral()
}

Generated class:
pastebin

This class full of errors, must I include some library in dependencies?
image

Version of Realm and tooling

Realm version(s): 1.1.1
Kotlin version: 1.0.3

Android Studio version: Android Studio Beta 2.2

Which Android version and device: —

T-Help

Most helpful comment

You should have at least 1 class that extends RealmObject , or implements RealmModel and has @RealmClass annotation to have at least 1 class in the schema

All 6 comments

You might have been hit by the bug described here: https://github.com/realm/realm-java/issues/3115 Can you try using our 1.2.0-SNAPSHOT? https://github.com/realm/realm-java#using-snapshots

Also from library projects, you must expose the schema using RealmModule in your realm configuration.

@cmelchior
I just switched to snapshot by changing my root build.gradle like that:

buildscript {
    ext.kotlin_version = '1.0.3'
    repositories {
        jcenter()
        maven {
            url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' // for realm snapshot
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
        classpath "io.realm:realm-gradle-plugin:1.2.0-SNAPSHOT"
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://oss.jfrog.org/artifactory/oss-snapshot-local' // for realm snapshot
        }
    }
}

And I still get the same compile-time error. I also tried to do gradlew clean / gradlew build, but it didn't help.

@Zhuinden I added empty class annotated with @RealModule. Is it enough to compile without errors? I don't have any class that extends RealmObject as there is no RealmObject in autocompletion for "model" module.

package com.nickapps.Diary.model

import io.realm.annotations.RealmModule

@RealmModule(library = true, allClasses = true)
class MyDiaryModule {
}

You should have at least 1 class that extends RealmObject , or implements RealmModel and has @RealmClass annotation to have at least 1 class in the schema

@Zhuinden But it seems that I have only Realm's annotations in classpath as autocompletion works only for it. I will try to add import manually and write back soon.

Project successfully built, but autocompletion works only for Realm's annotations. It may be issue with Android Studio Beta and I fixed it via File -> Invalidate caches / restart

image
image

Thanks for help!

Was this page helpful?
0 / 5 - 0 ratings