2017-07-26 49 views
2

當我試圖境界在Java /科特林項目整合的Java /科特林項目產生RealmProxy類,但kapt甚至沒有對.java文件境界不使用kapt

我已經更新產生RealmProxy類境界因爲this,但仍然沒有工作

搖籃應用程序文件:

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

repositories { 
    maven { 
     url 'https://maven.fabric.io/public' 
    } 
} 

kapt { 
    generateStubs = true 
} 

project.ext { 
    daggerVersion = '2.2' 
} 

dependencies { 

    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" 
    compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" 
    kapt "com.android.databinding:compiler:2.3.3" 

    annotationProcessor group: 'com.google.dagger', name: 'dagger-compiler', version: "${daggerVersion}" 
    compile group: 'com.google.dagger', name: 'dagger', version: "${daggerVersion}" 
    kapt "com.google.dagger:dagger-compiler:${daggerVersion}" 
    provided group: 'org.glassfish', name: 'javax.annotation', version: '10.0-b28' 
    testAnnotationProcessor group: 'com.google.dagger', name: 'dagger-compiler', version: "${daggerVersion}" 
    testCompile group: 'com.google.dagger', name: 'dagger', version: "${daggerVersion}" 
    androidTestAnnotationProcessor group: 'com.google.dagger', name: 'dagger-compiler', version: "${daggerVersion}" 
    androidTestCompile group: 'com.google.dagger', name: 'dagger', version: "${daggerVersion}" 
} 
... 

項目文件:

buildscript { 
    ext.kotlin_version = '1.1.3-2' 

    repositories { 
     jcenter() 

     maven { 
      url 'https://maven.fabric.io/public' 
     } 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:2.3.3' 
     classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
     classpath "io.realm:realm-gradle-plugin:3.5.0" 
    } 
} 
... 

Java模型文件:

@RealmClass 
public class NotificationEventsModel extends RealmObject { 

    @PrimaryKey 
    private long classPK; 

    @SerializedName("userNotificationEventsCount") 
    private int eventsCount; 

} 

科特林型號文件:

@RealmClass open class PageModel(

    open var classPK: Long = 0, 
    open var content: String? = null, 
    @PrimaryKey 
    open var id: Long = 0, 

) : RealmObject() { 

} 

回答

1

我通過聲明的境界,Android插件作爲最後一個插件列表,也解決了這個問題由annotationProcessor切換到Kapt,如下圖所示:

apply plugin: 'me.tatarka.retrolambda' 
apply plugin: 'realm-android' 
apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-kapt' 
apply plugin: 'realm-android' 

kapt 'com.android.databinding:compiler:2.3.3' 
compile group: 'com.google.dagger', name: 'dagger', version: "${daggerVersion}" 
kapt group: 'com.google.dagger', name: 'dagger-compiler', version: "${daggerVersion}" 
kaptTest group: 'com.google.dagger', name: 'dagger-compiler', version: "${daggerVersion}" 
kaptAndroidTest group: 'com.google.dagger', name: 'dagger-compiler', version: "${daggerVersion}" 
+1

就像一個評論,與AS 3.x你不必使用'retrolambda'了。 – kaneda

0

我相信你應該可以擴展RealmObject

open class PageModel(...) : RealmObject() 

或者use the @RealmClass annotation and implement RealmModel

@RealmClass 
open class PageModel(...) : RealmModel 

也許與子類一起使用的註釋是向Realm發出的東西。

+0

我已經這樣做,但說在https://blog.jetbrains.com/kotlin/2015/06/better-annotation-processing-supporting-stubs-in-kapt/中,javac不會將繼承的註釋傳播到類層次結構中。所以我也使用RealmClass註釋 –

0

kotlin-kapt插件指示gradle使用kapt3。也許這是相關的,Realm插件有一些問題嗎?不應該是這樣,從this question似乎工作,但也是一個老版本的插件(這使得它更奇怪)。