项目不会与Kotlin 1.1.3一起构建

时间:2017-06-26 22:11:21

标签: android kotlin

我有一个我最近用1.1.3更新的Android项目,每次构建时都会出现以下错误:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> kotlin.jvm.internal.FunctionReference.<init>(ILjava/lang/Object;)V

其他问题通常表示这意味着stdlib不包括在内,但我确实添加了它。使用1.1.2-5可以正常工作,而1.1.3也适用于其他项目。

解决方案

  

问题在于我将注释处理器与kapt混合。对于   像DbFlow和Glide这样的项目,annotationProcessor依赖可以   直接与kapt一起使用。

回到原来的问题:

Here是我的Travis日志,下面是我的依赖项:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.3-alpha', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    testCompile 'junit:junit:4.12'

    compile("ca.allanwang:kau:${KAU}")

    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:${KOTLIN}"
    testCompile "org.jetbrains.kotlin:kotlin-test-junit:${KOTLIN}"

    debugCompile "com.squareup.leakcanary:leakcanary-android:${LEAK_CANARY}"
    releaseTestCompile "com.squareup.leakcanary:leakcanary-android-no-op:${LEAK_CANARY}"
    releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:${LEAK_CANARY}"
    testCompile "com.squareup.leakcanary:leakcanary-android-no-op:${LEAK_CANARY}"

    compile "com.github.Raizlabs.DBFlow:dbflow:${DBFLOW}"
    compile "com.github.Raizlabs.DBFlow:dbflow-core:${DBFLOW}"
    annotationProcessor "com.github.Raizlabs.DBFlow:dbflow-processor:${DBFLOW}"
    kapt "com.github.Raizlabs.DBFlow:dbflow-processor:${DBFLOW}"
    compile "com.github.Raizlabs.DBFlow:dbflow-kotlinextensions:${DBFLOW}"

    //Icons
    compile "com.mikepenz:material-design-iconic-typeface:${IICON_MATERIAL}@aar"
    compile "com.mikepenz:community-material-typeface:${IICON_COMMUNITY}@aar"

    compile "org.jsoup:jsoup:${JSOUP}"

    compile "com.github.bumptech.glide:glide:${GLIDE}"
    annotationProcessor "com.github.bumptech.glide:compiler:${GLIDE}"

    compile("com.mikepenz:materialdrawer:${MATERIAL_DRAWER}@aar") {
        transitive = true
    }
    compile "co.zsmb:materialdrawer-kt:${MATERIAL_DRAWER_KT}"

    compile "nz.bradcampbell:paperparcel:${PAPER_PARCEL}"
    compile "nz.bradcampbell:paperparcel-kotlin:${PAPER_PARCEL}"
    kapt "nz.bradcampbell:paperparcel-compiler:${PAPER_PARCEL}"

    compile "com.jude:swipebackhelper:${SWIPE_BACK}"

    compile("com.crashlytics.sdk.android:crashlytics:${CRASHLYTICS}@aar") {
        transitive = true;
    }
}

当我尝试使用完整的堆栈跟踪进行构建时,以下是错误输出:[已删除,因为此帖子太长了] 我不确定它是否有帮助,但dbflow通常每个构建都有警告,因为它不需要每次都生成类。我已经向他们的回购发送了一个问题,但我不认为这是问题,因为它与1.1.2-5一起正常工作

编辑2:我看了./gradlew dependencies,他们都显示了kotlin 1.1.3(这里发布的时间太长了)。有一些依赖于他们的github源1.1.0,但不应该受到影响,排除那些std-libs无法解决错误。

编辑3:尝试.gradlew app:dependencies | grep org.jetbrains.kotlin后,我得到以下内容:

$ ./gradlew app:dependencies | grep org.jetbrains.kotlin
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
|    |    \--- org.jetbrains.kotlin:kotlin-stdlib:1.0.4 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    +--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3 -> 1.1.3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)
+--- org.jetbrains.kotlin:kotlin-annotation-processing:1.1.3
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.3
|    |    +--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1 -> 1.1.2-3
|    |    |    \--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-3
|    |    |         \--- org.jetbrains.kotlin:kotlin-stdlib:1.1.2-3 -> 1.1.3 (*)
|    \--- org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3 (*)

3 个答案:

答案 0 :(得分:17)

根据我的经验,你:

  1. 不应混用kaptannotationProcessor
  2. 使用kapt3
  3. 使用apply plugin: 'kotlin-kapt'
  4. 请勿使用kapt { generateStubs true } }kapt3不允许)
  5. 同时检查您的Kotlin插件和Gradle插件是否是最新的 另外,我通常不使用标准库的jre7版本,但我怀疑这是问题所在。

    以下是“Kotlin不起作用的事情”的更详尽的清单:https://gist.github.com/lmller/3c43eff454f7508474210fb2491b488a

答案 1 :(得分:2)

报告的错误消息为:

  

java.lang.NoSuchMethodError:

     

kotlin.jvm.internal.FunctionReference。&lt; init&gt;( ILjava / lang / Object; )V是构造函数(Int,Object)

构造函数在kotlin 1.1中引入,如下所示:

@SinceKotlin(version = "1.1")
public FunctionReference(int arity, Object receiver) {
    super(receiver);
    this.arity = arity;
}

您可以运行./gradlew dependencies并搜索哪个依赖项使用kotlin-stdlib版本&lt; 1.1。并将其从您的项目中排除。如下所示:

dependencies{
   compile('which dependency use stdlib < 1.1'){
        exclude group:'org.jetbrains.kotlin', module:'kotlin-stdlib'
   }
}

答案 2 :(得分:1)

添加:

申请插件:&#39; kotlin-kapt&#39;

enter image description here