sourceafis-java icon indicating copy to clipboard operation
sourceafis-java copied to clipboard

Android Proguard Rules

Open andredoubleu opened this issue 1 year ago • 1 comments

Hi, I've found that when I include the SourceAFIS SDK in my Android application, and then compile a release version of my app, the SourceAFIS SDK is adding about 12 MB to my .apk's file size. I opened up my .apk file and took a look inside, and it looks like all 12 MB are coming from new Java classes (in classes2.dex, classes3.dex, and classes4.dex). It this expected? I've just never seen an SDK add so many classes to my project before. Of course I understand that every SDK has dependencies, which in turn have dependencies of their own, but I have 'minifyEnabled=true', which enables code-shrinking, obfuscation, and optimization, and this is usually enough to remove all of the unused classes.

Next I thought maybe I could improve the code-shrinking with Proguard rules. Do you have any recommended Proguard rules when including the SDK in an Android application?

I'm including the SDK in my Android app's build.gradle file like this:

dependencies {
    implementation "com.machinezoo.sourceafis:sourceafis:3.18.0"
}

And these are some rules I've set in my build.gradle file:

buildTypes {
    release {
        minifyEnabled true // Code shrinking, obfuscation, and optimization.
        shrinkResources true // Resource shrinking.
        debuggable false // The apk can not be attached to a debugger.
        signingConfig signingConfigs.release
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
    debug {
        debuggable true
        signingConfig signingConfigs.debug
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}

Thanks in advance, and thanks for making this great SDK.

andredoubleu avatar Sep 27 '23 22:09 andredoubleu

My guess is it's mostly fastutil's primitive collections. Only a few of those classes will be actually loaded at runtime. Minification tools (no idea what's available for Android) should be able to filter out the unused classes.

Re Proguard, no, I do not have any experience with that tool.

robertvazan avatar Sep 28 '23 01:09 robertvazan