【问题标题】:error: resource color/com_facebook_messenger_blue not found错误:找不到资源颜色/com_facebook_messenger_blue
【发布时间】:2018-11-26 02:08:24
【问题描述】:

当我构建我的应用程序时(我尝试了干净构建和重建两者)它显示 AAPT2 错误,所以我从左侧的 gradle 选项卡运行 assembleDebug 显示休闲错误

AGPBI: {"kind":"error","text":"error: resource color/com_facebook_messenger_blue (aka com.example.itachi.com.pbr:color/com_facebook_messenger_blue) not found.","sources":[{"file":"C:\\Users\\ITACHI\\Downloads\\Scrof\\PBR\\app\\src\\main\\res\\values\\styles.xml"}],"original":"","tool":"AAPT"}

所以按照错误中建议的路径,我检查了 values 文件夹中的 styles.xml 文件,如下所示

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/com_facebook_messenger_blue</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>


<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>
<style name="DrawerHamburgerStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/black</item>
</style>


<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

谁能告诉我哪里做错了?

【问题讨论】:

  • 如果这不是您的应用程序styles.xml 文件,请在colors.xml 中创建一种新颜色,将其命名为 colorPrimay,它将覆盖您在依赖项中声明的颜色。如果它是您的样式文件,只需更改颜色,或添加名为 com_facebook_messenger_blue 的颜色
  • 不是我的,我的朋友把它作为 zip 文件发给我
  • 能否请您详细说明解决方案。
  • 尝试在您的colors.xml 文件中添加这一行&lt;color name="com_facebook_messenger_blue"&gt;#0084ff&lt;/color&gt;
  • 感谢它的帮助,但我仍然不明白为什么它出错了,如果你能解释我会写下答案,否则请写下答案。

标签: android android-layout android-studio android-gradle-plugin


【解决方案1】:

正如您在 cmets 中所说,您包含的依赖项应该是 jar 或 aar 文件。我猜它是依赖于 Facebook SDK 构建的,因为缺少资源的名称。

当您构建 aar 文件时,它不包含所需的依赖项,但您必须在 build.gradle 文件中提供它们。

要使其正常工作,您可以在项目中声明缺少的依赖项,或者按照我在这种情况下的建议,您只需在 colors.xml 文件中添加缺少的资源即可。

<color name="com_facebook_messenger_blue">#0084ff</color>

这样,当您的项目正在编译时,它能够将缺少的资源提供给您的存档库。我希望现在已经足够清楚了。

【讨论】:

    【解决方案2】:

    在您的代码中,您似乎从您的 colors.xml 文件中调用了一种以“com_facebook_messenger_blue”命名的颜色。

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/com_facebook_messenger_blue</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    </style>
    

    错误是指,colors.xml 文件中没有以“com_facebook_messenger_blue”命名的颜色。

    所以,

    转到 res > values 并打开 colors.xml 文件。然后在 &lt;resource&gt;...&lt;/resource&gt; 标签。

    <color name="com_facebook_messenger_blue">#your desired color code</color>
    

    记得放颜色代码。

    【讨论】:

      猜你喜欢
      • 2020-06-21
      • 1970-01-01
      • 2023-03-24
      • 2022-07-26
      • 2015-10-21
      • 1970-01-01
      • 2011-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多