Reputation: 4391
Ok so i have this use case:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (loginManager.isLoggedIn()) {
if(BuildConfig.IS_FLAVOR_A){
ActivityA.startActivity(this)
} else if(BuildConfig.IS_FLAVOR_B){
ActivityB.startActivity(this)
}
} else {
ActivityC.startActivity(this)
}
this.finish()
}
BuildConfig.IS_FLAVOR_A
is a flag present in the productFlavors that identify a flavour. ActivityB
is only ever referenced here, and i would expect Proguard to remove ActivityB
and all its resources but it isn't.
buildTypes {
release {
minifyEnabled true
shrinkResources = true
signingConfig signingConfigs.APK_Release_Temp
proguardFiles getDefaultProguardFile('proguard-android.txt'), '.../proguard-rules.pro'
}
}
What is missing? Can i really accomplish this? Flavours compile-time constants allow proguard to remove unused codes, in the case, ActivityB.startActivity(this)
EDIT: Proguard Rules
-dontobfuscate
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable
# AdvancesWebView
-keep class * extends android.webkit.WebChromeClient { *; }
# RxJava
-dontwarn sun.misc.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
# Retrofit2
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}
#OKHttp
-dontwarn okio.**
# RxBle
-dontwarn com.polidea.**
# Support v4
-dontwarn android.support.v4.**
#Anko
-dontwarn org.jetbrains.anko.internals.AnkoInternals
#Support v7
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}
# CardView
-keep class android.support.v7.widget.RoundRectDrawable { *; }
#Support Design
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }
#Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
#Moshi
-keepclassmembers class ** {
@com.squareup.moshi.FromJson *;
@com.squareup.moshi.ToJson *;
}
Upvotes: 0
Views: 431
Reputation: 6200
You need to enable optimization. To do that, use this configuration instead:
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'.../proguard-rules.pro'
Upvotes: 1