0

Is there a way to strip specific classes from an APK using proguard? I need to do this to build 2 different APKs, one with restricted features. For example some activities should not be available in one of the 2 APKs, so it shouldn't be in it.

I cannot use a library and 2 projects to achieve this because actual use case is much more complicated and already involves building 4 APKs, 2 more APKs should build from the same library, stripping specific components out of the APKs.

I tried something like this, but it didn't work at all and didn't remove anything from the built APK.

-assumenosideeffects class app.package.activities.classes_to_strip.** { public *** *(...); public static *** *(...); public *; private *; protected *; } 

UPDATE: I've change the title to better reflect what I'm trying to achieve.

So far, I've been able to build a trimmed-down APK (with less activities) however all other activity codes remains present in final APK, because they are referenced from various part of the code (this is not really a problem because such code will not run).

1
  • The default android proguard configuration at one point had optimisation turned off which will stop this working. You may want to check and if off try turning it on. Commented Aug 15, 2013 at 8:45

3 Answers 3

1

Android's Ant/Eclipse/Gradle build process automatically generates ProGuard configuration (bin/proguard.txt) that keeps activities (and other classes) that are referenced in AndroidManifest.xml (and other XML files). So you should somehow start your builds with different AndroidManifest.xml files.

Sign up to request clarification or add additional context in comments.

2 Comments

Don't really want to have different manifests (6 in total) to maintain. In those trimmed-down APKs, I disabled the components I don't want, but it doesn't remove them from final APKs.
Tested with different manifests, it doesn't actually help. Only classes not referenced anywhere in the code/xml will be stripped away. I need to remove a set of classes from the final APK.
0

No, proguard is for code mix, not for code 'build option'.

2 Comments

I understand that, however build options are not possible in Java per se, (like #ifdef in C) and I have one main library containing everything which is used to build 4 (then 6) APKs. That particular ProGuard option seemed a reasonable way to achieve this easily.
Any solution for build option that will allow removing specific classes from the final APK?
0

With Proguard, you are easy to mix most of the code and exclude some using -keep class *. However, what you want to do is the opposite.

I think you could just manually remove some code in your AndroidManifest.xml

2 Comments

The main library AndroidManifest is actually inherited by other APKs, so I'm disabling the components I don't want in the final APK, however all classes remain present in those trimmed-down APK. Final APK is about 8Mb, whereas the actual used code will be about 2MB!
The main issue with this approach is that it will require maintaining 6 different manifests, if I ever forget to update one, final APK will FC.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.