Android

[jsoup] Caused by: java.lang.IllegalStateException: Could not read resource entities-xhtml.properties. Make sure you copy resources for j.a.g.i

코딩이완료되어, 릴리즈 버전으로 apk를 생성하기에 앞서 코드난독화를 진행하였다. 그 결과에 따른 오류이다.

■build.gradle(:app)

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

Android JSOUP ExceptionInInitializerError 오류 역시 난독화로 발생하는 문제이다.

Fatal Exception: java.lang.ExceptionInInitializerError
       at org.jsoup.nodes.Document$OutputSettings.<init>(Document.java:3)
       at org.jsoup.nodes.Document.<init>(Document.java:13)
       at org.jsoup.parser.TreeBuilder.initialiseParse(TreeBuilder.java:5)
       at org.jsoup.parser.HtmlTreeBuilder.parse(HtmlTreeBuilder.java:5)
       at org.jsoup.parser.Parser.parse(Parser.java:5)
       at org.jsoup.Jsoup.parse(Jsoup.java:5)
       at ddolcat.app.bear.bell.network.NetworkManagement$1.onResponse(NetworkManagement.java:3)
       at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(ExecutorCallAdapterFactory.java:37)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7615)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
2020-06-02 21:49:39.072 8690-8690/? E/at.app.hi.lott: Unknown bits set in runtime_flags: 0x8000
2020-06-02 21:49:53.530 8690-8690/ddolcat.app.hi.lotto E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ddolcat.app.hi.lotto, PID: 8690
    java.lang.ExceptionInInitializerError
        at j.a.g.f$a.<init>(:372)
        at j.a.g.f.<init>(:19)
        at j.a.h.m.a(:32)
        at j.a.h.m.b(:42)
        at j.a.h.b.b(:56)
        at j.a.h.g.b(:100)
        at j.a.c.b(:58)
        at e.a.a.a.h.b$a.onResponse(:87)
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(:68)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7615)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
     Caused by: java.lang.IllegalStateException: Could not read resource entities-xhtml.properties. Make sure you copy resources for j.a.g.i
        at j.a.g.i.b(:301)
        at j.a.g.i.a(:25)
        at j.a.g.i$b.<init>(:53)
        at j.a.g.i$b.<clinit>(:34)
        at j.a.g.f$a.<init>(:372) 
        at j.a.g.f.<init>(:19) 
        at j.a.h.m.a(:32) 
        at j.a.h.m.b(:42) 
        at j.a.h.b.b(:56) 
        at j.a.h.g.b(:100) 
        at j.a.c.b(:58) 
        at e.a.a.a.h.b$a.onResponse(:87) 
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(:68) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7615) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
2020-06-02 21:49:53.601 8690-8690/ddolcat.app.hi.lotto E/UncaughtException: java.lang.ExceptionInInitializerError
        at j.a.g.f$a.<init>(:372)
        at j.a.g.f.<init>(:19)
        at j.a.h.m.a(:32)
        at j.a.h.m.b(:42)
        at j.a.h.b.b(:56)
        at j.a.h.g.b(:100)
        at j.a.c.b(:58)
        at e.a.a.a.h.b$a.onResponse(:87)
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(:68)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7615)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
     Caused by: java.lang.IllegalStateException: Could not read resource entities-xhtml.properties. Make sure you copy resources for j.a.g.i
        at j.a.g.i.b(:301)
        at j.a.g.i.a(:25)
        at j.a.g.i$b.<init>(:53)
        at j.a.g.i$b.<clinit>(:34)
        at j.a.g.f$a.<init>(:372) 
        at j.a.g.f.<init>(:19) 
        at j.a.h.m.a(:32) 
        at j.a.h.m.b(:42) 
        at j.a.h.b.b(:56) 
        at j.a.h.g.b(:100) 
        at j.a.c.b(:58) 
        at e.a.a.a.h.b$a.onResponse(:87) 
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(:68) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7615) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 
2020-06-02 21:49:53.646 8690-8774/ddolcat.app.hi.lotto E/CrashlyticsCore: Unexpected method invoked on AppMeasurement.EventListener: onEvent(java.lang.String, java.lang.String, android.os.Bundle, java.lang.Long); returning null
2020-06-02 21:49:53.852 8690-8690/ddolcat.app.hi.lotto E/UncaughtException: Ouch! My own exception handler threw an exception.
    java.util.concurrent.ExecutionException: java.lang.NoClassDefFoundError: j.a.g.i$b
        at java.util.concurrent.FutureTask.report(FutureTask.java:123)
        at java.util.concurrent.FutureTask.get(FutureTask.java:207)
        at com.google.firebase.crash.FirebaseCrash$c.uncaughtException(:9)
        at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(:51)
        at org.chromium.base.JavaExceptionReporter.uncaughtException(chromium-TrichromeWebViewGoogle.apk-stable-410408383:6)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1073)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
        at java.lang.Thread.dispatchUncaughtException(Thread.java:2187)
     Caused by: java.lang.NoClassDefFoundError: j.a.g.i$b
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at java.lang.Class.forName(Class.java:379)
        at aos.a(:com.google.android.gms.dynamite_dynamitemodulesc@201817081@20.18.17 (120400-0):38)
        at aos.a(:com.google.android.gms.dynamite_dynamitemodulesc@201817081@20.18.17 (120400-0):48)
        at aos.a(:com.google.android.gms.dynamite_dynamitemodulesc@201817081@20.18.17 (120400-0):93)
        at com.google.firebase.crash.internal.api.FirebaseCrashApiImpl.a(:com.google.android.gms.dynamite_dynamitemodulesc@201817081@20.18.17 (120400-0):7)
        at com.google.firebase.crash.internal.api.FirebaseCrashApiImpl.reportUncaughtException(:com.google.android.gms.dynamite_dynamitemodulesc@201817081@20.18.17 (120400-0):2)
        at aog.a(:com.google.android.gms.dynamite_dynamitemodulesc@201817081@20.18.17 (120400-0):10)
        at ku.onTransact(:com.google.android.gms.dynamite_dynamitemodulesc@201817081@20.18.17 (120400-0):4)
        at android.os.Binder.transact(Binder.java:939)
        at com.google.android.gms.internal.crash.zza.transactAndReadExceptionReturnVoid(:20)
        at com.google.android.gms.internal.crash.zzn.zzb(:18)
        at com.google.android.gms.internal.crash.zzg.zzd(:13)
        at com.google.android.gms.internal.crash.zzc.run(:12)
        at com.google.android.gms.internal.crash.zzg.run(:15)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: java.lang.ExceptionInInitializerError
        at j.a.g.f$a.<init>(:372)
        at j.a.g.f.<init>(:19)
        at j.a.h.m.a(:32)
        at j.a.h.m.b(:42)
        at j.a.h.b.b(:56)
        at j.a.h.g.b(:100)
        at j.a.c.b(:58)
        at e.a.a.a.h.b$a.onResponse(:87)
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(:68)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7615)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
     Caused by: java.lang.IllegalStateException: Could not read resource entities-xhtml.properties. Make sure you copy resources for j.a.g.i
        at j.a.g.i.b(:301)
        at j.a.g.i.a(:25)
        at j.a.g.i$b.<init>(:53)
        at j.a.g.i$b.<clinit>(:34)
        at j.a.g.f$a.<init>(:372) 
        at j.a.g.f.<init>(:19) 
        at j.a.h.m.a(:32) 
        at j.a.h.m.b(:42) 
        at j.a.h.b.b(:56) 
        at j.a.h.g.b(:100) 
        at j.a.c.b(:58) 
        at e.a.a.a.h.b$a.onResponse(:87) 
        at retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall$1$1.run(:68) 
        at android.os.Handler.handleCallback(Handler.java:883) 
        at android.os.Handler.dispatchMessage(Handler.java:100) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.app.ActivityThread.main(ActivityThread.java:7615) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) 

원인은  jsoup라이브러리에 있다. 난독화를 하였더니 entites-xhtmlproperties 리소스를 찾지 못하는 오류가 발생하였다.

해결법은 proguard-ruls.pro 파일을 열고 난독화 예외 코드를 추가해야한다.

 

■proguard-rules.pro 파일

-keep class org.jsoup.** 

 

모든 클래스의 예외처리가 싫다면 public 클래스만 예외하는 방법도 있다. 오류는 발생하지 않는다. 그러나 제대로 동작하지 않는다.

-keepnames class org.jsoup.nodes.Entities
-keep public class org.jsoup.** { public *; }

 

 

[reference]

https://stackoverflow.com/questions/40703857/android-jsoup-exceptionininitializererror

Leave a Reply

error: Content is protected !!