Reputation: 31
When creating a release using the build.gradle build variant below, I keep getting an app crash when I launch it. It has something to do with the logger, but I cannot seem to find out why it is happening with Proguard / minify enabled, while it works great without it. I would like my code to be as compact and obfuscated as possible, so disabling Proguard is not an option. I've added statements like "keep org.apache", but it won't work. How can I fix this issue? I cannot seem to find any answer anywhere, most of the answers I could find were regarding something like "smack, where they suggest keeping the org.apache class, but that didn't solve the issue.
EDIT:
There also is a warning coming from R8, with the following message: The method
void org.apache.commons.logging.impl.Log4JLogger.<clinit>() does not type check and will be assumed to be unreachable.
Build.gradle
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
Proguard-rules.pro
-keep class io.ktor.** { *; }
-dontwarn org.slf4j.**
-keep class org.apache.** { *; }
-keep class org.apache.commons.logging.** { *; }
-keep class kotlin.reflect.jvm.internal.** {*;}
-keep class kotlin.text.RegexOption {*;}
-keep class org.apache.log.** { *; }
-dontwarn org.apache.log.**
-keep class org.apache.log4j.** { *; }
-dontwarn org.apache.log4j.**
-keep class org.apache.avalon.** { *; }
-dontwarn org.apache.avalon.**
-keep class javax.servlet.** { *; }
-dontwarn javax.servlet.**
Crash
--------- beginning of crash
2020-02-01 12:13:42.928 23076-23152/? E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-2
Process: com.my.app, PID: 23076
java.lang.ExceptionInInitializerError
at b84.resumeWith(Unknown Source:11)
at kotlinx.coroutines.DispatchedTask.run(Unknown Source:80)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(Unknown Source:83)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Unknown Source:29)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Unknown Source:86)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:0)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Unknown Source:6)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:0)
at b84.resumeWith(Unknown Source:11)
at kotlinx.coroutines.DispatchedTask.run(Unknown Source:80)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(Unknown Source:5)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(Unknown Source:14)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(Unknown Source:28)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(Unknown Source:0)
Caused by: org.apache.commons.logging.LogConfigurationException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference (Caused by java.lang.NullPointerException: Attempt to invoke virtual
method 'java.lang.String java.lang.String.trim()' on a null object reference)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(Unknown Source:43)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(Unknown Source:10)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(Unknown Source:4)
at org.apache.commons.logging.LogFactory.getLog(Unknown Source:4)
at org.apache.http.conn.ssl.DefaultHostnameVerifier.<init>(Unknown Source:5)
at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(Unknown Source:79)
at io.ktor.client.engine.apache.ApacheEngine.prepareClient(Unknown Source:76)
at io.ktor.client.engine.apache.ApacheEngine.<init>(Unknown Source:23)
at io.ktor.client.engine.apache.Apache.create(Unknown Source:15)
at io.ktor.client.HttpClientKt.HttpClient(Unknown Source:22)
at io.ktor.client.HttpClientJvmKt.HttpClient(Unknown Source:7)
at io.ktor.client.HttpClientJvmKt.HttpClient$default(Unknown Source:6)
at b84.resumeWith(Unknown Source:11)
at kotlinx.coroutines.DispatchedTask.run(Unknown Source:80)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(Unknown Source:83)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Unknown Source:29)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Unknown Source:86)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:0)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Unknown Source:6)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:0)
at b84.resumeWith(Unknown Source:11)
at kotlinx.coroutines.DispatchedTask.run(Unknown Source:80)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(Unknown Source:5)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(Unknown Source:14)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(Unknown Source:28)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(Unknown Source:0)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference
at org.apache.commons.logging.impl.LogFactoryImpl.createLogFromClass(Unknown Source:400)
at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(Unknown Source:126)
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(Unknown Source:6)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(Unknown Source:10)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(Unknown Source:4)
at org.apache.commons.logging.LogFactory.getLog(Unknown Source:4)
at org.apache.http.conn.ssl.DefaultHostnameVerifier.<init>(Unknown Source:5)
at org.apache.http.impl.nio.client.HttpAsyncClientBuilder.build(Unknown Source:79)
at io.ktor.client.engine.apache.ApacheEngine.prepareClient(Unknown Source:76)
at io.ktor.client.engine.apache.ApacheEngine.<init>(Unknown Source:23)
at io.ktor.client.engine.apache.Apache.create(Unknown Source:15)
at io.ktor.client.HttpClientKt.HttpClient(Unknown Source:22)
at io.ktor.client.HttpClientJvmKt.HttpClient(Unknown Source:7)
at io.ktor.client.HttpClientJvmKt.HttpClient$default(Unknown Source:6)
at b84.resumeWith(Unknown Source:11)
at kotlinx.coroutines.DispatchedTask.run(Unknown Source:80)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(Unknown Source:83)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Unknown Source:29)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Unknown Source:86)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:0)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Unknown Source:6)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:0)
at b84.resumeWith(Unknown Source:11)
at kotlinx.coroutines.DispatchedTask.run(Unknown Source:80)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(Unknown Source:5)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(Unknown Source:14)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(Unknown Source:28)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(Unknown Source:0)
Upvotes: 2
Views: 801
Reputation: 173
I also encountered similar exception and spent several days struggling with it until I found the discussion in https://github.com/nextcloud/android-library/issues/411.
In short words, if you need a workaround, I think you could try to add
<application
...>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
inside your AndroidManifest.xml.
Upvotes: 2