In the Android SDK documentation, all of the examples used with the @drawable/my_image xml syntax directly address images that are stored in the res/drawable directory in my
#!/usr/bin/env ruby
# current dir should be drawable-hdpi/ etc
# nuke all symlinks
Dir.foreach('.') {|f|
File.delete(f) if File.symlink?(f)
}
# symlink all resources renaming with underscores
Dir.glob("**/*.png") {|f|
system "ln -s #{f} #{f.gsub('/', '_')}" if f.include?("/")
}
Use assets folder.
sample code:
InputStream is = null;
try {
is = this.getResources().getAssets().open("test/sample.png");
} catch (IOException e) {
;
}
image = BitmapFactory.decodeStream(is);
I like to use a simple script to flatten an organized directory structure provided by designers to something that can be used to generate an R file.
Run with current path in drawable-hdpi:
#! /bin/bash
DIRS=`find * -type d`
for dir in ${DIRS} ; do
for file in `ls ${dir}` ; do
mv ${dir}/${file} ${dir}_${file};
done
rmdir ${dir};
done
One way to partially get around the problem is to use the API Level suffix. I use res/layout-v1, res/layout-v2 etc to hold multiple sub projects in the same apk. This mechanism can be used for all resource types.
Obviously, this can only be used if you are targeting API levels above the res/layout-v? you are using.
Also, watch out for the bug in Android 1.5 and 1.6. See Andoroid documentation about the API Level suffix.
It is possible to have multiple drawable folders by having an extra folder parallel to 'res' with a subdirectory 'drawable' and then add following to gradle:
sourceSets {
main {
res.srcDirs 'src/main/<extra_res>'
}
}
Tested with gradle 6.5.1