Shared Code Between Target APK and Host Library

112 views
Skip to first unread message

Dave Smith

unread,
Jun 9, 2016, 5:32:49 PM6/9/16
to Android Building
I am building some components into an AOSP build and I would like them to share some Java code. Currently, I am adding two pieces:
  1. System APK (for some new services)
  2. Java library for host machines (client to interact with those services from apps)
There is some common code between the two that I would like to put in a shared "common" module, but I can't figure out the best way to include it? My first inclination was to do the following for each:
  1. Common = BUILD_STATIC_JAVA_LIBRARY
  2. Client Library = BUILD_HOST_JAVA_LIBRARY
    1. Includes the common under LOCAL_STATIC_JAVA_LIBRARIES
  3. APK = BUILD_PACKAGE
    1. Includes the common under LOCAL_STATIC_JAVA_LIBRARIES
The problem that I ran into is that BUILD_STATIC_JAVA_LIBRARY doesn't seem to feed nicely into BUILD_HOST_JAVA_LIBRARY as a dependency. It claims "no rule to make target" since javalib.jar doesn't exist for common (it builds a classes.jack file instead). If I change BUILD_HOST_JAVA_LIBRARY into BUILD_STATIC_JAVA_LIBRARY, everything compiles but I have no viable product in out/ that I can distribute (the code stays as classes.jack in intermediates).

Another idea I had was to change BUILD_STATIC_JAVA_LIBRARY into BUILD_JAVA_LIBRARY. However, I don't want the common code to be copied onto the target (no reason since it's built into the System APK as well).

Can anyone advise me on a proper technique for building the common code module that can be included by both an APK package and host library? Or perhaps a better way to deploy

Cheers,
--
Dave Smith, PE
@devunwired
Reply all
Reply to author
Forward
0 new messages