3

So this question is not out of necessity, I am just looking for a more elegant way to present the very first game I made to my friends.

When I export the game, it definitely works when all assets are in the same folder. However I also noticed when no assets are there, the first screen of the game still loads which had a background image. So somehow the background image for my first screen(a simple login screen) is probably incoparated with the jar file. When I switch to any other screen that would include a new asset, it crashes so other images I have are not in the jar file.

This situation let me think that there might be a way to put all my assets into one jar file(just like the background image I had) so that I will have a more elegant final product. Is there any way to do it?

I use AssetManager, I have already tried importing all other images next to the line where I import background image on login screen but it did not help. In fact for some reason, when I try that the game does not even include the first background image so it crashes even before login screen.

I would be grateful if anyone has a such experience or a knowledge that could point me into right direction.

Update: So far problem seems to be only about very few of the images and sounds. So for some reason(maybe size or dimension) AssetManager seems to need only some of the assets in the same directory that the jar is run.

ozgeneral
  • 6,079
  • 2
  • 30
  • 45

1 Answers1

3

If you want to export standalone jar from desktop module.

Libgdx uses gradle for project building so Hopefully you're using gradle and IntellijIDEA or Android Studio as IDE.

Open Terminal

View -> Tool Windows-> Terminal or Alt+ F12

run command on window

gradlew desktop:dist

run command on mac

./gradlew desktop:dist

It will put all your asset from your assets folder of android module into your jar.

Your can find your jar in desktop module.

Edit

You can also create your jar with Artifact

File -> Project Structure -> Artifacts -> Add(+) -> Jar -> From module and dependencies ->

Module : desktop Main Class : DesktopLauncher

then OK

In OutputLayout tab -> Add Copy of(+) -> Directory Content -> Choose your Android Assets folder -> Apply -> Ok

Then Build -> BuildArtifacts. -> desktop.jar -> build

Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65
  • I am at the main directory of the project and I had gradlew: command not found. Should I be installing something for it? (using mac btw) – ozgeneral Feb 19 '17 at 11:23
  • nvm just read this http://stackoverflow.com/questions/27094492/how-to-run-gradle-from-the-command-line-on-mac-bash, going to try now – ozgeneral Feb 19 '17 at 11:25
  • 1
    I am using above command on window. Have you tried your link. – Abhishek Aryan Feb 19 '17 at 11:38
  • FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':core:compileJava'. > Compilation failed; see the compiler error output for details. – ozgeneral Feb 19 '17 at 11:42
  • Have no idea what this means: Received result Failure[value=org.gradle.initialization.ReportedException: org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':core:compileJava'.] from daemon DaemonInfo{pid=32186, address=[dff5876f-b29e-490d-ac21-f74cc968b62a port:56263, addresses:[/0:0:0:0:0:0:0:1, /127.0.0.1]], idle=true, context=DefaultDaemonContext[uid=e716ba8f-26f8-4805-b9d7-59433b545881,javaHome=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home,daemonRegistryDir=/Users/MIKE/.gradle/daemon,...(too long to paste here)]} (build should be done). – ozgeneral Feb 19 '17 at 11:43
  • Looked with --debug option and found out this, probably its not able to find one of the dependencies error: package com.apple.eawt.AppEvent does not exist – ozgeneral Feb 19 '17 at 12:33
  • I was just able to get around the error, I just got rid of the import in my code and handled it in a different way. Now I get build successful but I cant find any executable/jar anywhere – ozgeneral Feb 19 '17 at 13:05
  • 1
    dektop module -> build -> libs -> desktop-1.0.jar in my window. check your's in mac – Abhishek Aryan Feb 19 '17 at 13:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/136071/discussion-between-oe1-and-abhishek-aryan). – ozgeneral Feb 19 '17 at 13:09
  • @OE1 Please post a new question. – Code-Apprentice Feb 19 '17 at 16:57
  • Sure, since I have more idea on what might be related, I also added AssetManager related code as well. http://stackoverflow.com/questions/42330261/assetmanager-needs-some-of-the-assets-in-the-same-folder-when-exported-into-jar – ozgeneral Feb 19 '17 at 17:14