I am writing an Android game, but when building i get this error. I am using IntelliJ and have all libraries installed via Gradle, the IDE sees them, but compiler doesn’t. Any help appreciated!
Are you able to provide a simple example application? Including the build.gradle files (Did you start from the https://start.jmonkeyengine.org? Not that you need to, but a useful reference)
No, i did not use the initializer. I took the code from https://github.com/Electrostat-Lab/jme3-Simple-Examples.git and changed the package name.
MainActivity.java
package com.example.game;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.Menu;
import androidx.annotation.Nullable;
import com.jme3.app.AndroidHarness;
import java.util.Objects;
/**
* <b>NB: Please Open this example <u>root module</u> using Android Studio; because android build scripts are different from java builds.</b>
* <br>
* An Example Class that demonstrates the usage of #{@link AndroidHarness} to render a jme game inside android.
* <br>
* Steps :
* <ol>
* <li>Create a class extending #{@link AndroidHarness} as your #{@link android.app.Activity} class that holds the #{@link android.opengl.GLSurfaceView}
* with its #{@link android.opengl.GLSurfaceView.Renderer} to render a jme game</li>
* <li>Specify the directory of your game class package inside #{@link AndroidHarness#appClass} using #{@link Class#getName()}</li>
* <li>That's it, and magic comes into play :-)</li>
* </ol>
*
* @author pavl_g
*/
public final class MainActivity extends AndroidHarness {
public MainActivity() {
/*get the jme class dir*/
appClass = Objects.requireNonNull(MyGame.class.getName());
}
@Override
protected void onDestroy() {
super.onDestroy();
System.err.println("OnDestroy invoked");
}
}
MyGame.java
package com.example.game;
import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetKey;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.debug.WireSphere;
/**
* <b>Your JmeGame class</b>
*
* @author pavl_g
*/
public final class MyGame extends SimpleApplication {
@Override
public void simpleInitApp() {
final WireSphere wireSphere = new WireSphere(50);
final Geometry geometry = new Geometry("wireSphere", wireSphere);
geometry.setLocalScale(0.05f);
final Material material = new Material(assetManager.loadAsset(new AssetKey<>("Common/MatDefs/Misc/Unshaded.j3md")));
material.setColor("Color", ColorRGBA.randomColor().mult(2f));
geometry.setMaterial(material);
rootNode.attachChild(geometry);
}
}
build.gradle.kts
plugins {
java
id("com.android.application") version "8.2.0" apply false
}
dependencies {
implementation("org.jmonkeyengine:jme3-core:3.6.1-stable")
implementation("org.jmonkeyengine:jme3-effects:3.6.1-stable")
implementation("org.jmonkeyengine:jme3-android-native:3.6.1-stable")
}
Solved! The problem occured because dependencies were declared in the global build file instead of a module-specific. Thank you, @richtea, for reminding about jMonkey Initializer!
3 Likes