2

I use libGdx for creating a game, everything is working but there is few things i don't understand in the gradle build.

And one of them is why all the assets are in the android subModule and not in the core subModule.

Core is the module responsible for all shared code and it's weird to not have the asset in it.

This can seem an easy question but that make the whole build more difficult to understand.

If you have a solution for avoiding that, i'm open to suggestion. I will try to change this behaviour on my side but i'm not much skilled in gradle configuration

Ruokki
  • 869
  • 1
  • 7
  • 24

2 Answers2

4

Why are assets in android project folder and not in core?

Well, because the libGDX team decided for the Libgdx Project Generator to put it there. You can setup your project in a different way but I would stick to the project layout proposed by libGDX.

Note that assets need not always be in android project folder, depending on what platforms you are targeting. For example, if you don't target Android devices, there will be no android folder. Feel free to read more on the Structure of LibGDX projects.

How do I change the location of the assets folder?

You have to edit:

  • ios/robovm.xml
...
<resources>
  <resource>
    <!-- change this path -->
    <directory>../android/assets</directory>
  </resource>
  ...
  • desktop/build.gradle
// ...
sourceSets.main.resources.srcDirs = ["../android/assets"]
// ...
project.ext.assetsDir = new File("../android/assets")
// ...
  • android/build.gradle
// ...
sourceSets {
    main {
        // ...
        assets.srcDirs = ['assets']
// ...

This list is probably not complete and I don't think there's an exhaustive one online. Perhaps that's another reason against changing the location of your assets folder.

Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
0

I think the main reason to have the assets directory in the android project is just convention. According to this answer the reason is that...

Android projects do have a specific folder in its root named assets. The folder has to be strictly named "assets" as enforced by the Android project. Therefore, it would be a better idea to lay your folder hierarchy the same way in other projects as well so that you won't have to make changes for individual platforms.

But I think it should be possible to move the assets directory to the core project, because it is also placed in the core proejct, if you create a project without an Android part.

To move the assets directory to the core project you just need to adapt your build.gradle file, that is placed inside the sub-projects and change the following lines:

//sourceSets.main.resources.srcDirs = ["../android/assets"]
sourceSets.main.resources.srcDirs = ["../core/assets"]

//project.ext.assetsDir = new File("../android/assets");
project.ext.assetsDir = new File("../core/assets");

In my project this file was located in the desktop sub-project, but there might be some in other build.gradle files too.

To run your project in eclipse it might be neccessary to re-link the asset folder after moving it. See this answer for a detailed description on how to do this.

Tobias
  • 2,547
  • 3
  • 14
  • 29