Cinder
Cinder copied to clipboard
Android Resources support
From @richardeakin on August 31, 2015 3:59
Other than many samples using resources so they can reference a file in the main samples/data folder, many real-world applications are setup to use resources, especially for windows where the files get packed into the .exe (we're doing this for our current project). Things are obviously different on android, and while I don't know much about this topic yet, here is what I have recently found out:
- By default, android expects resources to live in the 'res' folder. This doesn't work for us on its own - we need them to be specifiable at arbitrary locations relative to the project folder.
-
Here is a lengthly post that explains how @safetydank approached this problem.
- I believe he referenced resource files from within an assets folder
- @arielm mentioned that using the old And build system, you could specify
asset.dir = ../resources
in the ant.properties file.- Is there an equivelant using gradle?
- In this distantly related document I saw mention of a gradle property that looks like the following, not sure if this is a valid lead or not:
android.sourceSets {
main.res.srcDirs = ['src/main/res', src/main/res2']
}
- In any event, one solution seems that we could have a prebuild step that copies the resource files into somewhere within the androidstudio/build folder (so they don't show up dirty in VCS), and then refer to them at runtime similar to how the assets system works.
Copied from original issue: chaoticbob/Cinder#39
From @chaoticbob on September 18, 2015 23:54
I don't really have a strong opinion about this. Based on all the things that you listed, there are a couple of different ways to fix this in the immediate:
- adding
resources
(or whatever dir you want to theassets.srcDirs
works (as @arielm suggested).- You can see an example of it here
- The only caveat to this is that you need to make sure that you don't have competing paths and names in the other dirs that you list for
assets.srcDirs
as well. - Currently, if you call
loadResource
on Android, it just calls load assets.
- Alternatively (based @safetydank suggested) we can treat
assets/resources
as a special folder and have load resources access that.- This doesn't actually have to live inside of
assets
. It can live where you want it to, you just that the parent directory is what gets specified toassets.srcDirs
. This path can probably be symlink if needed...so it will work almost anywhere but Windows. - This will require modification to
loadResources
.
- This doesn't actually have to live inside of
Both of these avoids a prebuild copy process.
We cannot do anything to/with the actual res
dir. That folder has to exists since it's where all the UI related resources lives.
Anyway, think about it and discuss it with whoever is interested and let me know how you want this implemented. The only thing I'd recommend is to avoid a prebuild copy step if possible.
So for this issue, it makes the most sense, in my opinion, to hook into the Android asset/resource manager.
One of the things that Android does quite well is handle resources like strings and graphics across different languages and resolutions - it's very common to see an Android app with, say, multi language variations, all provided by the resource manager. Additionally, it's conceivable that a developers might want to incorporate a Cinder program into a larger Android app, via a NativeActivity. It seems sensible to hook Cinder into the Android resources & assets manager rather than creating something new an non-standard. I'll look into it further.