【问题标题】:android studio/intellij IDEA with libgdx error 'compilation completed with 16 errors' 'Error:(3, 24) java: package com.badlogic.gdx does not exist'android studio/intellij IDEA 与 libgdx 错误“编译完成,出现 16 个错误”“错误:(3, 24) java: com.badlogic.gdx 包不存在”
【发布时间】:2017-07-03 07:08:07
【问题描述】:

使用 libgdx 创建项目后,通过使用 android studio/intellij IDEA 打开/导入,我在尝试 google 和其他堆栈时都遇到相同的错误,但答案没有帮助。

我的 gradle 构建

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"
}

【问题讨论】:

  • 刷新依赖?
  • 是刷新 gradle/reimported/restarted 项目但没有变化

标签: android intellij-idea libgdx


【解决方案1】:

您的类路径中似乎缺少gdx.jar

使用Import project 而不是Open an existing AS project

然后点击 Gradle Project 菜单顶部的Refresh all Gradle project(两个圆形箭头)。

对于 Gradle 项目菜单使用:

MenuBar 的菜单View -> Tools Windows -> Gradle


创建一个全新的项目:

  1. 点击运行gdx-setup.jar,也可以使用cmd

  2. 用所需的值填充所有文本字段。

  3. 选择您想要在项目中使用的子项目。

  4. 如果您需要分机选择。

  5. 点击Advanced按钮并选择IDEA并点击保存。

  6. 生成。

成功创建项目后,在 Android Studio/IntellijIDEA 中导入*您的项目。导入时选择项目的根级build.gradle文件。

*第 1st 次导入项目时需要良好的互联网连接。

【讨论】:

    【解决方案2】:

    它对我有用

    1. 在杀毒软件中关闭防火墙(avast)
    2. 打开cmd 进入根文件夹,并使用此命令 gradlew clean build

    截图here is the cmd command for gradle to download dependencies

    【讨论】:

      猜你喜欢
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 2013-05-16
      • 2021-06-24
      • 2014-06-22
      • 1970-01-01
      • 1970-01-01
      • 2020-05-23
      相关资源
      最近更新 更多