0

I have a project to deal with some existing dex files. One of the requirements is to strip all unnecessary information and reduce their size.

If you try to build a simple "hello world" app by using Eclipse plugin and just following the wizard (the SDK and plugin are the latest version that I just downloaded and installed last night), you will create a classes.dex file of more than 300KB.

However, if you look at the project, you will find a support lib file appears in the lib folder. If you get rid of it the app is still working but the size of the dex file suddenly droped to 3KB.

So I reckon that our existing files may also contains similar unnecessary references. The problem is now being how to find them and get rid of them.

Are there any tools can do this?

ejohansson
  • 2,832
  • 1
  • 23
  • 30
Earth Engine
  • 10,048
  • 5
  • 48
  • 78

2 Answers2

2

In the project.properties file you have to add this line

proguard.config=proguard.cfg

and you will find the proguard properties in proguard-project.txt file

Here is an example for an android application

-injars      bin/classes
-outjars     bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic

-keep public class mypackage.MyActivity

This one is for an entire android application

-injars      bin/classes
-injars      libs
-outjars     bin/classes-processed.jar
-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar

-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.content.Context {
    public void *(android.view.View);
    public void *(android.view.MenuItem);
}

-keepclassmembers class * implements android.os.Parcelable {
    static android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

you can use injars,libraryjars ,etc to control the jar files that are necessary for you

you can get the necessary example from here and for an complete android application is here

Girish Nair
  • 5,148
  • 5
  • 40
  • 61
0

The standard tool for this is proguard, which the Android SDK already supports. You can find more info here

JesusFreke
  • 19,784
  • 5
  • 65
  • 68
  • According to http://proguard.sourceforge.net/index.html#manual/usage.html , it looks like this is a tool that works on JAR level, not dex level. Which is not what I am looking for, as I do not have access to the jar files. – Earth Engine Nov 01 '12 at 01:58
  • Ah, I had mis-read the question :). There's just the one small blurb about dex files at the top. You are correct, proguard does not work on dex files. I don't know of anything similar for dex files. – JesusFreke Nov 01 '12 at 17:19