beeware / briefcase

Tools to support converting a Python project into a standalone native application.
https://briefcase.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
2.47k stars 350 forks source link

Add ability to override resources in application #1875

Open Pairman opened 3 weeks ago

Pairman commented 3 weeks ago

What is the problem or limitation you are having?

Is there any way to add or override resource files?

This is extremely useful when managing resources. For example, I'd like my ic_launcher_background be defined in an xml, to support gradient colors.

Describe the solution you'd like

Either under the android specific section in pyproject.toml, or by modifying briefcase.toml.

For example, a project can store the overrides under a directory, with the exact same hierarchy.

And in pyproject.toml, user specifies this dir to override the resiurces under [tool.briefcase.app.xdcheckin.android].

The packaging process will first apply the common res dir in the project's src/<name>/app/res, then apply the overrides directly to the generated template's res dir.

Describe alternatives you've considered

Modifying res in the result .apk can also work, but it's not convenient and universal for every briefcase projects.

Additional context

Thanks.

freakboy3742 commented 3 weeks ago

Thanks for the suggestion. There's definitely an interesting idea contained in this suggestion - the catch is how we can implement it in a generic way that makes sense.

Broadly speaking, "here's a collection of files I want you to copy into the final project" makes sense as a use case. The question is the exact format for that file specification.

Your suggestion is specific to Android resources - which will definitely be a good use of this feature, but there are other files you might want to add to an Android project, and other platforms may have use for this feature.

We could possibly treat this as an analog of cleanup_paths - that is, require specifying paths relative to the root of the template folder. This could work, but it would require very deep, empty directory structures to inject a file into the resources folder.

The best idea I can think of right now it to treat this as specification of roots: so a configuration like:

additional_files."app/src/main/res" = [
   "foobar/resources/**"
]
additional_files."app/src/main/java/com/example" = [
   "whiz/bang/*.java",
   "whiz/bang/*.txt",
]

would copy all the files in the foobar/resources folder into the res folder for the project, and all the java and txt files in wiz/bang directory into the com.example code namespace.

There's some details to finesse about exactly how you'd copy in a full directory tree; but hopefully this gives the start of an idea that someone can turn into an implementation.