sharing assets between desktop and android game

41 views
Skip to first unread message

Ruben Garat

unread,
Mar 24, 2011, 8:35:07 PM3/24/11
to maven-androi...@googlegroups.com
Hi, I am trying to make games for android an pc, using the libgdx
library http://code.google.com/p/libgdx/

this library provides abstraction that make it easy to make games that
run on both platforms with the same code.

I have a maven build working for this made of:

parent - pom with common info
- core module - just a jar with the common code
- android module - an android module using maven-android-plugin,
depends on the core
- desktop module - a jar module that depends on the core

the issue I am facing now, is how to avoid having to duplicate the
assets to work with android and desktop
right now I have the assets both in the desktop module, and in the
assets dir of the android module

One solution I see is to use a separate module for the assets, and then
declare them in some special way for the plugin to unpack into the
combined-assets/assets dir, or something like that.

Not really sure what would be the best way to signal that the artifact
contains assets and should be treated in that special way. Using a
different packaging would make it harder to use in the normal desktop
module. Perhaps declaring the artifact in the configuration of the
plugin instead of as a dependency.

thanks for your help.

Rub�n

Manfred Moser

unread,
Mar 25, 2011, 12:00:07 AM3/25/11
to maven-androi...@googlegroups.com


That should be pretty easy to do. Just pull all the shared assets needed
for desktop and android app out into another jar packaging project. Then
in the desktop app declare it as normal dependency provided you want it to
be just on the classpath in the same way you had it in the originating
jar.

In the android project bind the dependency plugin goal "unpack" for the
assets artifact to an early lifecycle phase so it gets extracted to the
target folder for assests.. and voila. The android build will pull it in..

That should do it. Depending on assest structure and needs you could even
to that with multiple different ones and or getting them extracted to
different folders and so (e.g. even the drawable folder..)

manfred
http://www.simpligility.com

Ruben Garat

unread,
Mar 25, 2011, 5:24:04 PM3/25/11
to maven-androi...@googlegroups.com
thanks I tried to use the dependency:unpack goal but it fails because it
can't resolve the assets dependency. It tries to lookup the jar from a
repo and fails unless you have previously run a mvn install.

Another solution that I tried was using an execution of the antrun
plugin where I first delete the assets dir, and then copy the assets
from the asset module to the android one.

like this:

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>prepare-package</phase>
<configuration>
<target>
<delete>
<fileset dir="assets">
<include name="**" />
</fileset>
</delete>
<copy todir="assets">
<fileset dir="../magick-assets/src/main/resources">
<include name="**" />
</fileset>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

this works perfectly when running from console, but I am having
intermitent problems when using it from eclipse with the m2eclipse
integration, lots of times it says that it can't find the apk when
trying to run the game.

The other thing that I tried and what I will use now, is set the
<assetsDirectory>../magick-assets/src/main/resources</assetsDirectory>
configuration to point to the module assets.

This solution works, but I feel really dirty by doing this to poor
maven, it is more like a workaround than a proper solution.

thanks for your help.

Rub�n

Manfred Moser

unread,
Mar 25, 2011, 5:29:29 PM3/25/11
to maven-androi...@googlegroups.com
You will have to tie it together in a multi module build that ensures that
the assest are built before the desktop and android apps. Then it will
work just fine..


manfred

> --
> You received this message because you are subscribed to the Google Groups
> "Maven Android Developers" group.
> To post to this group, send email to
> maven-androi...@googlegroups.com.
> To unsubscribe from this group, send email to
> maven-android-deve...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/maven-android-developers?hl=en.
>

Ruben Garat

unread,
Mar 25, 2011, 5:59:25 PM3/25/11
to maven-androi...@googlegroups.com
I am using a multi module build and at first dependency:unpack worked
but some time later it didn't

after some investigation, I found that in previous tests I had the
dependency to the assets artifact in the android module, so that made
the assets module to be build before the android one. After seeing that
the dependency:unpack worked I removed the unused dependency, and it
started to fail, didn't relate those two events at the time, so I
searched for other options.

A quick fix for this is declaring the assets module before the android
one, but that is a brittle solution and prone to be broken by mistake. I
you have by chance an old artifact of the same version installed in your
local repo the build will succeed but the assets artifact will be an old
one.

Another fix is declaring the dependency to the assets artifact but with
scope runtime, so it is not included in the apk, but again, don't like
that solution either.

for now unless I need some filtering or other maven processing of the
assets I will point the assets directory in the android module plugin to
the src/main/resources of the assets module, as it is way less
configuration and avoids an extra step making the build complete faster.

thanks for your help.

Ruben

Manfred Moser

unread,
Mar 25, 2011, 6:06:24 PM3/25/11
to maven-androi...@googlegroups.com
I am glad you figured it out.

Joakim Erdfelt

unread,
Mar 25, 2011, 7:24:09 PM3/25/11
to maven-androi...@googlegroups.com, Ruben Garat
You'll want to stick with dependency:unpack, perceived warts and all.

That behavior is pretty standard for maven.
Maven operates on all projects as if they are the only project, and all inter-project references are via the repository system.
Going outside of the project to access another project via a filesystem reference is generally unsupported by maven itself.

There are perceived exceptions when dealing with <scope>system</scope> dependencies.
But in reality, even those exceptions are using the repository system, its just that maven looks elsewhere on the local system for that dependency, and not the repository system itself.

- Joakim Erdfelt

Rubén
Reply all
Reply to author
Forward
0 new messages