Android应用程序在Release中崩溃,但在Debug NullPointerException中没有崩溃

时间:2019-06-29 23:52:45

标签: android nullpointerexception crash

由于我正在使用的API返回的数据发生更改,因此我最近更改了两行代码作为解决方法。现在,使用发行版apk和aab时,应用程序崩溃了。但是,当我通过API 27上的Android仿真器使用该应用程序并将API 27设备连接到运行调试apk的计算机时,该应用程序可以正常运行。

我真的对这个问题感到困惑,根本不理解错误消息。

FATAL EXCEPTION: main
Process: com.guy.aqi, PID: 8328
java.lang.NullPointerException: throw with null exception
    at com.guy.aqi.n.a(Unknown Source:3)
    at com.guy.aqi.m.b(CurrentAirQualityFragment.java:8)
    at com.guy.aqi.m.b(CurrentAirQualityFragment.java:6)
    at com.guy.aqi.d.a(Unknown Source:4)
    at b.a.a.a.m.c(StringRequest.java:4)
    at b.a.a.a.m.a(StringRequest.java:1)
    at b.a.a.h$a.run(ExecutorDelivery.java:4)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

我的API停止发送“主要污染物”字符串,因此我更改了这一行:

textViewMainPollutantUS.setText("U.S. Main Pollutant: " decodePollutant(mainPollutantUS));

textViewMainPollutantUS.setText("");

和这一行:

textViewMainPollutantCN.setText("China Main Pollutant: " decodePollutant(mainPollutantCN));

textViewMainPollutantCN.setText("");

我希望更改这些行将解决此问题。但现在,该问题似乎已在该应用的调试版本中得以解决,但在发行版本中未得到解决。

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

# JSR 305 annotations are for embedding nullability information.
-dontwarn javax.annotation.**

# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*

# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform

# Prevent Proguard from inlining methods that are intentionally extracted to ensure locals have a
# constrained liveness scope by the GC. This is needed to avoid keeping previous request references
# alive for an indeterminate amount of time. See also https://github.com/google/volley/issues/114
-keepclassmembers,allowshrinking,allowobfuscation class com.android.volley.NetworkDispatcher {
    void processRequest();
}
-keepclassmembers,allowshrinking,allowobfuscation class com.android.volley.CacheDispatcher {
    void processRequest();
}

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

##---------------End: proguard configuration for Gson  ----------

-keep class com.crashlytics.** { *; }
-keepattributes SourceFile,LineNumberTable

1 个答案:

答案 0 :(得分:1)

对我来说,添加行(您可能在将POJO文件放入其中的程序包中使用其他名称):

-keep class [mypackagename].model.** { *; }

-keep class [mypackagename].datamodel.** { *; }

到proguard.rules效果很好,然后选择:

android
{
    ...

    buildTypes {

        release {

            minifyEnabled true 
            shrinkResources true

        }
    }
}

在build.gradle中设置(模块:应用)