readium / kotlin-toolkit

A toolkit for ebooks, audiobooks and comics written in Kotlin
https://readium.org/kotlin-toolkit
BSD 3-Clause "New" or "Revised" License
163 stars 72 forks source link

Exception connected to opening an e-book and Proguard/R8. [Bug] #505

Closed svepett closed 2 months ago

svepett commented 2 months ago

Describe the bug

I have inherited an app that has imported the sample app and rewritten some of it.

When Obfuscatiing Android app with the following code:

release { debuggable false minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' signingConfig signingConfigs.releaseConfig } I run into the following exception:

Error: java.lang.InstantiationException : java.lang.Class cannot be instantiated java.lang.InstantiationException: java.lang.Class cannot be instantiated at java.lang.Class.newInstance(Native Method) at org.nanohttpd.router.RouterNanoHTTPD$UriResource.process(RouterNanoHTTPD.java:380) at org.nanohttpd.router.RouterNanoHTTPD$UriRouter.process(RouterNanoHTTPD.java:597) at org.nanohttpd.router.RouterNanoHTTPD.serve(RouterNanoHTTPD.java:672) at org.nanohttpd.protocols.http.NanoHTTPD$1.handle(NanoHTTPD.java:376) at org.nanohttpd.protocols.http.NanoHTTPD$1.handle(NanoHTTPD.java:372) at org.nanohttpd.protocols.http.NanoHTTPD.handle(NanoHTTPD.java:535) at org.nanohttpd.protocols.http.HTTPSession.execute(HTTPSession.java:418) at org.nanohttpd.protocols.http.ClientHandler.run(ClientHandler.java:75) at java.lang.Thread.run(Thread.java:1012)

I would appriciate some idea of what could be the reason

How to reproduce?

  1. Adding Obfuscating code to gradle
  2. Open an e-book

Readium version

2.2.1

Android API version

14

Additional context

No response

mickael-menu commented 2 months ago

In our own app, we use this in the Proguard config file:

-keep class org.readium.r2.shared.** { *; }
-dontwarn org.readium.r2.shared.**
-keep class org.readium.r2.streamer.** {*;}
-dontwarn org.readium.r2.streamer.**
-keep class org.readium.r2.navigator.** {*;}
-dontwarn org.readium.r2.navigator.**
-keep class org.readium.r2.opds.** {*;}
-dontwarn org.readium.r2.opds.**
-keep class org.readium.r2.lcp.** {*;}
-dontwarn org.readium.r2.lcp.**
-keep class org.readium.lcp.** {*;}
-dontwarn org.readium.lcp.**

This adds about 1 KB to the AAB.

Disclaimer: I'm not a Proguard expert. If someone has a better solution, please chime in.

svepett commented 2 months ago

Thank you Michael-menu , you are a life safer in a sea of strange code. Feeling like a monkey in a house made of glass. The solution was to not obfuscate the radium files that complained.