1

I am setting up to develop an libGDX Android app on Windows 10, latest Eclipse Mars.2, latest Android SDK and latest version of libGDX. I am following the setup instructions from here: Project Setup Gradle

and here:

Setting up your Development Environment (Eclipse, Intellij IDEA, NetBeans)

and here

Gradle and Eclipse

I when I run my android app it crashes with output in logcat:

04-09 02:01:56.357: E/Trace(20747): error opening trace file: No such file or directory (2)
04-09 02:01:56.367: D/ActivityThread(20747): setTargetHeapUtilization:0.25
04-09 02:01:56.367: D/ActivityThread(20747): setTargetHeapIdealFree:8388608
04-09 02:01:56.367: D/ActivityThread(20747): setTargetHeapConcurrentStart:2097152
04-09 02:01:56.548: W/dalvikvm(20747): Unable to resolve superclass of Lcom/mygdx/game/AndroidLauncher; (3)
04-09 02:01:56.548: W/dalvikvm(20747): Link of class 'Lcom/mygdx/game/AndroidLauncher;' failed
04-09 02:01:56.548: W/dalvikvm(20747): threadid=1: thread exiting with uncaught exception (group=0x41367438)
04-09 02:01:56.568: E/AndroidRuntime(20747): FATAL EXCEPTION: main
04-09 02:01:56.568: E/AndroidRuntime(20747): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mygdx.game/com.mygdx.game.AndroidLauncher}: java.lang.ClassNotFoundException: com.mygdx.game.AndroidLauncher
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2005)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.app.ActivityThread.access$600(ActivityThread.java:138)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.os.Looper.loop(Looper.java:137)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.app.ActivityThread.main(ActivityThread.java:4921)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at java.lang.reflect.Method.invokeNative(Native Method)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at java.lang.reflect.Method.invoke(Method.java:511)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at dalvik.system.NativeStart.main(Native Method)
04-09 02:01:56.568: E/AndroidRuntime(20747): Caused by: java.lang.ClassNotFoundException: com.mygdx.game.AndroidLauncher
04-09 02:01:56.568: E/AndroidRuntime(20747):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.app.Instrumentation.newActivity(Instrumentation.java:1056)
04-09 02:01:56.568: E/AndroidRuntime(20747):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1996)
04-09 02:01:56.568: E/AndroidRuntime(20747):    ... 11 more

Any idea on what I am doing wrong?

Here is my android code which unchanged and generated by the libGDX setup process.

package com.mygdx.game;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.mygdx.game.MyGdxGame;

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        initialize(new MyGdxGame(), config);
    }
}

Here's my AndroidManifest.xml (again unchanged by be at all)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mygdx.game"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/GdxTheme" >
        <activity
            android:name="com.mygdx.game.AndroidLauncher"
            android:label="@string/app_name" 
            android:screenOrientation="landscape"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Here is the gradle.build in the android directory, also unchanged by me.

android {
    buildToolsVersion "23.0.3"
    compileSdkVersion 23
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        instrumentTest.setRoot('tests')
    }
    defaultConfig {
        applicationId "com.mygdx.game"
        minSdkVersion 8
        targetSdkVersion 23
    }
}


// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() { 
    file("libs/armeabi/").mkdirs();
    file("libs/armeabi-v7a/").mkdirs();
    file("libs/arm64-v8a/").mkdirs();
    file("libs/x86_64/").mkdirs();
    file("libs/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
        if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")        
        if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
        if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
        if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
        if(outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}

task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.mygdx.game/com.mygdx.game.AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
    // ignores any nodes added in classpath.file.withXml
    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.6
        targetCompatibility = 1.6
    }

    classpath {
        plusConfigurations += [ project.configurations.compile ]        
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'       
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}

// sets up the Android Idea project, using the old Ant based build.
idea {
    module {
        sourceDirs += file("src");
        scopes = [ COMPILE: [plus:[project.configurations.compile]]]        

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance();
                builder.current = node;
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES", value:"true")
                        }
                    }
                }
            }
        }
    }
}

If I try to run the App in the debugger I get this in the logcat as soon as I try and step over the first instruction:

04-09 19:23:54.285: D/AndroidRuntime(2419): Shutting down VM
04-09 19:23:54.286: E/AndroidRuntime(2419): FATAL EXCEPTION: main
04-09 19:23:54.286: E/AndroidRuntime(2419): Process: com.mygdx.game, PID: 2419
04-09 19:23:54.286: E/AndroidRuntime(2419): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mygdx.game/com.mygdx.game.AndroidLauncher}: java.lang.ClassNotFoundException: Didn't find class "com.mygdx.game.AndroidLauncher" on path: DexPathList[[zip file "/data/app/com.mygdx.game-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mygdx.game-1/lib/x86_64, /data/app/com.mygdx.game-1/base.apk!/lib/x86_64, /vendor/lib64, /system/lib64]]
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.app.ActivityThread.-wrap11(ActivityThread.java)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.os.Handler.dispatchMessage(Handler.java:102)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.os.Looper.loop(Looper.java:148)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.app.ActivityThread.main(ActivityThread.java:5417)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at java.lang.reflect.Method.invoke(Native Method)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-09 19:23:54.286: E/AndroidRuntime(2419): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mygdx.game.AndroidLauncher" on path: DexPathList[[zip file "/data/app/com.mygdx.game-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mygdx.game-1/lib/x86_64, /data/app/com.mygdx.game-1/base.apk!/lib/x86_64, /vendor/lib64, /system/lib64]]
04-09 19:23:54.286: E/AndroidRuntime(2419):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
04-09 19:23:54.286: E/AndroidRuntime(2419):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
04-09 19:23:54.286: E/AndroidRuntime(2419):     ... 9 more
04-09 19:23:54.286: E/AndroidRuntime(2419):     Suppressed: java.lang.NoClassDefFoundError: com.mygdx.game.AndroidLauncher
04-09 19:23:54.286: E/AndroidRuntime(2419):         at dalvik.system.DexFile.defineClassNative(Native Method)
04-09 19:23:54.286: E/AndroidRuntime(2419):         at dalvik.system.DexFile.defineClass(DexFile.java:226)
04-09 19:23:54.286: E/AndroidRuntime(2419):         at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
04-09 19:23:54.286: E/AndroidRuntime(2419):         at dalvik.system.DexPathList.findClass(DexPathList.java:338)
04-09 19:23:54.286: E/AndroidRuntime(2419):         at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
04-09 19:23:54.286: E/AndroidRuntime(2419):         ... 13 more
04-09 19:23:54.286: E/AndroidRuntime(2419):     Suppressed: java.lang.ClassNotFoundException: com.mygdx.game.AndroidLauncher
04-09 19:23:54.286: E/AndroidRuntime(2419):         at java.lang.Class.classForName(Native Method)
04-09 19:23:54.286: E/AndroidRuntime(2419):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
04-09 19:23:54.286: E/AndroidRuntime(2419):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
04-09 19:23:54.286: E/AndroidRuntime(2419):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
04-09 19:23:54.286: E/AndroidRuntime(2419):         ... 12 more
04-09 19:23:54.286: E/AndroidRuntime(2419):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Red Cricket
  • 9,762
  • 21
  • 81
  • 166
  • It seems that you are not proper loading texture badlogic.jpg or have wrong path to file. Could you post some code, where you creating/initializing ? – Tony Danilov Apr 09 '16 at 09:53
  • Make sure that you can find the file in your assets folder in whatever project folder you're currently in. – Eames Apr 09 '16 at 11:02
  • You'd probably want to look in the Android, Core, and Desktop project folders (I'm talking about "badlogic.jpg" btw) – Eames Apr 09 '16 at 11:03

3 Answers3

1

By default, your libgdx asset "badlogic.jpg" is located in "project_direcotry/android/assets".

That error occures when you didn't set the working directory properly, which causes you application to be unable to find data files. To fix this you need to set your working directory properly.

check this link, if you are using intelij idea or android studio (which is based off of idea): Libgdx project Exception in thread "LWJGL Application". Couldn't load file. Error log inside

check this, if you are using eclipse: "File not found" when running new LibGDX project

Community
  • 1
  • 1
Fish
  • 1,689
  • 1
  • 18
  • 28
0

I only had this problem with Eclipse. When I followed the setup instructions for Android Studio the issue did not occur.

Red Cricket
  • 9,762
  • 21
  • 81
  • 166
0

The com.badlogic.gdx.backends.android.AndroidApplication class not found issue happens in eclipse, you have to check the Project and External Dependencies in the Order and Export tab in the Java Build Path section of the project properties.

The project will work and run on android after that.

Working example