首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android Apache Logger在生产中无缘无故地崩溃(发布版)

Android Apache Logger在生产中无缘无故地崩溃(发布版)
EN

Stack Overflow用户
提问于 2020-02-01 14:52:36
回答 1查看 504关注 0票数 2

当使用下面的build.gradle构建变体创建一个发行版时,我总是在启动它时出现应用程序崩溃。这与记录器有关,但我似乎找不出为什么它是在启用Proguard / minify的情况下发生的,而如果没有它,它就会工作得很好。我希望我的代码尽可能紧凑和模糊,所以禁用Proguard不是一种选择。我添加了诸如“保存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.

Build.gradle

代码语言:javascript
运行
复制
release {
    minifyEnabled true
    proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}

Proguard-rules.pro

代码语言:javascript
运行
复制
-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.**

崩溃

代码语言:javascript
运行
复制
--------- 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) 
EN

回答 1

Stack Overflow用户

发布于 2021-04-09 08:55:33

我也遇到了类似的异常,并花了几天时间与它斗争,直到我在https://github.com/nextcloud/android-library/issues/411中找到了讨论。

简而言之,如果你需要一个解决办法,我想你可以尝试加入

代码语言:javascript
运行
复制
<application
    ...>

    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false" />

</application>

在你的AndroidManifest.xml里面。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60018008

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档