Next up, you need to import your project into your IDE.

Importing & Running - 图1

Importing the Project

  1. In IntelliJ IDEA or Android Studio, you can choose to open the build.gradle file and select “Open as Project” to get started.

    In Eclipse, choose File -> Import... -> Gradle -> Existing Gradle Project (make sure that your freshly generated project is not located inside of your workspace).

    In NetBeans it is File -> Open Project.

  2. You may need to refresh the Gradle project after the initial import if some dependencies weren’t downloaded yet.

    In IntelliJ IDEA/Android Studio, the Reimport all Gradle projects button is a pair of circling arrows at the top left in the Gradle tool window, which can be opened with View -> Tool Windows -> Gradle.

    In Eclipse right click on your project Gradle -> Refresh Gradle Project.

Getting it Running

If you want to execute your freshly imported project, you have to follow different steps, depending on your IDE and the platform you are targeting.

Desktop

In IDEA/Android Studio:

  1. Extend the Gradle tab on the right sight of your window:
    Importing & Running - 图2
  2. Expand the tasks of your project and then select: desktop -> other -> run.

Alternatively, you can create a run configuration:

  1. Right click your DesktopLauncher class
  2. Select ‘Run DesktopLauncher.main()’. This should fail with missing assets, because we need to hook up the assets folder first.
  3. Open up Run Configurations
    Importing & Running - 图3
  4. Edit the Run Configuration that was just created by running the desktop project and set the working directory to point to your core/assets folder (or android/assets if you are using an Android subproject)
    Importing & Running - 图4
  5. Run your application using the run button

In Eclipse:

  1. Right click your desktop project -> Run as -> Run Configurations…
  2. On the right side, select Java Application:
    Importing & Running - 图5
  3. At the top left, click the icon to create a new run configuration: Importing & Running - 图6
  4. As Main class select your DesktopLauncher class
  5. After that, click on the Arguments tab
  6. At the bottom, under ‘Working directory’ select ‘Other’ -> Workspace… Importing & Running - 图7
  7. Then select your asset folder located in core/assets (or android/assets if you are using an Android subproject)

In NetBeans:

Right click the desktop project -> Run

Android

  • IDEA/Android Studio: Right click AndroidLauncher -> Run AndroidLauncher
  • Eclipse: Right click Android project -> Run As -> AndroidApplication
  • NetBeans: Right click Android project -> Run As -> AndroidApplication

iOS

In IDEA/Android Studio

  1. Open Run/Debug Configurations
  2. Create a new run configuration for a RoboVM iOS application

Importing & Running - 图8

  1. Select the provisioning profile and simulator/device target
  2. Run the created run configuration

For more information on using and configuring the RoboVM IntelliJ plugin please see the documentation.

In Eclipse

  • Right click the iOS RoboVM project > Run As > RoboVM runner of your choice

Importing & Running - 图9

For more information on using and configuring the RoboVM IntelliJ plugin please see the documentation.

HTML

HTML is best suited to be run on command line. You are welcome to manually setup GWT in the IDE of your choice if you are familiar with it, but the recommended way is to drop down to terminal or command prompt.

The HTML target can be run in Super Dev mode, which allows you to recompile on the fly, and debug your application in browser.

To do so, open up your favourite shell or terminal, change directory to the project directory and invoke the respective gradle task:

  1. ./gradlew html:superDev

On Unix: If you get a permission denied error, set the execution flag on the gradlew file: chmod +x gradlew

You should see lots of text wizzing by, and if all goes well you should see the following line at the end:

Importing & Running - 图10

You can then go to http://localhost:8080/index.html, to see your application running, with a recompile button.

For further info on configuring and debugging with SuperDev check the GWT documentation.

Command Line

All the targets can be run and deployed to via the command line interface.

Desktop:

  1. ./gradlew desktop:run

Android:

  1. ./gradlew android:installDebug android:run

The ANDROID_HOME environment variable needs to be pointing to a valid android SDK before you can do any command line wizardry for Android. On Windows, use: set ANDROID_HOME=​C:/Path/To/Your/Android/Sdk; on Linux and macOS: export ANDROID_HOME=​/Path/To/Your/Android/Sdk. Alternatively you can create a file called “local.properties” with the following content: sdk.dir /Path/To/Your/Android/Sdk.

iOS:

  1. ./gradlew ios:launchIPhoneSimulator

HTML:

  1. ./gradlew html:superDev

Then go to http://localhost:8080/index.html.

Gradle tasks are failing?

If whenever you invoke Gradle, the build or refresh fails to get more information, run the same command again and add the --debug parameter to the command, e.g.:

  1. ./gradlew desktop:run --debug

This will provide you with a stacktrace and give you a better idea of why gradle is failing.

What to do next?

Now that you’re done with the set up, you can get to do some real coding. Take a look at our post A Simple Game for a step-by-step guide.