title: Building Java Library that Depends on Android Project Gradle
body: <p>I have an Android project that defines various datatypes that are serialized via Protocol Buffers. I would like to have a separate Java project that is able to deserialize these data types on the server. </p>
  
  <p>My project is structured as follows:</p>
  
  <pre><code>Android Library
    - Data
        - TypeA 
        - TypeB
        - ...
  
  Java Server
    - Parser (depends on .Data)
  </code></pre>
  
  <p>In this example, all classes in the package Data handle marshaling themselves. </p>
  
  <p>When trying to build the Java Server, it successfully compiles the Android project, but ultimately fails with Gradle saying it cannot find the referenced packages.</p>
  
  <p>Note, that I can successfully build the Java Server with cross project dependencies if I only pull in other Java libraries, leading me to believe this is a Java -> Android dependency problem rather than a Gradle configuration issue. </p>
  
  <p>On possible solution I have considered is to pull out all of these data types from the Android project and place them in a separate Java library. The trouble with this however is that some of these classes merely provide a means of converting Android specific classes ( SensorEvent, Location, etc ) into a type that can be used with ProtoBuf. One solution I've been considering would look like this:</p>
  
  <pre><code>Data Types
    - TypeA
    - TypeB
    - ...
  
  Android Library
    - Data
      - AndroidTypeA (Class with Android Specific constructor that can be cast to the parent type)
      - AndroidTypeB
      - ...
  
  Java Server
    - Parser ( Depends on the Data Types module )  
  </code></pre>
  
  <p>While this would indeed solve my issue, it hardly seems like the best solution.</p>
  
  <p>Is there any way to accomplish this through Gradle alone?</p>
  
  <hr>
  
  <p>For reference here are abbreviated versions of my <code>build.gradle</code> files.</p>
  
  <p>Android Library:</p>
  
  <pre><code>apply plugin: 'com.android.library'
  
  android {
      compileSdkVersion 21
      buildToolsVersion "21.0.2"
  
      defaultConfig {
          applicationId "com.foo.bar.androidlib"
          ...
      }
      buildTypes {
          release {
              runProguard false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      ...
      compile 'com.google.protobuf:protobuf-java:2.6.1'
  }
  </code></pre>
  
  <p>Java Server:</p>
  
  <pre><code>apply plugin: 'java'
  
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      compile 'com.google.protobuf:protobuf-java:2.6.1'
      compile project(':androidlib')
  }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>Specifically Gradle gives the following error:</p>
  
  <blockquote>
    <p>error: package com.foo.bar.androidlib does not exist</p>
  </blockquote>