Search code examples
androidproguardminifybundling-and-minification

Minifying my App strips essential classes


My app runs fine when launched via USB in Android Studio. Though when I create an apk file and install that, the app crashes immediately on launch with a ClassNotFoundException. Investigating further I disabled minifying, changing

minifyEnabled true

to

minifyEnabled false

in build.gradle.

Without minifying, the apk file works. However, I don't want to refrain from minifying my app. How does the minifier work? Why does it strip essential classes of my app? How can I make the minifier to include all my classes?

My proguard-rules.pro file is empty except for comments.


Solution

  • Adding

    -keep public class MyClass
    

    to proguard-rules.pro did the trick. In the end I had to keep two classes this way. They both have something in common: They're both added via

    <androidx.fragment.app.FragmentContainerView
    

    in xml layout, not in code with FragmentManager. Those are the only classes added this way.