【发布时间】:2019-02-16 03:52:22
【问题描述】:
我正在尝试将我现有的一些应用程序代码拆分为一个 android 库模块。在将我的工作代码复制到模块目录中时,我遇到了一个注释问题,其中@EViewGroup(R.layout.dialog_action_item)casts 行在消息中显示了一个编译时错误
注解参数必须是编译时常量
当完全相同的代码在应用程序模块中运行时,我不明白为什么这会突然成为问题。两个模块的 gradle 文件实现了相同的依赖关系,并且布局文件也是旧布局文件的副本。
查看文件:
import android.content.Context
import android.graphics.Typeface
import android.os.Build
import android.support.annotation.AttrRes
import android.support.v4.content.ContextCompat
import android.util.AttributeSet
import android.widget.FrameLayout
import com.lam.locationmapservicelib.R
import kotlinx.android.synthetic.main.dialog_action_item.view.*
import com.lam.locationmapservicelib.utils.ImageLoader
import com.lam.locationmapservicelib.utils.ViewManager
import com.lam.locationmapservicelib.views.dialog.DialogActionItemModel
import org.androidannotations.annotations.EViewGroup
@EViewGroup(R.layout.dialog_action_item)
open class DialogActionItem : FrameLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet?, @AttrRes defStyleAttr: Int) : super(context, attrs, defStyleAttr)
some methods..
}
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_size">
<TextView
android:id="@+id/buttonText"
style="@style/Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/padding_16"
android:layout_marginStart="@dimen/padding_16"
android:ellipsize="end"
android:lines="1"
android:textAlignment="center" />
</FrameLayout>
分级:
kapt 'org.androidannotations:androidannotations:4.4.0'
implementation 'org.androidannotations:androidannotations-api:4.4.0'
构建错误堆栈:
`e: ...\LocationMapService\locationmapservicelib\build\tmp\kapt3\stubs\debug\com\lam\locationmapservicelib\fragments\map\MapFragment.java:5: error: incompatible types: <null> cannot be converted to int
@org.androidannotations.annotations.EFragment(value = null)
^
e: ...\LocationMapService\locationmapservicelib\build\tmp\kapt3\stubs\debug\com\lam\locationmapservicelib\views\dialog\Dialog.java:5: error: incompatible types: <null> cannot be converted to int
@org.androidannotations.annotations.EViewGroup(value = null)
^
e: ...\LocationMapService\locationmapservicelib\build\tmp\kapt3\stubs\debug\com\lam\locationmapservicelib\views\dialog\views\DialogActionItem.java:5: error: incompatible types: <null> cannot be converted to int
@org.androidannotations.annotations.EViewGroup(value = null)`
gradle 和布局文件与 DialogActionItem 类位于同一模块 (locationmapservicelib) 中。
非常感谢任何帮助!
【问题讨论】:
-
我最近看到了类似的东西,但在我的例子中,我引用了一个位于不正确的构建变体源集中的布局文件。如果您不是这种情况,您能否将完整的编译错误堆栈跟踪添加到您的问题中?谢谢:)
-
我并没有真正为这个项目使用构建变体,所以所有布局文件都在同一个目录中(每个模块)。我在上面的描述中添加了简短的错误堆栈
-
您使用的是发布/调试源集吗?如果没有,恐怕没有别的想法了。
标签: android annotations android-library android-annotations android-module