Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best answer I have heard to this problem so far is to use ProGuard in optimized mode (proguard-android-optimize.txt) with the <code>-dontobfuscate</code> flag to remove unused classes and methods from the final APK (without obfuscating them). Then you can use the ProGuard mapping.txt to help you strip the unused classes out of the library JARs that you use (I'm not aware of a good tool to do this). Unfortunately I don't think there is a feature in ProGuard to do this automatically.</p> <p>ProGuard only runs when doing an Export in Eclipse, not when doing a Run As -> Android Application. This means it won't help avoid the limit on debug builds, unless you use a custom build process. The creator of ProGuard suggests using its commercial sibling <a href="http://www.saikoa.com/dexguard" rel="nofollow">DexGuard</a>, which will run in Eclipse on both debug and release builds.</p> <p>Using ProGuard is strongly encouraged for release builds as it will reduce your code size, improve performance (e.g. by inlining code), and will obfuscate your source too. Make sure you do enough testing on the final APK as it will be dramatically different to the debug one. Unfortunately, ProGuard on its own wasn't enough to solve my problem, so I removed one of my JAR dependencies as a workaround.</p> <p>I checked the number of methods in my dependent JARs using this command:</p> <pre><code>dx --dex --output=temp.dex library.jar cat temp.dex | head -c 92 | tail -c 4 | hexdump -e '1/4 "%d\n"' </code></pre> <p>Examples numbers of methods for our biggest libraries:</p> <pre><code>11222 guava-11.0.1.jar 10452 aws-android-sdk-1.5.0-core.jar 5761 org.restlet.jar 5129 protobuf-java-2.4.1.jar 2499 aws-android-sdk-1.5.0-s3.jar 2024 ormlite-core-4.41.jar 1145 gson-2.2.2.jar 1716 google-http-client-1.11.0-beta.jar </code></pre> <p>FYI, you can check the number of methods in your APK using dexdump (which you can find in your SDK <code>build-tools</code> folder, e.g. "Android Studio.app/sdk/build-tools/21.0.2/dexdump"):</p> <pre><code>dexdump -f MyApp.apk | grep method_ids_size method_ids_size : 64295 </code></pre> <p>In our case we were only using Guava for doing YouTube searches, so it was easy to remove that dependency and give us more breathing room.</p> <p><strong>Update:</strong> I found the easiest way to strip out unused code from large JARs was to use dex2jar on my Proguard build, then use JD-GUI to compare that final JAR with the specific input JAR I wanted to trim. Then I remove top level packages that I know get removed by Proguard. This allowed me to remove >8000 methods from aws-android-sdk-1.5.0-core.jar.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload