Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems using latest jars from Square - retrofit, okhttp, okio and okhttp-urlconnection

I introduced the following Square jars for a feature I'm working on:

  • okttp-2.0.0
  • okhttp-urlconnection-2.0.0.jar
  • okio-1.0.0.jar
  • retrofit-1.6.1.jar

I downloaded these from the central maven repo.

Everything worked fine locally and I committed my code to svn. We have a Jenkins CI Server that produces our debug and release builds. This failed.

There are a number of differences between my local environment and Jenkins:

  • locally I run java 8, Jenkins runs java 6
  • locally I only produce debug builds, Jenkins produces both debug and release builds
  • locally I have build tools version 22.6.2, Jenkins runs 18.0.1

And these are the sort of issues I'm seeing in the Jenkins logs:

    -compile:
    [javac] Compiling 545 source files to /var/lib/jenkins/jobs/Planner_4_10_Retrofit/workspace/Planner_4_10_Retrofit/bin/classes
    [javac] warning: /var/lib/jenkins/jobs/Planner_4_10_Retrofit/workspace/Planner_4_10_Retrofit/libs/okhttp-2.0.0.jar(com/squareup/okhttp/OkHttpClient.class): major version 51 is newer than 50, the highest major version supported by this compiler.
    [javac] It is recommended that the compiler be upgraded.

    [dex] Pre-Dexing /var/lib/jenkins/jobs/Planner_4_10_Retrofit/workspace/Planner_4_10_Retrofit/libs/okhttp-urlconnection-2.0.0.jar -> okhttp-urlconnection-2.0.0-5f923d75acdde39a4616800eb222e1bf.jar
           [dx] 
           [dx] trouble processing:
           [dx] bad class file magic (cafebabe) or version (0033.0000)
           [dx] ...while parsing com/squareup/okhttp/internal/huc/CacheAdapter.class
           [dx] ...while processing com/squareup/okhttp/internal/huc/CacheAdapter.class

    [proguard] Initializing...
     [proguard] Warning: retrofit.RxSupport$1: can't find superclass or interface rx.Observable$OnSubscribe
     [proguard] Warning: okio.DeflaterSink: can't find referenced method 'int deflate(byte[],int,int,int)' in class java.util.zip.Deflater
     [proguard] Warning: okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
     [proguard] Warning: okio.Okio: can't find referenced class java.nio.file.Files
    [proguard] Warning: retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.HTTPMethod
     [proguard] Warning: retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchServiceFactory
     [proguard] Warning: retrofit.appengine.UrlFetchClient: can't find referenced class com.google.appengine.api.urlfetch.URLFetchService
    [proguard] Note: there were 10 unresolved dynamic references to classes or interfaces.
 [proguard]       You should check if you need to specify additional program jars.
 [proguard] Warning: there were 90 unresolved references to classes or interfaces.
 [proguard]          You may need to specify additional library jars (using '-libraryjars').
 [proguard] Warning: there were 1 unresolved references to program class members.
 [proguard]          Your input classes appear to be inconsistent.
 [proguard]          You may need to recompile them and try again.
 [proguard]          Alternatively, you may have to specify the option 
 [proguard]          '-dontskipnonpubliclibraryclassmembers'.

Even on Jenkins the debug build says it passed but failed the release build. Is the problem only Proguard?

I did find some settings, my current proguard file has the following directives about the the libs:

-dontwarn com.squareup.okhttp.**
-keep class retrofit.** { *; }
-keepclasseswithmembers class * {
@retrofit.http.* <methods>;
}

With so many differences, I'm trying to find the likely culprit! Any ideas where to start? I'm loathe to change the configurstion on jenkins if I can get away with just proguard changes.

like image 565
FinalFive Avatar asked Jul 21 '14 17:07

FinalFive


1 Answers

This was finally solved but required multiple changes.

  1. I updated the jdk to 7 on the node running Jenkins.
  2. I updated the android sdk tools
  3. I added the following to proguard:

    -dontwarn com.facebook.android.BuildConfig
    
    -dontwarn rx.**
    
    -dontwarn okio.**
    
    -dontwarn com.squareup.okhttp.*
    
    -dontwarn retrofit.appengine.UrlFetchClient
    
    -keepattributes *Annotation*
    
    -keep class retrofit.** { *; }
    
    -keepclasseswithmembers class * {
        @retrofit.http.* <methods>; 
    }
    
    -keepattributes Signature
    
like image 163
FinalFive Avatar answered Oct 06 '22 13:10

FinalFive