jberkel / android-plugin

An sbt plugin for Android development in Scala
https://groups.google.com/forum/#!forum/scala-on-android
Other
476 stars 113 forks source link

Add proguard custom '-injars' parameter and filtering in jar files from the '-injars' parameter #154

Closed mkneissl closed 11 years ago

mkneissl commented 11 years ago

Summary

Sometimes you have to pack resources from input jars differently in the Proguard output. For that case this patch provides for adding additional unfiltered jars as input to proguard (which is currently not easily possible with the way the proguardInJars is used) and also allows for custom filtering of the content of specific injars.

Documentation

Modification of the input to ProGuard

By default the plugin filters out the Manifest and generated resource classes from ProGuard input. If you need to filter out more resources, you can specify them in proguardInJarsFilter as a partial function. The partial function takes the injar element as input and can return additional ProGuard filter expressions for this jar. If the partial function does not match, only the above default filtering is applied. For example, you can match on the akka jars and exclude reference.conf from the ProGuard input to avoid the duplicate resource issue.

val AkkaReg = """.*akka.*\.jar""".r
proguardInJarsFilter := { case AkkaReg() => Seq("!reference.conf") }

If you have further jars or other content to feed unfiltered into ProGuard, you can specify them in proguardInJarsOption.

proguardInJarsOption += "path/to/my/resource"

Related

There is a related pull request https://github.com/jberkel/android-plugin/pull/150 which implements the filtering slightly different and misses the ability to add unfiltered injars.

aginiewicz commented 11 years ago

Is there any workaround available with currently released snapshot of plugin? When building LibGDX apps for android there are some files in gdx.jar (file that comes from libgdx project) that I'd like to remove from final apk - default font (arial), default pixel and fragment shaders and xml files used by GWT backend - they are just using valuable space on users devices.

If not, are there any plans of merging this or #150 or at least making it possible to disable default -injars at all and allow user to specify their own -injars in proguard configuration next to -keep directives? Thanks.

appamatto commented 11 years ago

Hmm, I don't like how specific this option is. Is this not possible to add manually to proguardOptions? If it requires some dynamic functionality then it seems strange to limit it to inJars.

yuchangyuan commented 11 years ago

If there no changes during these months(and I remember correctly), there is not way to just exclude some classes or files without modify modify '-injar' option of proguard.

appamatto commented 11 years ago

A form of pull request #150 has been merged.

ntcarapkin commented 11 years ago

One of the purpouse of this patch is to add custom -inJars options without filtering. It makes possible to add any custom resources to the proguard's output jars. At the moment it is not possible. It is usefull in the following case for example: if we have different jars with dependency on the akka library and each of this jars has custom akka configuration files ('reference.conf'), it is necessary to merge all this configurations in one file and put it in the -inJars option as additional resource, otherwise configurations will be overwrote and in the output jar landing the configuration from the last input jar in the list.

appamatto commented 11 years ago

That makes sense. Can you provide a minimal build.sbt demonstrating this?