Sharing LibGDX assets

I recently came across the problem of not being able to properly share the “data” folder of my Desktop and Android LibGDX project in IntelliJ IDEA. Now i found 3 solutions for this. Each one has it’s benefits.

Solution 1 using only IntelliJ IDEA

In this solution both projects use the “data” folder in your Desktop project:

  • Right-click you Android project and select “Open Module Settings [F4]”
  • Under “Modules” select the Android Facet
  • In the tab “Structure” you can change the default Android assets directory
  • Browse to the folder containing the data folder of your Desktop project an click OK

Notice: You have to select the parent folder of the data folder in your Desktop project since the Android project will look for the data folder inside the defined assets folder.

The first solution didn’t work for me though, because I’m working on a project with a mate and he is using Eclipse with the default LibGDX project setup explained here.

Now, if you want to keep the two separate data folders but also keep their files automatically in sync, there’s an elegant way to do this using Ant.

Solution 2 using Ant

In this solution both projects keep their own “data” folder but their files are automatically synced right before the project is run with the help of a small Ant task.

  • Right-click your Android project and select “New > File”
  • Name it “build.xml”
  • Paste the following content into the newly created “build.xml”
<project name="Your Project Name here" basedir="." default="refreshAssets">
  <property name="from.dir"  value="../glowjump_java/data"/>
  <property name="to.dir"     value="./assets/data"/>

  <target name="refreshAssets">
    <copy todir="${to.dir}">
      <fileset dir="${from.dir}"/>
    </copy>
  </target>
</project>
  • Now go to “Run > Edit Configurations…”
  • Select your Android Run Configuration and check “Run Ant target” at the bottom
  • Click on “…” and select the newly created Ant task called “refreshAssets”

This task is now executed every time you launch the Android application. Meaning that the files in the data folder are copied from the Desktop project to the Android project right before launch.

For more info about the copy command in Ant see here.

Solution 3 using a symlink (Windows)

The third and probably easiest solution is to create a Windows symlink called “data” inside the Android “assets” folder. This symlink will point to the “data” folder of your Desktop project.

  • In your FileExplorer navigate inside your LibGDX Android project folder
  • Right-click the “assets” folder and select “Open command window here”
  • In the command prompt enter mklink /D data "..\..\your_libgdx_desktop_project_folder_name\data
  • On success the following message should be displayed symbolic link created for data <<===>> ..\..\your_libgdx_desktop_project_folder_name\data
  • Refresh the project view in IntelliJ IDEA
  • You should now see the data symlink as a normal folder containing the files of your desktop project

Please feel free to ask questions in the comments!