title: Android: library project with Retrofit results in NoClassDefFoundError
body: <p>I'm trying to build an android library project which uses OkHttp and Retrofit to grant access to our REST-backend.</p>
  
  <p>It seems to be working as long as I use <code>api</code> instead of <code>implementation</code> on my gradle-dependency for <code>com.squareup.retrofit2:converter-gson</code>. It seems that this is the only dependency needing this (all others can used with <code>implementation</code>).</p>
  
  <p>When using <code>implementation</code> here as well, the calling app will crash with <code>NoClassDefFoundError</code>:</p>
  
  <blockquote>
    <p>java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/gson/GsonBuilder;</p>
  </blockquote>
  
  <hr>
  
  <p>I'm using <code>consumerProguardFiles</code> with a bunch of proguard-rule-files (e.g. one for okhttp3, retrofit2 etc. from this <a href="https://github.com/krschultz/android-proguard-snippets" rel="nofollow noreferrer">repo</a>). All this will then be packed into an AAR, so rules from the dependencies should be added as well.</p>
  
  <p>It seems that I'm missing a proguard-rule for <code>converter-gson</code>. Can somebody post the rules needed to use <code>com.squareup.retrofit2:converter-gson</code> in a library project?</p>
  
  <hr>
  
  <h2>Edit 1</h2>
  
  <p>My <a href="https://github.com/krschultz/android-proguard-snippets/blob/master/libraries/proguard-square-retrofit2.pro" rel="nofollow noreferrer">current proguard-rule</a> for retrofit is:</p>
  
  <pre><code># Retrofit 2.X
  ## https://square.github.io/retrofit/ ##
  
  -dontwarn retrofit2.**
  -keep class retrofit2.** { *; }
  -keepattributes Signature
  -keepattributes Exceptions
  
  -keepclasseswithmembers class * {
      @retrofit2.http.* &lt;methods&gt;;
  }
  </code></pre>
  
  <p>As mentioned, this seems not enough. Maybe I need something else for <code>converter-gson</code>!?</p>
  
  <h2>Edit 2</h2>
  
  <p>My dependencies look like this:</p>
  
  <pre><code>implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
  implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
  api "com.squareup.retrofit2:converter-gson:$retrofitVersion"
  </code></pre>
  
  <p>And I'm trying to get rid of the <code>api</code> on the last one as I do not need it in the app using this library (or is this not avoidable)?</p>
  
  <hr>
  
  <h2>Edit 3</h2>
  
  <p>Hmm, maybe proguard is the wrong keyword. Actually the problem lies in the use of <code>implementation</code> over <code>api</code>. So dependencies will not be exposed to consumers. See <a href="https://stackoverflow.com/a/44493379/2170109">https://stackoverflow.com/a/44493379/2170109</a>.</p>
  
  <p>But I don't get why I need to expose <code>converter-gson</code> to consumers of my library when only the library calls <code>GsonBuilder</code>?</p>