Cedric Martens Cedric Martens - 2 months ago 5
Android Question

AndroidLauncher cannot find assets, but DesktopLauncher can (Android Studio, libGDX)

I am trying to make an android app, I am using Android Studio and libGDX. The problem is that my app keeps crashing since it cannot find my sprite.

When I do :

player = new Texture(Gdx.files.local("/data/Sprites/sqr_blue.png"));

my DesktopLauncher can find the file so it works correctly, but my AndroidLauncher cannot find the file, resulting in the app crashing.

Previously I did
player = new Texture(Gdx.files.internal("/data/Sprites/sqr_blue.png"));
, but it did not work with the DesktopLauncher nor the AndroidLauncher.

If I do
it will return O:\Stuff\GameName\android\assets which is also the path I set under the working directory of the DesktopLauncher.

The absolute path of my file is O:\Stuff\GameName\android\assets\data\Sprites\sqr_blue.png

I also tried a Gradle Sync, but it did nothing to help the situation.

I am quite confused on what to do.


Do player = new Texture(Gdx.files.internal("data/Sprites/sqr_blue.png"));

Notice that there is no slash at the beginning. This little slash was breaking your path.