0

I'm trying to shrink my app size with the R8 compiler and the Proguard Rules. The problem is that the Safe Args extension uses reflection in NavArgsLazy.kt like so:

override val value: Args
        get() {
            var args = cached
            if (args == null) {
                val arguments = argumentProducer()
                val method: Method = methodMap[navArgsClass]
                    ?: navArgsClass.java.getMethod("fromBundle", *methodSignature).also { method ->
                        // Save a reference to the method
                        methodMap[navArgsClass] = method
                    }

                @SuppressLint("BanUncheckedReflection") // needed for method.invoke
                @Suppress("UNCHECKED_CAST")
                args = method.invoke(null, arguments) as Args
                cached = args
            }
            return args
        }

And when I try to run the app I get an exception saying that the method fromBundle does not exist when the fragment that uses Safe Args is created. I'm aware of the reflection problems with ProGuard but I cannot fix this, I'm unable to exclude the class that is giving me this error as I cannot access the generated file and excluding all the files that extends from NavArgs interface is not working either.

1 Answers1

0

This issue has already fixed in Navigation Component version 2.4.0-alpha03

The detailed problem is described here: https://issuetracker.google.com/issues/190082521

hientp
  • 634
  • 4
  • 11