gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:54:05 24 4
gpt4 key购买 nike

由于从我正在使用的 API 返回的数据发生更改,我最近更改了 2 行代码作为解决方法。现在应用程序在使用发布 apk 和 aab 时崩溃。但是,当我通过 API 27 上的 Android Emulator 使用该应用程序并将 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

最佳答案

对我来说,添加行(你可能有你放置 POJO 文件的包的其他名称):

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

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

proguard.rules 完美运行,然后选项:
android
{
...

buildTypes {

release {

minifyEnabled true
shrinkResources true

}
}
}

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

关于Android 应用程序在 Release 中崩溃,但在 Debug NullPointerException 中没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56821567/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com