Project setup Guide: Java 1.7 currently causes problems with Android

View: 706    Dowload: 0   Comment: 0   Post by: daii   Category: Mobile applications   Fields: Game - Entertainment

9 point/4 review File has been tested

Attention: this is extremely outdated and NOT supported anymore! Please use the Gradle-based setup instead

Note: Java 1.7 currently causes problems with Android. Please make sure your project uses Java 1.6Note: use of setup-ui is highly recommended if you want to deploy to iOS

This page describes how to configure Eclipse to develop and run libgdx applications on both the desktop and Android.

Main project setup

  1. Create a new Java project in Eclipse: File -> New -> Project -> Java Project. Give it a name and click Finish.
  2. Go to the project folder on the file system and create a sub-folder named libs. Download the libgdx-nightly-latest.zip and place gdx.jar and gdx-sources.jar in the libs folder.
  3. In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select gdx.jar and click OK.
  4. Under the gdx.jar file, double click "Source attachment", click Workspace, select the gdx-sources.jar and click OK.
  5. Click the Order and Export tab, check the gdx.jar and click OK.

Note: Step 5 makes gdx.jar a transitive dependency. That means that projects that depend on the main project will also have gdx.jar on their classpath. However, this doesn't work for Android projects.

Desktop project setup

  1. Create a new Java project in Eclipse: File -> New -> Project -> Java Project. Name it appropriately (e.g., "gamename-desktop") and click Finish.
  2. Go to the project folder on the file system and create a subfolder named libs. From thelibgdx-nightly-latest.zip, place gdx-natives.jargdx-backend-lwjgl.jar and gdx-backend-lwjgl-natives.jar in the libs folder.
  3. In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select the three JARs, and click OK.
  4. Click the Projects tab, click Add, check the main project, and click OK.

Android project setup

Before doing these steps, the Android SDK must first be installed.

  1. Create a new Android project in Eclipse: File -> New -> Project -> Android Project. Name it appropriately (e.g., "gamename-android"). For build target, check "Android 1.5". Specify a package name (e.g., "com.gamename"). Next to "Create Activity" enter "AndroidGame". Click Finish.
  2. Go to the project folder on the file system and create a subfolder named libs. From thenightly zip, place gdx-backend-android.jar and the armeabi and armeabi-v7a folders in the libs folder.
  3. In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select gdx-backend-android.jar and click OK.
  4. Click Add JARs again, select gdx.jar under the main project and click OK.
  5. On the Projects tab: click Add, check the main project, and click OK.
  6. On the Order and Export tab: check the main project.

Note: The folder really must be called "libs", a naming convention forced on us by the Android Eclipse plugin.

Asset folder setup

The Android project has a subfolder named assets, which is created automatically. Files available to the Android application must be placed here. This is problematic, because these same files must be available to the desktop application. Rather than maintain two copies of all the files, the desktop project should be configured to find the assets in the Android project:

  • In the Properties for the core project: click the Source tab, click Link Source, Browse, select the "assets" folder from your Android project and click OK.
  • Specify "assets" for the folder name and click Finish then OK.

Note: If your desktop and Android projects are in the same parent folder, you can use "PARENT-1-PROJECT_LOC/gamename-android/assets" for the location of the linked assets folder, where "gamename-android" is the name of your Android project. This is better than a hard-coded path if you plan on sharing your projects with others.

Creating a game

In your main project, create a new class: right click the project -> New -> Class. Name it "Game" and specify a package (eg, "com.gamename"). Next to Interfaces, click Add, chooseApplicationListener, and click OK. It will look like this:

import com.badlogic.gdx.ApplicationListener;

public class Game implements ApplicationListener {
    public void create () {
    }

    public void render () {
    }

    public void resize (int width, int height) {
    }

    public void pause () {
    }

    public void resume () {
    }

    public void dispose () {
    }
}

These methods allow you to setup and render your game. Since they are empty, this particular game is simply a blank screen. We will first get this simple game running before doing something more interesting.

Running the game on the desktop

Right click the desktop project -> New -> Class. Name it DesktopGame and specify a package (eg, "com.gamename"). Click OK. Make the class look like this:

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;

public class DesktopGame {
    public static void main (String[] args) {
        new LwjglApplication(new Game(), "Game", 480, 320);
    }
}

This code creates an LwjglApplication, gives it an instance of your game, a title, and size.

To run the game on the desktop, right click the project -> Debug As -> Java Application. You should get a black window titled "Game".

Running the game on Android

Open the AndroidGame class in the Android project that was automatically created and make it look like this:

import com.badlogic.gdx.backends.android.AndroidApplication;

public class AndroidGame extends AndroidApplication {
    public void onCreate (android.os.Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initialize(new Game());
    }
}

This code is an Android activity that calls initialize, passing an instance of your game.

To run the game on Android, right click the project -> Debug As -> Android Application. The screen will turn black, since the game doesn't yet do anything. If any errors occur running the application, they show up in the Logcat view, which can be seen by clicking Window -> Show View -> Other -> Android -> Logcat.

Updating libgdx

At some point you may want to update libgdx to the latest. To do this, download the libgdx-nightly-latest.zip again and update these files in your projects:

Project Files
main libs/gdx.jar
libs/gdx-sources.jar
Android libs/gdx-backend-android.jar
libs/armeabi (directory)
libs/armeabi-v7a (directory)
desktop libs/gdx-natives.jar
libs/gdx-backend-lwjgl.jar
libs/gdx-backend-lwjgl-natives.jar

There also exists a python script that will automatically update your libraries by fetching the latest nightlies: https://github.com/jrenner/libgdx-updater

Project setup Guide: Java 1.7 currently causes problems with Android

Project setup Guide: Java 1.7 currently causes problems with Android Posted on 18-11-2016  Attention: this is extremely outdated and NOT supported anymore! Please use the Gradle-based setup instead Note: Java 1.7 currently causes problems with Android. Please make sure your project uses Java 1.6Note: use of setup-ui is highly recommended if you want to deploy to iOS 2.25/10 706

Comment:

To comment you must be logged in members.

Files with category

  • An Experience about Using Webview in Android Studio 3.0

    An Experience about Using Webview in Android Studio 3.0

    View: 10    Download: 0   Comment: 0

    Category: Android     Fields: Other

    I am blogging on ngocminhtran.com (using WordPress platform). Like most websites, I want to write an Android application to help viewers have a lot of great experiences with my blog.

  • Android - Simple Sending SMS

    Android - Simple Sending SMS

    View: 145    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    Learn on how to create a Simple Sending SMS using Android. This tutorial is only an example for sending an SMS, it does not contain the receiving message yet. Android is a mobile operating system developed by Google. It used in several gadget like...

  • Bomb Explode! (An Android App Strategy Game)

    Bomb Explode! (An Android App Strategy Game)

    View: 269    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This android app named Bomb Explode! is a capstone project that I made for a particular school. BOMB EXPLODE! is a Human Versus Computer strategy game. The objective is to eliminate the opponent by blowing up their BOMBS. Each player takes a turn by...

  • GIS App for Flood-Prone and Disease Affected Areas

    GIS App for Flood-Prone and Disease Affected Areas

    View: 294    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    GIS App for Flood-Prone and Disease Affected Areas is one of the capstone project that I have created in a particular school. Features of the application: - Geographic Map - GIS - Flood Prone Map - Urban Map - Search a particular area - Has SQLite...

  • NSO Demographic Application

    NSO Demographic Application

    View: 291    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This app is entitled NSO Demographic Application that was one of the capstone project/thesis project that I made for a particular school. This app features to provide a demographic survey of the National Statistics Office that will send to the...

  • HandEBook: An IT Portable Book Application

    HandEBook: An IT Portable Book Application

    View: 245    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    This is an android mobile application entitled HandEBook: An IT Portable Book Application was one one of the capstone project that I have made in our clients at Cotabato. We used the Basic4Android software for the frontend and SQLite for the database...

  • Publishing The Game

    Publishing The Game

    View: 118    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    To build the game go to the file menu, then choose Build Setting. Drag all the scenes in the empty box and set the platform to android as shown below. After you're done click the Player Setting, then fill up the required information in order to build...

  • Simple Game in Android

    Simple Game in Android

    View: 158    Download: 0   Comment: 0

    Category: Mobile applications     Fields: Game - Entertainment

    The is simple game developed in eclipse compatible with all screen resolution using getwidth() and getheight() function -Highscore page added -Volume control page In this game the player collects the coins by jumping and makes score. More tips:...

 
File suggestion for you
File top downloads
Codetitle.net - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.net Develope by Vinagon .Ltd