I’m trying to create an Android project with a game inside of that project. I found a Java development game framework called LibGDX
. When I was trying to use it, I got several problems. First, Inside a class that extends ApplicationAdapter
in the core
module, I’m unable to call all of the Java object like String
, error said:
Cannot resolve symbol 'String'
The second problem is all of the Gdx
object having some errors like:
Cannot access java.lang.Object
Cannot resolve constructor 'Texture(java.lang.String)'
The weird thing: with the second problem I can still installing and running it.
I have been trying to fix the Gradle
but it doesn’t work. This is my build.gradle
buildscript {
repositories {
mavenLocal()
mavenCentral()
gradlePluginPortal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = "TestGame"
gdxVersion = '1.10.0'
roboVMVersion = '2.3.12'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.3'
aiVersion = '1.8.2'
gdxControllersVersion = '2.1.0'
}
repositories {
mavenLocal()
mavenCentral()
google()
gradlePluginPortal()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":android") {
apply plugin: "com.android.application"
configurations { natives }
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
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"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.+'
testImplementation 'commons-logging:commons-logging:1.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
}
project(":core") {
apply plugin: "java-library"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
}
}
The Class:
public class TestGame extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
@Override
public void create () {
batch = new SpriteBatch();
img = new Texture("badlogic.jpg");
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, 0, 0);
batch.end();
}
@Override
public void dispose () {
batch.dispose();
img.dispose();
}
}
Any suggestions?
Perhaps this is a basic question, but this LibGDX
stuff is somewhat Greek to me.
2
Answers
I’ve had this problem before and this solution worked for me. Go to your gradle.properties file. Write
org.gradle.java.home=C:/Program Files/Java/jdk-11.0.12
or wherever your JDK folder is located like org.gradle.java.home=(wherever your jdk FOLDER is). I also found this post online that shows a similar problem but it is specifically for IntelliJ and maybe Android Studio so this might not work for you. This solution might not work if you are not using the libGDX setup since it is only tested on that. I am also very new to libGDX. https://intellij-support.jetbrains.com/hc/en-us/community/posts/207039495-Cannot-resolve-symbol-String-. This post is old though
Yes-yes I had been spent two days resolving this issue.
In my case, I just updated Android Studio and all works well.