简体   繁体   中英

Add sibling project resources to Android assets without tight coupling

Problem

I am developing a game using libGDX with a project structure similar to:

Root project 'gdx-play'
+--- Project ':android'
+--- Project ':core'
\--- Project ':desktop'

Subprojects android and desktop depend on core .

I want to keep my assets in the resources folder of the core project. Depending on core from desktop works just fine, as libGDX is happy loading the assets from the packaged JAR root. On Android, however, libGDX expects the assets to reside in the assets folder of the packaged Apk.

How best can I configure my multi-project build without tight coupling among projects?

Possible solutions

One

Store the assets in an assets subfolder in the core project, so that they magically end up in the assets folder of the Apk when packaged.

Two

Publish two separate JARs from core ; one with classes and one with resources. Or separate the core project into two. Then, in android , somehow add the items in the resources JAR to the Android plugin's assets SourceDirectorySet and remove that JAR from the classpath (so that its items are not redundantly included into the APK). I don't know if this is dangerous.

Three

Add the android-library plugin to the core project and export an AAR. I'm sure this would be most compatible with android , however, I do not know how I would then get a normal JAR for the desktop project.

I would take one of two approaches. Either @jake-wharton's approach to creating jars from APK's in this similar question that, basically, involves creating JAR tasks for each release variant of the library (skipping over debug variants).

Or I would pull the assets into their own Android Library, like core-assets , leaving behind only java code in core . One benefit of this approach is that pure Java projects are easier to thoroughly test. Android's testing support is a bit lacking, at the moment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM