build_native.sh: copy all resource files directly to assets root

I’m porting another game from iOS to Android and I found it’s very inconvenient that iOS and Android uses different strategies regarding to resources. On iOS all resources put to the same folder on target (simulator/device) therefore most of the code works only with basenames of resource files, e.g. even if I have Resources/Sounds/foo.wav I can play it simply with short name: playEffect(‘foo.wav’).
But on Android build_native.sh copies all resource files to proj.android/assets preserving directory structure. I need some solution to make my game more cross-platform.
I don’t want to put all eggs (resources) in one basket in my sources because it very quickly becomes a real mess (been there done that). So I decided to copy all my resources to proj.android/assets without subdirectories and therefore get the same behavior as on iOS.

I googled for such recipe and found http://superuser.com/questions/312348/linux-copy-all-files-matching-pattern-from-dir-and-subdirs-into-a-single-dir
In the comments there is one-liner that uses only find command because on my Mac xargs does not have ~~i option. So I changed build_native.sh in that way:
<pre>
diff —git a/proj.android/build_native.sh b/proj.android/build_native.sh
index e0cb27f…d4622a7 100755
— a/proj.android/build_native.sh
**+ b/proj.android/build_native.sh
@ -38,17 +38,9@ fi
mkdir $GAME_ANDROID_ROOT/assets
~~# copy resources
~~for file in $RESOURCE_ROOT/*
~~do
~~ if [ ~~d “$file” ]; then
~~ cp rf “$file” $GAME_ANDROID_ROOT/assets
~~ fi
*# copy resources
*find $RESOURCE_ROOT
type f ~~exec cp ‘{}’ $GAME_ANDROID_ROOT/assets ‘;’
~~ if [ ~~f “$file” ]; then
~~ cp “$file” $GAME_ANDROID_ROOT/assets

  • fi
    -done

# copy icons (if they exist)
file=$GAME_ANDROID_ROOT/assets/Icon-72.png

HTH

You could just use playEffect* instead ofplayEffect( “foo.wav” )*
Tried it on iOS and Android and it works fine.