Android-приложение вылетает в Release, но не в Debug NullPointerException - PullRequest
0 голосов
/ 30 июня 2019

Недавно я изменил 2 строки кода в качестве обходного пути из-за изменений в данных, возвращаемых из API, который я использую. Теперь происходит сбой приложения при использовании релиза apk и aab. Однако, когда я использую приложение через эмулятор Android на API 27 и подключаю устройство 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
...