Enabled proguard to reduce APK size and added the pertinent proguard rules to avoid removing too much code.

This commit is contained in:
Severiano Jaramillo 2019-04-26 16:23:04 -05:00
parent 1eb9b64b45
commit ac7e729816
2 changed files with 94 additions and 34 deletions

View file

@ -28,14 +28,13 @@ android {
} }
buildTypes { buildTypes {
release { release {
minifyEnabled false minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// enable crashlytics // enable crashlytics
ext.enableCrashlytics = true ext.enableCrashlytics = true
} }
debug { debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue("string", "PORT_NUMBER", "8082") resValue("string", "PORT_NUMBER", "8082")
// disable crashlytics // disable crashlytics
ext.enableCrashlytics = false ext.enableCrashlytics = false

123
app/proguard-rules.pro vendored
View file

@ -20,37 +20,76 @@
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
###### itextpdf & opencsv -dontskipnonpubliclibraryclasses
-dontwarn java.awt.** # TODO enable optimization
-dontwarn javax.security.** -dontoptimize
-dontpreverify
# TODO enable obfuscation
-dontobfuscate
-verbose
##--------------- proguard configuration for ITextPDF ----------
-dontwarn com.itextpdf.**
##--------------- proguard configuration for openCSV ----------
-dontwarn java.beans.** -dontwarn java.beans.**
-dontwarn com.itextpdf.awt.**
-dontwarn javax.imageio.**
-keep class org.bouncycastle.** ##--------------- proguard configuration for Gson ----------
-dontwarn org.bouncycastle.** # Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
-keep class org.spongycastle.** { *; } # For using GSON @Expose annotation
-dontwarn org.spongycastle.** -keepattributes *Annotation*
-keep class javax.xml.crypto.dsig.** { *; } # Gson specific classes
-dontwarn javax.xml.crypto.dsig.** -dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
-keep class org.apache.jcp.xml.dsig.internal.dom.** { *; } # Application classes that will be serialized/deserialized over Gson
-dontwarn org.apache.jcp.xml.dsig.internal.dom.** -keep class com.google.gson.examples.android.model.** { *; }
-keep class javax.xml.crypto.dom.** { *; } # Prevent proguard from stripping interface information from TypeAdapterFactory,
-dontwarn javax.xml.crypto.dom.** # JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class org.apache.xml.security.utils.** { *; } -keep class * implements com.google.gson.JsonSerializer
-dontwarn org.apache.xml.security.utils.** -keep class * implements com.google.gson.JsonDeserializer
-keep class javax.xml.crypto.XMLStructure
-dontwarn javax.xml.crypto.XMLStructure
###### OkHttp ##--------------- proguard configuration for Retrofit ----------
# Retrofit does reflection on generic parameters. InnerClasses is required to use Signature and
# EnclosingMethod is required to use InnerClasses.
-keepattributes Signature, InnerClasses, EnclosingMethod
# Retrofit does reflection on method and parameter annotations.
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit
# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.KotlinExtensions
# With R8 full mode, it sees no subtypes of Retrofit interfaces since they are created with a Proxy
# and replaces all potential values with null. Explicitly keeping the interfaces prevents this.
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
##--------------- proguard configuration for OkHttp ----------
# JSR 305 annotations are for embedding nullability information. # JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.** -dontwarn javax.annotation.**
@ -64,16 +103,38 @@
-dontwarn okhttp3.internal.platform.ConscryptPlatform -dontwarn okhttp3.internal.platform.ConscryptPlatform
###### bitcoinj ##--------------- proguard configuration for Okio ----------
-dontwarn org.bitcoinj.store** # Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
###### ??? ##--------------- proguard configuration for bitcoinj ----------
-keep class org.slf4j.** { *; } # source: https://github.com/bitcoin-wallet/bitcoin-wallet/blob/v7.07/wallet/proguard.cfg#L49
-dontwarn org.slf4j.** -keep,includedescriptorclasses class org.bitcoinj.wallet.Protos$** { *; }
-keepclassmembers class org.bitcoinj.wallet.Protos { com.google.protobuf.Descriptors$FileDescriptor descriptor; }
-keep,includedescriptorclasses class org.bitcoin.protocols.payments.Protos$** { *; }
-keepclassmembers class org.bitcoin.protocols.payments.Protos { com.google.protobuf.Descriptors$FileDescriptor descriptor; }
-dontwarn org.bitcoinj.store.WindowsMMapHack
-dontwarn org.bitcoinj.store.LevelDBBlockStore
-dontnote org.bitcoinj.crypto.DRMWorkaround
-dontnote org.bitcoinj.crypto.TrustStoreLoader$DefaultTrustStoreLoader
-dontnote com.subgraph.orchid.crypto.PRNGFixes
-dontwarn okio.DeflaterSink
-dontwarn okio.Okio
-dontnote com.squareup.okhttp.internal.Platform
-dontwarn org.bitcoinj.store.LevelDBFullPrunedBlockStore**
-dontwarn org.bitcoinj.protocols.channels.PaymentChannelClient
###### Firabase Crashlytics ##--------------- proguard configuration for Crashlytics ----------
-keepattributes *Annotation* # source https://stackoverflow.com/a/34751033/5428997
-keepattributes SourceFile,LineNumberTable -keep class com.crashlytics.** { *; }
-keep public class * extends java.lang.Exception -dontwarn com.crashlytics.**
-keepattributes SourceFile,LineNumberTable,*Annotation*
-keep class com.crashlytics.android.**
##--------------- other ----------
-dontwarn org.slf4j.LoggerFactory
-dontwarn org.slf4j.MDC
-dontwarn org.slf4j.MarkerFactory