Question

I have just created template Libgdx project (Core,Android,Windows). Core is regular Java project library. There is a dependency in Core to XStream.jar library. Core contains file input-output via Xml. Android project has dependency to java core project.

Now XStraem is working for Windows but not for Android. For Android i got this:

01-22 13:03:24.141: E/AndroidRuntime(25074): FATAL EXCEPTION: GLThread 5187
01-22 13:03:24.141: E/AndroidRuntime(25074): Process: com.barsoft.drag, PID: 25074
01-22 13:03:24.141: E/AndroidRuntime(25074): java.lang.NoClassDefFoundError: com.thoughtworks.xstream.XStream
01-22 13:03:24.141: E/AndroidRuntime(25074):    at com.barsoft.drag.managers.XmlManager.loadFromFileAutoType(XmlManager.java:29)
01-22 13:03:24.141: E/AndroidRuntime(25074):    at com.barsoft.drag.managers.ObjectManager.createObjectAutoType(ObjectManager.java:66)
01-22 13:03:24.141: E/AndroidRuntime(25074):    at com.barsoft.drag.Game.create(Game.java:36)
01-22 13:03:24.141: E/AndroidRuntime(25074):    at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:334)
01-22 13:03:24.141: E/AndroidRuntime(25074):    at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1512)
01-22 13:03:24.141: E/AndroidRuntime(25074):    at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

If I am adding library to the build path in Android project i got:

[2014-01-22 13:23:06 - Dex Loader] Unable to execute dex: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;
[2014-01-22 13:23:06 - drag-android] Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lorg/xmlpull/v1/XmlPullParser;

The same stuff is when I check libraries in Core -> Order and Export

From LibGDX doc about creating core project:

  1. Main project setup Create a new Java project in Eclipse: File -> New -> Project -> Java Project. Give it a name and click Finish.

  2. Go to the project folder on the file system and create a sub-folder named libs. Download the nightly zip and place gdx.jar and gdx-sources.jar in the libs folder.

  3. In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select gdx.jar and click OK.

  4. Under the gdx.jar file, double click "Source attachment", click Workspace, select the gdx-sources.jar and click OK.

  5. Click the Order and Export tab, check the gdx.jar and click OK.

Note: Step 5 makes gdx.jar a transitive dependency. That means that projects that depend on the main project will also have gdx.jar on their classpath. However, this doesn't work for Android projects.

Does that mean that any dependency included within Java core project won't work on Android? Is there a way to get XStream transit lib working?

Was it helpful?

Solution

If the library is supported on Android, it will work.

Put it in the Core project's "libs" folder. Add it to its Order & Export tab.

Add it to the Libraries tab of the Android Project. ("Add jars", not "Add external jars") And then check it in the Order & Export tab aswell.

That means that projects that depend on the main project will also have gdx.jar on their classpath. However, this doesn't work for Android projects.

This just means that the libraries in the classpath of the Core project aren't automatically added to the Android project (As far as I know, some time ago it did).

If you get the Multiple dex files error. Uncheck private libraries in the Order & Export tab of the Android project.

OTHER TIPS

You need to fix your

compile fileTree(dir: 'libs', include: '*.jar')

line. If your libs folder is in core project's folder, add above line to

project(":core") {...

    dependencies {....
        compile fileTree(dir: 'libs', include: '*.jar')
    }
}

part of your build.gradle file. And add below line to your Android project's part in the build.gradle file.

project(":android") {...

    dependencies {....
        compile fileTree(dir: '../libs', include: '*.jar')
    }
}

Android must have this line but it is not necessary for other projects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top