Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

My project was initially not meant for Android, and its assets are organised along the following directory structure (I hope the ASCII art renders reasonably well):

/
+- engine/
 |    +- src/
 |     |      enginefile1.cpp
 |     |      ...
 |     `- textures/
 |            texture1.tex
 |            ...
+- game/
 |    +- src/
 |     |      gamefile1.cpp
 |     |      ...
 |    +- textures/
 |     |      gametexture1.tex
 |     |      ...
 |    +- ios/
 |     |      [various iOS-specific files]
 |     `- android/
 |           | build.xml
 |           | AndroidManifest.xml
 |           +- jni/
 |           |     Android.mk
 |           +- assets/
 |             [other Android-specific files]
 `- othergame/

My game/android/jni directory is almost empty because Android.mk points to the relative paths of the source files in engine/src and game/src. Actually, it even includes the proper Makefiles so that I never have to modify Android.mk when I add or remove a source file to the project.

Both engine and game provide assets that need to be shipped with the Android build. I would like build.xml to refer to these assets without having to manually copy them. A rule that copies the assets at build time then deletes them would be acceptable, but of course I would prefer a zero copy solution. Does this make sense? How did others solve this cross-platform build problem?

share|improve this question

5 Answers 5

Yes, you can absolutely use files in other directories. Place the assets you have in to the assets directory (sibling to the res directory), and use the AssetManager to access them.

To load bitmaps, you'll want the BitmapFactory, and you'll have to do some extra work if you intend to load resolution dependent images.

Be careful about loading Bitmaps more than once. Because you will be dealing with raw file handles, you'll probably want to implement some resource/memory manager that allows you ot quickly look up references to existing Bitmap objects and the like. Depending on your architecture, you may need to do this with WeakReferences so you don't end up with the entire game data in memory. (With normal android resources, the ResourceManager handles all of this for you.)

share|improve this answer
    
Placing the assets in the same directory (be it res or assets) is precisely what I do not want to do. As I said in the question, both engine and game provide assets that I want to ship. –  Sam Hocevar Apr 29 '11 at 11:32
    
Add a pre-compile script to link or copy assets into the assets directory, allowing you to preserve any game specific directory structure. As for Windows symlinks: windows7home.net/how-to-create-symbolic-link-in-windows-7 –  Anm in LA May 3 '11 at 20:01
    
Though a pre-compile script is probably the most conventient solution, it would be nice if your answer mentioned it, maybe together with a short example, so that it could be accepted. (note that I'm making the exact same comment in the other answer) –  Sam Hocevar Oct 20 '11 at 22:42

Ant build property "asset.dir" is responsible for providing name of assets directory. It's "assets" by default, but you can change it to something like "../assets". This changes path of entire directory, but if you have Android-specific resources, you can still use "res" directory.

share|improve this answer

Off the top of my head, I don't think you can use anything outside of res/, but if you're looking to avoid added cost to your dev cycle with a copy, you might try moving them instead or maybe even using a symlink...

share|improve this answer
    
I can definitely not move the files because some of them are shared across games and need to stay in the engine directory, which is in a separate repository. Symlinks might be acceptable but I am not sure they'd work well on Windows and then there is still the problem of having them synchronised automatically by build.xml. –  Sam Hocevar Apr 10 '11 at 9:35
1  
@Sam - You can leave the files in place in your repository, but create a pre-compile step in your build framework (apparent an Ant build.xml file) to copy the files to the places necessary for your Android project. This is common practice when share assets in a multi-platform game. See the Ant copy task: ant.apache.org/manual/Tasks/copy.html –  Anm in LA Apr 24 '11 at 20:06
    
Though a pre-compile script is probably the most conventient solution, it would be nice if your answer mentioned it, maybe together with a short example, so that it could be accepted. (note that I'm making the exact same comment in the other answer) –  Sam Hocevar Oct 20 '11 at 22:42

If you were using a Maven project as opposed to an Ant project, you could easily redefine the res folder to be whatever you wanted via the resourceDirectory configuration option of the android:apk mojo in the android-maven-plugin.

  <plugin>
    <groupId>com.jayway.maven.plugins.android.generation2</groupId>
    <artifactId>android-maven-plugin</artifactId>
    <version>${android.maven.version}</version>
    <configuration>
      <resourceDirectory>${project.basedir}/res</resourceDirectory>
    </configuration>
    <extensions>true</extensions>
  </plugin>

Sadly, unless you were willing to migrate from using Ant to using Maven, this answer might not help you very much...

share|improve this answer

If you are on a unix OS you can hard-link them, and tell your version control to ignore the res/ directory.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.