0
votes

I used the GDX setup to create my project structure with its library alredy included but after I try call an Intent from Android Library I noticed it could not find the class even the library path. Look that screnshot:

Android-library-error.png

Then I started a new project by Android Studio itself and pretty worked as well:

Intent-working.png

As you can see it looks like gradle problem setting. Then I tried to fix it myself but I could not.

I know to add a library we need to code some dependences even if I remove the GDX dependence it will cause same error. But Android must not need to be added, then I dont know how to add and if will work.

GDX dependence is writen here:

    project(":core") {
apply plugin: "java"


dependencies {
    compile "com.badlogicgames.gdx:gdx:$gdxVersion"
    // If I remove that line it will causes same error
} [...]

I made some comparation between GDX and Android Studio:

GDX made:

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {

        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
    }
}

Android Studio made:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

I'm using 3.0.1 Android Studio version.

1

1 Answers

1
votes

You are missing one core aspect of libGDX as a cross-platform solution. You can't call platform specific code from your core module, because it does not know anything about a specific platform like Android.

Good to see is that in the core module are no android specific libraries included, and thats whats intendet.

   project(":core") {
    apply plugin: "java"
    dependencies {
    compile "com.badlogicgames.gdx:gdx:$gdxVersion"
   } 


As you can see here is that there are includes of libraries specific for the android platform and a include of the code module.

project(":android") {
  apply plugin: "android"

  configurations { natives }

  dependencies {

    compile project(":core")
    compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
  }
}

That means:
- Android has all access to everything in the core module and within its own module
- Core has only access to everything within its own module, nothing above

Click here or here to inform yourself about how to deal with your situation.