简体   繁体   中英

android studio/intellij IDEA with libgdx error 'compilation completed with 16 errors' 'Error:(3, 24) java: package com.badlogic.gdx does not exist'

after creating project with libgdx, by opening/importing with both android studio/intellij IDEA i get same errors on both of them tried google and other stack,s answers didn't helped.

Android Studio错误

intellij IDEA错误

my gradle build

buildscript {

  repositories {
      mavenLocal()
      mavenCentral()
      maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
      jcenter()
  }

  dependencies {

  }
}

allprojects {
apply plugin: "eclipse"
apply plugin: "idea"

version = '1.0'
ext {
    appName = "my-gdx-game"
    gdxVersion = '1.9.6'
    roboVMVersion = '2.3.1'
    box2DLightsVersion = '1.4'
    ashleyVersion = '1.7.0'
    aiVersion = '1.8.0'
}

repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url "https://oss.sonatype.org/content/repositories/releases/"       }
  }
 }

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


   dependencies {
       compile project(":core")
       compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
       compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
    compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
    compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
    compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"

      }
    }

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


   dependencies {
      compile "com.badlogicgames.gdx:gdx:$gdxVersion"
      compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
      compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
      compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
      compile "com.badlogicgames.gdx:gdx-ai:$aiVersion"

   }
  }

tasks.eclipse.doLast {
    delete ".project"
}

Seems like the gdx.jar is missing in your classpath.

Use Import project instead of Open an existing AS project .

Then click Refresh all Gradle project (two circular arrow) that is available on top of Gradle Project menu.

For Gradle Project Menu use :

MenuBar's menu View -> Tools Windows -> Gradle


Create a fresh new project :

  1. run gdx-setup.jar by click or you can use cmd

  2. Fill all Textfield with required value.

  3. Select Sub Projects that you want in your project.

  4. If you need extension select.

  5. Click Advanced button and select IDEA and click Save.

  6. Generate.

After successful creation of your project, import * your project in Android Studio/IntellijIDEA. Select root level build.gradle file of project at the time of import.

* Required good internet connection while you importing your project 1 st time.

It worked for me

  1. Turning off fire wall in antivirus(avast)
  2. Opening cmd going to root folder, and used this command gradlew clean build

Screen shot here is the cmd command for gradle to download dependencies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM