dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.92k stars 526 forks source link

Using color resource in AndroidManifest.xml leads into build error #1559

Open Sebastian1989101 opened 6 years ago

Sebastian1989101 commented 6 years ago

Steps to Reproduce

  1. Creating colors.xml under Resources\values with the used color resource.
  2. Use it within the AndroidManifest.xml as shown here:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.SoftwareNotion.MyApp" android:installLocation="auto" android:versionCode="18104" android:versionName="1.6.0">
    <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
    <permission android:protectionLevel="signature" android:name="${applicationId}.permission.C2D_MESSAGE" />
    <uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
    <application android:label="My App" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:theme="@style/AppTheme" android:appCategory="productivity" android:largeHeap="true">
        <meta-data android:name="android.max_aspect" android:value="2.1" />
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" />
        <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorPrimaryDark" />
        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
    </application>
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
</manifest>

The line <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colorPrimaryDark" /> is causing the problem.

This is how my colors.xml within Resources\values looks like:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!--Syles-->
    <color name="colorPrimary">#bd8846</color>
    <color name="colorPrimaryDark">#784627</color>
    <color name="colorAccent">#efbb79</color>
    <color name="colorActive">#dc8701</color>
    <color name="colorInactive">#cccccc</color>

    <!-- White to Black -->
    <color name="white">#FFFFFF</color>
    <color name="light_gray">#EFF2F5</color>
    <color name="med_gray">#C7D2DC</color>
    <color name="gray">#5C7082</color>
    <color name="dark_gray">#FF2B343D</color>
    <color name="black">#0D131A</color>
</resources>

Also I can use the colors within my styles.xml without any problem.

Expected Behavior

Should work.

Actual Behavior

Causing the exception No resource found that matches the given name (at 'resource' with value '@color/colorprimarydark'). when compiling.

Version Information

Microsoft Visual Studio Community 2017 Version 15.6.6 VisualStudio.15.Release/15.6.6+27428.2037 Microsoft .NET Framework Version 4.7.02556

Installed Version: Community

Visual C++ 2017 00369-60000-00001-AA851 Microsoft Visual C++ 2017

Visual F# Tools 10.1 for F# 4.1 00369-60000-00001-AA851 Microsoft Visual F# Tools 10.1 for F# 4.1

ASP.NET and Web Tools 2017 15.0.40314.0 ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 1.0 Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.51214.0 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.0.40215.0 Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.3.3000.4 Microsoft Azure Data Lake Tools for Visual Studio

Azure Stream Analytics Tools for Visual Studio 2.3.3000.4 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 2.7.0-beta3-62715-05. Commit Hash: db02128e6e3c4bdfc93e6ec425ac9162b4d4fe80 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Dotfuscator Community Edition 5.32.1.6167-6ce295ebd PreEmptive Protection - Dotfuscator CE

Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events

GitHub.VisualStudio 2.2.0.10 A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

JavaScript Language Service 2.0 JavaScript Language Service

JavaScript Project System 2.0 JavaScript Project System

JavaScript UWP Project System 2.0 JavaScript UWP Project System

JetBrains ReSharper Ultimate 2017.2.2 Build 109.0.20171006.122324 JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright © 2018 JetBrains, Inc.

Merq 1.1.17-rc (cba4571) Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure HDInsight Azure Node 2.3.3000.4 HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.3.3000.4 Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio 2.0 Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service 2.3.3000.4 Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.51212.2

Microsoft Continuous Delivery Tools for Visual Studio 0.3 Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio 4.9.11-pre (71eb098) Support for debugging Mono processes with Visual Studio.

Node.js Tools 1.4.11027.3 Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2017 ENU 15.0.27326.00 Microsoft Office Developer Tools for Visual Studio 2017 ENU

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

ResXManager 1.15.1006.0 Manage localization of all ResX-Based resources in one place. Shows all resources of a solution and let's you edit the strings and their localizations in a well-arranged data grid.

SQL Server Data Tools 15.1.61801.210 Microsoft SQL Server Data Tools

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 15.6.20202.3 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.7.0-beta3-62715-05. Commit Hash: db02128e6e3c4bdfc93e6ec425ac9162b4d4fe80 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Linux Development 1.0.8 Visual C++ for Linux Development

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake

Visual Studio Tools for Unity 3.6.0.5 Visual Studio Tools for Unity

Visual Studio Tools for Universal Windows Apps 15.0.27428.01 The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

WebJobs Tools v1.0.0 15.0.30923.0 WebJobs Tools v1.0.0

Workflow Manager Tools 1.0 1.0 This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin 4.9.0.753 (f0f46392f) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.10.96 (a702a9ceb) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 8.2.0.16 (HEAD/a78295902) Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 11.9.1.24 (f62de47) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Log File

JonDouglas commented 6 years ago

@Sebastian1989101 This looks like a bug to me in Xamarin.Android. Can you try to change the color resource to all lower case and see if it builds successfully(Only in colors.xml, leave it proper cased in the AndroidManifest.xml)? I believe it's being lower-cased by a build task which causes it to not be found by the aapt tooling. If we can confirm this, we can look into a fix.

EX:

    <color name="colorprimarydark">#1B3147</color>
jawrainey commented 5 years ago

I have just experienced this same bug when trying to override default color of notifications via Firebase (see here) as @Sebastian1989101 above.

In my AndroidManifest.xml I have used camelCase (i.e. colorPrimary) to define colors, which produces the same exception as above.

I added another color with all lowercase as @JonDouglas suggested and built and ran as expected (i.e., changing the icon color of notifications). This was alongside colors being defined in camelCase as I use these throughout my application and did not want to also refactor those.

I can confirm that (1) this bug still exists and (2) your suggestion solves it.

cjrvdev commented 4 years ago

This is still happening and changing the colors shouldnt be a solution. Any estimation on this please?

MaxxDelusional commented 4 years ago

I just lost an afternoon to this issue before finally finding this thread.

upsilondynamics commented 3 years ago

This issue really needs to be resolved, I lost an hour and a half today banging my head on the wall until I found this issue. Specifically I am using Firebase push notifications and was trying tp apply a custom color like so:

AndroidManifest.xml <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/colornotifications" />

colors.xml `<?xml version="1.0" encoding="utf-8"?>

#FFFFFF #3F51B5 #303F9F #2196F3 #2196F3 #FFFFFF ` You MUST use all lower case, I had camelCase before and wasn't working. Please resolve this issue.