15

Kotlin Kapt error: identifier expected 问题记录 - 技术小黑屋

 2 years ago
source link: https://droidyue.com/blog/2021/09/28/kotlin-kapt-android-error-identifier-expected/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Kotlin Kapt Error: Identifier Expected 问题记录

Sep 28th, 2021

在工作中,小伙伴说他遇到了一个 kapt的问题,在使用 gradle 构建的时候出现了如下的错误。

Kapt worker classpath: []
/Users/androidyue/Documents/SecooComponentMaster/module-xxxx/build/tmp/kapt3/stubs/debug/com/xxxxx/xxxxx/util/PlayerCommandStateManager.java:7: error: <identifier> expected
    private static final java.util.Map<java.lang.String, com.xxxxxx.xxxxxxx.util.const.PlayerCommandState> recordMap = null;
                                                                                    ^/Users/androidyue/Documents/xxxxxxx/module-xxxxxx/build/tmp/kapt3/stubs/debug/com/xxxxx/xxxxxx/util/PlayerCommandStateManager.java:7: error: <identifier> expected
    private static final java.util.Map<java.lang.String, com.xxxxxx.xxxxxxxx.util.const.PlayerCommandState> recordMap = null;
                                                                                                            ^/Users/androidyue/Documents/xxxxxxx/module-xxxxxx/build/tmp/kapt3/stubs/debug/com/xxxxx/xxxxxxx/util/PlayerCommandStateManager.java:7: error: <identifier> expected
    private static final java.util.Map<java.lang.String, com.xxxxxx.xxxxxxx.util.const.PlayerCommandState> recordMap = null;

对应的实际代码为

object PlayerCommandStateManager {
    private val recordMap = mutableMapOf<String, PlayerCommandState>()
}
package com.secoo.gooddetails.util.const

enum class PlayerCommandState {
    PAUSE_BY_USER,
    PAUSE_NORMAL,
    PLAY,
    INITIAL,
    ENDED,
    IDLE
}

奇怪的解决方法

  • PlayerCommandState所在的包名由com.secoo.gooddetails.util.const,修改为其他不包含const的包名即可正常编译。
  • 可能是kapt的识别包名的一些bug。可能的相关链接 https://youtrack.jetbrains.com/issue/KT-16153
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------

Build time:   2019-04-26 08:14:42 UTC
Revision:     261d171646b36a6a2xxxxxxx4c19d

Kotlin:       1.3.21
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_281 (Oracle Corporation 25.281-b09)
OS:           Mac OS X 10.16 x86_64

droidyue_gzh_green_png.png

加入技术小黑屋官方电报群

Posted by androidyue Sep 28th, 2021Android, Gradle, Java, Kapt, Kotlin

« Gson NoClassDefFoundError 问题解决


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK