In my Android app I am building in release mode. With Proguard activated an rare issue is caused, a specific for-loop never is executed:
List<MyClass> objectList = getObjectList();
Log.d("Step 1", String.valueOf(objectList.size())); //Print size > 0
for(MyClass object: objectList) {
Log.d("Step 2", object.toString()); //Never printed
...
}
The "Step 1" Log is printed correctly and objectList.size() > 0
. I don't understand what is causing "Step 2" Log is never printed (and all code into for-loop never executed). I am using the Android Device manager Logcat.
In debug mode or with Proguard disabled this snippet works correctly.
Thanks in advance.
Update
I just added -dontoptimize
but the problem was not resolved. This is my proguard-rules file:
-dontoptimize
-dontpreverify
-repackageclasses ''
-allowaccessmodification
#-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*,EnclosingMethod,SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
-keepnames class com.androidplot.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class org.acra.** { *; }
-keep,allowoptimization class com.mypackage.myapp.model.** { *; }
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.preference.PreferenceFragment
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * implements android.os.Parcelable {
static android.os.Parcelable$Creator CREATOR;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
-dontwarn com.mypackage.myapp.**
-dontwarn com.fasterxml.jackson.databind.ext.**
-dontwarn com.google.common.**
-dontwarn android.support.**
https://stuff.mit.edu/afs/sipb/project/android/sdk/android-sdk-linux/tools/proguard/docs/index.html#manual/troubleshooting.html