bazelbuild / rules_apple

Bazel rules to build apps for Apple platforms.
Apache License 2.0
496 stars 261 forks source link

Problem with Assets.xcassets/accentColor.colorset #1097

Closed pedrofveloso closed 3 years ago

pedrofveloso commented 3 years ago

Hi! I am trying to implement Bazel in some personal projects (for learning purposes) and I'm facing a very peculiar problem involving the colorset inside the xcassets folder.
Bazel builds as expected and I'm even able to run the app in a simulator successfully, but it seems that the accentColor (defined via colorset [yes, I'm using SwiftUI]) is being ignored 🤔; but ALL other resources from xcassets folder are being displayed as expected.

Here is how I'm implementing my assets resource:

apple_resource_group(
    name = "Assets",
    resources = glob(["Assets.xcassets/**"]),
)

and I'm implementing my swift_library as follows:

swift_library(
    name = "Source",
    srcs = glob(["Source/**/*.swift"]),
    data = [
        ...
        "Assets",
    ]
)

The directory structure is something like this:

.xcassets
├── AccentColor.colorset
             └─ Contents.json
├── AppIcon.appiconset
             └─ <<All app icons + Contents.json>>
├── Contents.json
├── Images            
...

So, the app icons are being displayed as expected, as well as all the other images.

Is anyone facing a similar issue?

Thanks in advance!

keith commented 3 years ago

Probably best to look in the Asset.car file of the built app with something like assetutil -I Asset.car and see if it's represented there as you'd expect. Nothing stands out as wrong from your description so far.

pedrofveloso commented 3 years ago

Hi, Keith! Thank you for your answer/tip! It was very useful! I ran the command you suggested and you were right! The color set was there as expected.

I did some researches and I figured out the real problem... It seems that the Xcode adds the accentColor to the Info.plist (NSAccentColorName property) when building the project.

Here a quote from the doc:

NSAccentColorName This Info.plist value controls the global tint color (iOS and watchOS) or accent color (macOS) for the target. When set in a widget extension, the widget configuration user interface uses this color as the tint color while editing a widget. While you can set this directly in your Info.plist, the recommended approach is to use the Global Accent Color Name build setting (in the Asset Catalog Compiler - Options section) of the target. Set the value of the build setting to the name of the Color Set in the asset catalog. Xcode automatically sets NSAccentColorName to the appropriate value in the Info.plist file when building your project.

I just added the NSAccentColorName to my info.plist and it worked (as a workaround). I know that the recommended approach is to use the global accent color build setting, but I still don't know how to do this with Bazel hehe 😅 If you have any tips about how I can do this, it would be awesome!

Thank you very much for the quick support!

thii commented 3 years ago

The equivalent of that in Bazel is to pass --accent-color <color-set-name> to actool, but rules_apple doesn't support passing additional flags to resource tools yet.