首页 > 解决方案 > 如何解决 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

标签: android

解决方案


推荐阅读