NoClassDefFoundError with LuaJ

568 Views Asked by At

I'm trying to use LuaJ in an Android Studio (V0.2.3) project.

I added the luaj-jme-3.0-beta.jar to the libs folder.

Under "Project Structure" libraries I added the project library luaj-jme-3.0-beta.jar.

In the build.gradle file under "dependancies" I added this line: compile files('libs/luaj-jme-3.0-beta1.jar')

In my MainActivty I call luaj:

import org.luaj.vm2.Globals;
import org.luaj.vm2.lib.jme.JmePlatform;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
  Globals globals = JmePlatform.standardGlobals();
}

Compiling is succesfull, then after uploading the apk file to the target device I got this message:

08-18 16:59:25.533  11363-11363/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: org.luaj.vm2.lib.jme.JmePlatform
at de.ibr.luaj5.MainActivity.onCreate(MainActivity.java:16)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)

I use apkananyser.jar to look in the apk file. It looks like the lua lib is not include in the apk file.

Im new to gradle, so how can I add the lua lib to the apk file? I've been Googling this for two days but I can't find a solution.

How can I solve this error?

1

There are 1 best solutions below

2
On

After adding luaj-jme-3.0-beta.jar to your Project's Structure, right click on it and select add as library.
Rest of your app seems fine, as you have added the compiling commands under the dependencies in your gradle file.

EDIT:
Please do follow these steps too, this is a common problem that you are facing.
1. While your application opened go to File => Close Project.
2. Open cmd (command promt) on your project's root location, i.e 'C:\Users\Username\AndroidStudioProjects\MyApplicationProject\'
3. On the cmd, type gradlew clean, wait till it's done processing the command.
4. Reopen your application project in Android Studio.
5. Test run your application and it should work.