2

I'm building APK files using gradle and let proguard shrink and obfuscate my code. One external library that I use contains some *.so files that I do not need but that end up in my final APK file.

I guess it should be possible to tell proguard to ignore those files, but how?

The documentation of proguard (http://proguard.sourceforge.net/manual/usage.html#filters) explains how to use filters, for example this is how to avoid errors with duplicate MANIFEST files:

-injars  in1.jar
-injars  in2.jar(!META-INF/MANIFEST.MF)
-injars  in3.jar(!META-INF/MANIFEST.MF)
-outjars out.jar

And we can also filter based on filenames and patterns:

-injars  in.jar(!images/**)
-outjars out.jar

This would be perfect, let's assume I wanted to do exactly as in the second example and strip everything in an 'images' directory from one of my jars.

The problem is, when using proguard in a gradle build for an Android project, we don't specify the input and output ourselves as in these examples. Instead probably gradle tells proguard which JARs to work on and where to write the results to. So there is no place in the config file to put the

(!images/**)

statement.

What I would expect to work is an option similar to this one:

-stripfiles !images/**
sebkur
  • 658
  • 2
  • 9
  • 18

2 Answers2

1

Okay, finally found a solution through this question: Android Gradle plugin 0.7.0: "duplicate files during packaging of APK"

Arbitrary files can be excluded from being packaged into the APK by adding

android {
    packagingOptions { 
        exclude 'path/to/file/to/be/ignored.so'
    }
}

to the build.gradle file.

Unfortunately, it doesn't seem to support regular expressions though.

Community
  • 1
  • 1
sebkur
  • 658
  • 2
  • 9
  • 18
0

If you have the following files in the libs folder:

app/libs
    ├─ library-1.0.jar
    ├─ library-1.0-sources.jar
    └─ library-1.0-javadoc.jar

Then the library-1.0-sources.jar and library-1.0-javadoc.jar will be included in the built APK (at the top-level root).

You should exclude them like this, in the app/build.gradle file:

dependencies {
    compile fileTree(include: ['*.jar'], exclude: ['*-sources.jar', '*-javadoc.jar'], dir: 'libs')
}

See also: How to attach javadoc or sources to jars in libs folder?

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
  • Hey Mr-IDE, this question is about files *within* individual jars, not about which jar files to consider in the first place. – sebkur Jul 02 '18 at 10:52