Search code examples
androidsimple-framework

App using SimpleXML with minifyEnabled does not work


I have an app that works fine when debugging, but when I make a release version, with minifyEnabled true in the build.gradle file, it seems not to work at all anymore:

D/SapphirePocket( 6520): Could not serialize telegram: <init> [interface a.a.a.b.am, interface a.a.a.a, class a.a.a.e.n]

Does SimpleXML work with minified APKs, where inspection might not completely work anymore or should this just work?


Solution

  • When you activate minifyEnabled, you are obfuscating the code with proguard. SimpleXML should use some classes that you are obfuscating and you must not do this. You must keep the names of the classes that SimpleXML needs.

    See this post about the same problem as you have (simplexml failed to compile with proguard activated).

    The first thing I recommend is put this on proguard file (extracted from the post I've linked):

    -keep public class org.simpleframework.** { *; }
    -keep class org.simpleframework.xml.** { *; }
    -keep class org.simpleframework.xml.core.** { *; }
    -keep class org.simpleframework.xml.util.** { *; }
    
    -keepattributes ElementList, Root
    
    -keepclassmembers class * {
        @org.simpleframework.xml.* *;
    }
    

    For a more detailed response, please, show us more information (proguard file, code getting the error...).