Skip to content

Instantly share code, notes, and snippets.

@JakeWharton
Last active May 10, 2018 08:39
Show Gist options
  • Select an option

  • Save JakeWharton/017738659d4f38adedc2 to your computer and use it in GitHub Desktop.

Select an option

Save JakeWharton/017738659d4f38adedc2 to your computer and use it in GitHub Desktop.
A workaround for Android "L" Okio packaging problem. Place all of the following in a `libs/` folder.

JarJar'd OkHttp Dependencies

Due to a bug in the packaging of Android OS "L", dependencies which reference Okio need to be repackaged.

For more information see square/okhttp#967

Usage

Download jarjar-1.4.jar and place it in this directory.

Download OkHttp, Okio, and optionally OkHttp UrlConnection and place it in this directory.

The contents of the folder should look like:

-rw-r--r--  1 you  you   118K Jul 30 12:07 jarjar-1.4.jar
-rw-r--r--  1 you  you    34B Jul 30 12:08 jarjar.rules
-rwxr-xr-x  1 you  you   175B Jul 30 13:37 jarjar.sh
-rw-r--r--  1 you  you   255K Jul 30 12:09 okhttp-2.0.0.jar
-rw-r--r--  1 you  you    30K Jul 30 12:09 okhttp-urlconnection-2.0.0.jar
-rw-r--r--  1 you  you    51K Jul 30 12:09 okio-1.0.0.jar

Now run the jarjar.sh script and you should see the repackaged jars:

-rw-r--r--  1 you  you   256K Jul 30 13:37 repackaged-okhttp-2.0.0.jar
-rw-r--r--  1 you  you    30K Jul 30 13:37 repackaged-okhttp-urlconnection-2.0.0.jar
-rw-r--r--  1 you  you    52K Jul 30 13:37 repackaged-okio-1.0.0.jar

Include these in your build.gradle with:

dependencies {
  compile fileTree(dir: 'libs', include: 'repackaged-*.jar')
}
rule okio.** com.squareup.okio.@1
#!/bin/bash
set -ex
rm repackaged-*.jar 2> /dev/null
for jar in `ls *.jar | grep -v 'jarjar-'`; do
java -jar jarjar-* process jarjar.rules "$jar" "repackaged-${jar}"
done
@gcarre
Copy link
Copy Markdown

gcarre commented Aug 27, 2014

jarjar.sh was failing for me on MacOS without any existing repackaged jar files in the directory, had to replace rm repackaged-*.jar 2> /dev/null with rm -f repackaged-*.jar

@arkangelx
Copy link
Copy Markdown

I get this error
Error:Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment