Code Monkey home page Code Monkey logo

libgdx-gradle-template's Introduction

libgdx-gradle-template

Notice Jan-14-2014

This incarnation of the Gradle Template is no longer under active development. Further work is being done in the main libgdx project/repo. If you'd like to contribute, you'll find development being done inside of the extensions module.

Gradle template for libgdx projects that works on the CLI, Eclipse and Intellij IDEA. This tempate will eventually replace the libgdx Setup-UI currently in use. To get started Download the template or fork and clone this repository.

A word about Gradle

Gradle is a nifty build and dependency managment system. A build system allows you to easily compile and package (potentially different versions of) your project. A dependency management system allows you to declaratively specify 3rd party libraries, which the dependency management system will pull in automatically for you. No need to put Jar files or native libraries in your project tree.

You do not need to install Gradle manually, this template uses the Gradle wrapper which takes care of that for you transparently. The first time you invoke gradle on the command line, the Gradle wrapper will automatically download and install Gradle into your home directory.

To use this template you do not need to know Gradle necessarily, pretty much everything is taken care of for you.

A word about Source Control

The contents of this repository are everything you need to commit to your source control repository. Do not commit Eclipse or IntelliJ Idea projec files, especially if other people are working on the same project. Instead, everyone just downloads this IDE-unaware project, then uses Gradle to generate local IDE project files.

Also make sure to commit the gradlew, gradlew.bat files and the gradle/ folder. This way, nobody needs to manually install Gradle on their system.

Project Structure

This template has the following structure (ignoring some directores and files in the Android project for brevity).

build.gradle                 <- main Gradle build file, add dependencies here
settings.gradle              <- definition of the sub-modules for core, desktop, Android

core/                        <- Core project
   build.gradle              <- Gradle build file for core project, no need to touch this
   src/                      <- All your game's source code goes here!
   
desktop/                     <- Desktop project
   build.gradle              <- Gradle build file for desktop project, no need to touch this
   src/                      <- the desktop project's source code, contains launcher class
   
android/                     <- Android project
   AndroidManifest.xml       <- Android specific configuration
   build.gradle              <- Gradle build file for Android project, DON'T EVER TOUCH THIS!
   assets/                   <- contains all your graphics, audio, etc. files, shared with desktop
   res/                      <- contains icons of your app and other resources
   src/                      <- the Android project's source code, contains launcher class

Command Line Usage

Before you can do anything, you need to set the ANDROID_HOME environment variable to point to your Android SDK's root folder. On Windows you can do this on the command line

set ANDROID_HOME=C:/Path/To/Your/Android/Sdk

On Linux and Mac OS X you can do this in the shell

export ANDROID_HOME=/Path/To/Your/Android/Sdk

Both commands will set the ANDROID_HOME enviroment variable for the duration of your shell session. You should set this environment variable permanently on your system. Please consult the internet for instructions.

Once you have ANDROID_HOME set, you can continue with using Gradle. On windows, you use the gradlew.bat files, which you can invoke like this:

gradlew clean

On Linux or Mac OS X you invoke gradle like this:

./gradlew clean

Note the leading dot slash on Unix like systems. In both cases, the clean task will remove all build files, e.g. class files previously generated.

Running the desktop project

To run the desktop project issue this gradle command:

./gradlew desktop:run

Packaging the desktop project

To create a ZIP distribution including shell scripts to start your app, issue this gradle command:

./gradlew desktop:distZip

This will create a ZIP file in the folder desktop/build/distributions, ready to be send to testers.

Running the Android project

To run the Android project, issues this gradle command:

./gradlew android:installDebug

This will compile the APK for Android, and install it on a connected device. You will have to start the app manually on the device.

Packaging the Android project

The android:installDebug task will create an unsigned debug APK of your app, which you can find in the android/build/apk/ folder. If you want to build a signed APK for release on the Google Play Store, please consult the Android Gradle plugin documentation

Eclipse Usage

You can let Gradle generate Eclipse projects for your application easily:

./gradlew eclipse

Once Gradle is done, delete the .project file in the root directory of the project. This is a little glitch that will get resolved shorty.

Now you can import the projects into Eclipse

  1. File -> Import ... -> General -> Existing projects into Workspace
  2. Click 'Browse', select the root folder of the project. You should see the core, android and desktop project.
  3. Make sure the three projects are checked, then click 'OK'

Running/Debugging in Eclipse

To run/debug the desktop project:

  1. Right click the desktop project in the package viewer
  2. Select either 'Run As' or 'Debug As'
  3. Select 'Java Application'

To run/debug the Android project:

  1. Right click the Android project in the package viewer
  2. Select either 'Run As' or 'Debug As'
  3. Select 'Android Application'

Intellij Idea Usage

You can let Gradle generate Intellij Idea project for your application easily:

./gradlew idea

Once Gradle is done, you can open the projects in Intellij Idea:

  1. File -> Open
  2. Select the .ipr file in the root of the project, Click 'OK'

You'll need to set the Android SDK on the Android module before continuing:

  1. File -> Project Structure ...
  2. Select 'modules' in the left side panel
  3. Select the 'android' module in the modules panel
  4. Set 'Module SDK' to the Android SDK you configured for IntelliJ Idea

Running/Debugging in Intellij Idea

To run/debug the desktop project, first create a run configuration:

  1. Run -> Edit Configurations
  2. Click the plus ('+') in the top left corner, select 'Application'
  3. Set the Name of the configuration, e.g. 'Desktop'
  4. Set the Main Class to 'DesktopLauncher', by clicking on the button on the left of the field
  5. Set the Working Directory to $root/android/assets, by clicking on the button on the left of the field
  6. Set 'Use classpath of module' to 'desktop'
  7. Click 'OK'

To run/debug the desktop project, just select the run configuration you just created and then either click the green play button, or the green play button with the bug.

To run/debug the Android project, first create a run configuration:

  1. Run -> Edit Configurations
  2. Click the plus ('+') in the top left corner, select 'Android Application'
  3. Set the Name of the configuration, e.g. 'Android'
  4. Set 'Module' to 'Android'
  5. Click 'OK'

To run/debug the desktop project, just select the run configuration you just created and then either click the green play button, or the green play button with the bug.

Dependency Management

One of the benefits of Gradle and similar systems like Maven or Ivy, is that integrating third party dependencies in your project is really simple. It also has the benfit that your project file tree doesn't contain any JAR files or other 3rd party resources, keeping things clean and tidy. Every time your or a team mate invoke a Gradle task, the dependencies of your project will get checked and updated if necessary.

How and where do you specify dependencies?

TBD see build.gradle in root for now

libgdx-gradle-template's People

Contributors

badlogic avatar ivoryfitz avatar johnnyapol avatar mobidevelop avatar timroes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libgdx-gradle-template's Issues

Can not import the gradle-template to IDEA because of inter-module reference

When I try to import the template to IDEA as a gradle project I get following error:

[  30793]   WARN - .plugins.gradle.util.GradleLog - java.lang.IllegalArgumentException: Can't register given path of type 'SOURCE' because it's out of content root.
Content root: '/tmp/libgdx-gradle-template/desktop'
Given path: '/tmp/libgdx-gradle-template/android/assets'
    at org.jetbrains.plugins.gradle.model.gradle.GradleContentRoot.storePath(GradleContentRoot.java:66)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl.populateContentRoot(GradleProjectResolverImpl.java:200)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl.populateContentRoots(GradleProjectResolverImpl.java:171)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl.populateModule(GradleProjectResolverImpl.java:142)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl.populateModules(GradleProjectResolverImpl.java:133)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl.doResolveProjectInfo(GradleProjectResolverImpl.java:82)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl.access$000(GradleProjectResolverImpl.java:36)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl$1.fun(GradleProjectResolverImpl.java:51)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl$1.fun(GradleProjectResolverImpl.java:47)
    at org.jetbrains.plugins.gradle.remote.impl.RemoteGradleServiceHelper.execute(RemoteGradleServiceHelper.java:132)
    at org.jetbrains.plugins.gradle.remote.impl.GradleProjectResolverImpl.resolveProjectInfo(GradleProjectResolverImpl.java:47)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.jetbrains.plugins.gradle.remote.impl.GradleApiFacadeImpl$1.invoke(GradleApiFacadeImpl.java:116)
    at com.sun.proxy.$Proxy3.resolveProjectInfo(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
    at sun.rmi.transport.Transport$1.run(Transport.java:177)
    at sun.rmi.transport.Transport$1.run(Transport.java:174)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

Maybe it would be an option to extract assets to separate subproject?

Question: Android SDK Versions

Foreword: I'm a complete Android newb so forgive my ignorance on this.

Trying to track down all the SDK versioning and what means what is driving me up the wall. From what I can tell, there's settings in the following places that refer to android-sdk stuff (omitting all lines I THINK are not relevant)...

android/build.gradle

android {
buildToolsVersion "17.0"
compileSdkVersion 17
}

android/project.properties

target=android-18

android/AndroidManifest.xml

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

Can someone either enlighten me as to the purpose of these different settings or point me towards the info? Do any of these things need to be kept in sync? (From my perspective they look out of sync[ie 17, 18, 19])

Side Note: It seems like the buildTools versioning does not have a 1-1 relationship with the actual SDK version, is this true? As in, is it perfectly reasonable to continue to update your buildtools version while remaining on an old SDK?

Thanks!

Build breaks with Gradle 1.8

Execution of "gradle clean" command fails with Gradle version 1.8 (the wrapper is set tu use 1.7 at the moment) with the following stack trace:

  • Where:
    Build file 'C:\HomeSpace\gradle\libgdx-gradle-template-master\libgdx-gradle-temp
    late-master\android\build.gradle' line: 37
  • What went wrong:
    A problem occurred evaluating project ':android'.

    Could not expand ZIP 'C:\Users\ob.gradle\caches\artifacts-26\filestore\com.ba
    dlogicgames.gdx\gdx-platform\0.9.9-SNAPSHOT\jar\f4d6af8931ecb83354d9ccdc51a238d9
    49da06ef\gdx-platform-0.9.9-SNAPSHOT-natives-armeabi.jar'.

Using Gradle 1.7 works Ok.

Android Studio 0.4.0 and Android Build Tools 0.7.+ incompatibility...

The template has the following lines in it:

// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
    println pkgTask
    pkgTask.jniDir new File(projectDir, 'libs')
}

Unfortunately, the latest Android tools break this functionality, so builds at the command-line seem not to have the JNI libraries present in the APK. Any ideas?

To Do's

Anywhere we can go to see what other big ticket tasks need to be accomplished? kanban board or anything? I'd love to help and have some of my own ideas but I'd rather help with predetermined goals if there are any already.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.