代码之家  ›  专栏  ›  技术社区  ›  Mustafa Berkay Mutlu

重新构建安卓即时应用程序后,使用功能模块中基本模块中定义的颜色失败

  •  2
  • Mustafa Berkay Mutlu  · 技术社区  · 9 年前

    base 模块和一个称为 query 我的即时应用程序项目中的模块。

    QueryActivity 在…内 模块使用以下颜色: 单元

    QueryActivity.kt :

    @ColorInt
    val textColor: Int = when (resultCode) {
        FetchAddressIntentService.RESULT_SUCCESS -> android.R.color.white
        FetchAddressIntentService.RESULT_FAILURE -> R.color.accent // this color is inside the base module
        else -> R.color.accent // this color is inside the base module
    }
    

    如果我试着 run 该项目运行良好,没有任何问题。但是如果我 rebuild

    ../net/epictimes/uvindex/query/QueryActivity.kt
    Error:(133, 63) Unresolved reference: color
    Error:(134, 27) Unresolved reference: color
    

    指向那些颜色值。

    我通过添加另一个解决了这个问题 colors.xml 文件内部 模块并引用 基础 this commit .

    <color name="query_location_success_text">@android:color/white</color>
    <color name="query_location_fail_text">@color/accent</color>
    

    现在它可以工作了,但我不知道为什么。这样做对吗?我的问题是不应该是里面的资源

    版本:

    Android目标/编译SDK:26

    科特林:1.1.50

    即时应用:1.1.0

    here .

    1 回复  |  直到 6 年前
        1
  •  11
  •   Julia K    9 年前

    是的,当您使用完全限定名(package\u name.R.resource\u name)引用基本模块时,可以从功能模块访问基本模块内的资源。

    net.epictimes.uvindex ,您的功能模块包名称为 net.epictimes.uvindex.query ).

    • net.epictimes.uvindex.R -用于基本功能模块
    • net.epictimes.uvindex.query.R -用于功能模块

    net.epictimes.uvindex.R.color.accent 标识符:

    FetchAddressIntentService。结果_失败->网史诗时代。紫外线指数。R、 颜色。口音

    推荐文章