Search code examples
eclipsegradlelibgdx

LibGDX dual assets setup, Eclipse, Gradle


I have decided to use two different sets of assets for desktop and android but I am not sure what the best way to do this would be? If anyone got some tip or suggestion on how to streamline this I would appreciate it!

I am using Eclipse and Gradle.


Solution

  • You can use two different assets folders. No one is forcing you to share assets for all platforms.

    In build.gradle of Android project you can locate and modify assets.srcDirs = ['assets'] line. It stores a relative path to the assets folder. Since you want to keep separate assets for mobiles (or at least the Android version), I suggest you leave it as it is, though - just keep the android/assets folder as usual and store mobile assets there.

    As for the desktop project, assets are referenced two times in build.gradle: in project.ext.assetsDir = new File("../android/assets"); and linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/android/assets'. As you can see, they both store (sorta) relative paths that you can safely replace. Creating a new desktop/assets folder makes sense if you want to keep a similar folder structure. These two lines would be simply replaced with project.ext.assetsDir = new File("assets"); and linkedResource name: 'assets', type: '2', location: 'PARENT-1-PROJECT_LOC/desktop/assets' - and then you can just import the project as usual.

    Note that this answer assumes that you generated your project with the default gdx-setup app. The default LibGDX project generator usually does not handle assets folder linking for you, so just remember to mark the new desktop/assets folder as resource in Eclipse.