使用下面的 build.gradle 构建变体创建版本时,我在启动应用程序时不断遇到应用程序崩溃的情况。它与记录器有关,但我似乎无法找出为什么在启用 Proguard/minify 的情况下会发生这种情况,而在没有启用它的情况下它也能很好地工作。我希望我的代码尽可能紧凑和困惑,因此禁用 Proguard 不是一个选择。我添加了诸如“keep org.apache”之类的语句,但它不起作用。我该如何解决这个问题?我似乎无法在任何地方找到任何答案,我能找到的大多数答案都是关于“smack”之类的内容,他们建议保留 org.apache 类,但这并没有解决问题。
编辑:
还有来自 R8 的警告,其中包含以下消息:The method
void org.apache.commons.logging.impl.Log4JLogger.<clinit>() does not type check and will be assumed to be unreachable.
构建.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.**
崩溃
--------- 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)
最佳答案
我也遇到了类似的异常,并花了几天的时间来解决它,直到我在https://github.com/nextcloud/android-library/issues/411中找到了讨论.
简而言之,如果您需要解决方法,我认为您可以尝试添加
<application
...>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
在 AndroidManifest.xml 中。
关于java - Android Apache Logger 在生产(发布版本)中无故崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60018008/