contentful / vault

Easy persistence of Contentful data for Android over SQLite.
https://contentful.github.io/vault/
Apache License 2.0
85 stars 19 forks source link

Vault fails to sync with minification enabled #143

Closed AurimasSikorskas closed 5 years ago

AurimasSikorskas commented 6 years ago

Everything works fine n debug, but when i tried a release build, Vault wouldn't sync and SyncCallback returns a failure. If i set minifyEnabled to false everything works fine again, but i would prefer to keep it true for release.

mariobodemann commented 6 years ago

Hey,

are there any logs (logcat, exceptions?) you could share? Additionallly do you have a special Proguard file or are you using this one?

AurimasSikorskas commented 6 years ago

Hi,

i didn't notice any strange logcat entries or exceptions, is there any specific logcat Tag i should be looking for?

As for Proguard, i applied this repository's Proguard file to mine, but it's a bit outdated and i had to do some adjustments to the library versions, for example okhttp to okhttp3, or else i would get over 200 warnings. My ProGuard file:

#Firebase
-keep class com.google.android.gms.ads.** { *; }
-dontwarn okio.**
-keepattributes *Annotation* 
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception

#Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

# Vault
-keepattributes Signature
-dontwarn javax.lang.model.type.TypeMirror
-keep class com.contentful.vault.** { *; }
-keep class **$$SpaceHelper { *; }
-keep class **$$ModelHelper { *; }
-keep class **$Fields extends com.contentful.vault.BaseFields { *; }
-keep @com.contentful.vault.ContentType class * { *; }
-keep @com.contentful.vault.Space class * { *; }

# contentful.java
-keep class com.contentful.java.cda.** { *; }

# Okio
-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

# Gson
-keepattributes EnclosingMethod
-keep class com.google.gson.stream.** { *; }

# contentful.java
-keep class com.contentful.java.cda.** { *; }

# RxJava
-dontwarn sun.misc.**

# OkHttp
-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

# Retrofit
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}
mariobodemann commented 6 years ago

Thanks for the update. I will investigate accordingly...

imecstamas commented 5 years ago

Hey! Since Vault uses the Serializable interface, you should add these lines to your proguard configuration:

-keepnames class * implements java.io.Serializable
-keepclassmembers class * implements java.io.Serializable {
    private static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

Check this for more details.

AurimasSikorskas commented 5 years ago

Finally had time to test it. Everything works as expected after adding those lines to the proguard file. Thank you very much.