构建项目时,没有错误。
但是在安装并启动应用后,应用已关闭。
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":"..."}
和我的gradle
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