android - 如何解决 minifyEnabled true 的错误?
问题描述
构建项目时,没有错误。
但安装并启动应用程序后,应用程序已关闭。
ProjectApi.loginWithDevice(deviceId)
.subscribe(object : DisposableObserver<Response<Resp<User>>>() {
override fun onNext(resp : Response<Resp<User>>) {
if (!resp.isSuccessful) {
Toast.makeText(this@Splash, R.string.connectServerError, Toast.LENGTH_SHORT).show()
return
}
val response = resp.body()!!
goToMainActivity = if (0 == response.result && ("join" == response.msg || "login" == response.msg)) {
Hawk.put("user", response.data!!)
true
}
else {
Toast.makeText(this@Splash, response.msg!!, Toast.LENGTH_SHORT).show()
false
}
if (animationEnd) {
startActivity(Intent(this@Splash, MainActivity::class.java))
finish()
}
}
override fun onError(e : Throwable) {
e.printStackTrace()
Toast.makeText(this@Splash, R.string.connectServerError, Toast.LENGTH_SHORT).show()
}
override fun onComplete() {
}
})
OkHttp 结果是{"result":0,"msg":"login", "data":"..."}
和我的毕业生
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
使用上述代码,我认为没有任何可疑代码。
Logcat 中的错误消息是这样的。
W/System.err: c.a
W/System.err: at com.my.project.Splash$c.a(Splash.kt:99)
W/System.err: at com.my.project.Splash$c.a_(Splash.kt:86)
W/System.err: at a.b.e.e.b.g$a.a_(ObservableUnsubscribeOn.java:60)
W/System.err: at a.b.e.e.b.c$a.f(ObservableObserveOn.java:201)
W/System.err: at a.b.e.e.b.c$a.run(ObservableObserveOn.java:255)
W/System.err: at a.b.a.b.b$b.run(HandlerScheduler.java:124)
W/System.err: at android.os.Handler.handleCallback(Handler.java:751)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err: at android.os.Looper.loop(Looper.java:154)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6682)
W/System.err: at java.lang.reflect.Method.invoke(Native Method)
W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
第 99 行代码是Toast.makeText(this@Splash, response.msg!!, Toast.LENGTH_SHORT).show()
如果去掉 minifyEnable 或设置为 False,则没有错误。\
如何解决这个错误?
编辑。
proguard-rules.pro
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
# -renamesourcefileattribute SourceFile
-ignorewarnings
解决方案
推荐阅读
- swift - 从显示用户名称的文本字段在 firebase 数据库中创建一个名为用户 uid 的节点
- c# - 有多少种不同的方法可以从大小为 n 的数组中选择 K 个元素但不重复
- watchos - SwiftUI TabView on WatchOS breaks when a ScrollView is nested inside. SwiftUI bug or coding error?
- ssis - an "Invalid Class String" error when saving SSIS
- php - Google Cloud Platform - Server running PHP 7.3x however Wordpress says 7.0x - How do I get WP to run on 7.3x?
- node.js - 如何在 DigitalOcean 中限制对 Express API 的访问
- rest - 使用 HTTP 请求将用户插入 SharePoint 组
- android - Can't use firebase function emulator : INTERNAL ERROR
- html - span 标签上的 CSS Transform 元素(连同 display: inline-block)正在强制换行
- python - object has no attribute 'zero_state' [Tensorflow 2.0]