当 minifyEnabled 设置为 true 时,React Native Android 应用程序在发布版本中崩溃

问题描述 投票:0回答:1

在我的应用程序级别 build.gradle 文件中,我启用了缩小功能

buildTypes {
    debug {
        signingConfig signingConfigs.debug
    }
    release {
        signingConfig signingConfigs.release
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
}

然后,当我在 Android 设备中安装 apk 时,应用程序崩溃了。

当我从 Android Studio 检查 logcat 时,出现此错误。

FATAL EXCEPTION: mqt_native_modules
Process: com.skoolbag.singleapp, PID: 7895
java.lang.RuntimeException: Could not invoke RNQBSettingsModule.init
    at com.facebook.react.bridge.JavaMethodWrapper.invoke(Unknown Source:192)
    at com.facebook.react.bridge.JavaModuleWrapper.invoke(Unknown Source:147)
    at com.facebook.jni.NativeRunnable.run(Native Method)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(Unknown Source:0)
    at android.os.Looper.loopOnce(Looper.java:226)
    at android.os.Looper.loop(Looper.java:313)
    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(Unknown Source:37)
    at java.lang.Thread.run(Thread.java:1012)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)

正如类似问题中所建议的,我检查了 RNQBSettingsModule 的来源。

我发现的是这个 enter image description here

enter image description here

因此,我将以下代码添加到 android/app/proguard-rules.pro 文件中,以免混淆这个特定的包。

-keep class com.quickblox.reactnative.settings.** {*;}

但这并不能解决问题

android react-native gradle
1个回答
0
投票

我通过更新

android/app/proguard-rules.pro
文件修复了崩溃,如下所示。

为此,我遵循了

quickblox-android-sdk
的自述文件。

https://github.com/QuickBlox/quickblox-android-sdk/blob/master/README.md#customize-proguard-in-android-studio

上述步骤未记录在

quickblox-react-native-sdk
中。所以,我必须对比赛进行一些小改动。

# Adding minifyEnabled caused runtime crashes in the release build. To fix that I have added proguard rules relating to quickblox
# Refer to https://github.com/QuickBlox/quickblox-android-sdk/blob/master/README.md#customize-proguard-in-android-studio

##---------------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
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson

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

##---------------Begin: proguard configuration for quickblox  ----------

#quickblox auth module
-keep class com.quickblox.reactnative.auth.parsers.** { *; }
-keep class com.quickblox.reactnative.auth.model.** { *; }

#quickblox users module
-keep class com.quickblox.reactnative.users.parsers.** { *; }
-keep class com.quickblox.reactnative.users.model.** { *; }

#quickblox chat module
-keep class com.quickblox.reactnative.chat.parser.** { *; }
-keep class com.quickblox.reactnative.chat.model.** { *; }
-keep class org.jivesoftware.** { *; }
-keep class org.jxmpp.** { *; }
-dontwarn org.jivesoftware.smackx.**

#quickblox videochat-webrtc module
-keep class org.webrtc.** { *; }

##---------------End: proguard configuration for quickblox  ----------

##---------------End: proguard configuration ----------
© www.soinside.com 2019 - 2024. All rights reserved.