[Android] App crashes on release mode
Describe the bug App crashes when displaying the date picker modally on Android devices in release mode
Expected behavior App shouldn't crash
To Reproduce
export default class App extends Component {
state = { date: new Date() }
render = () =>
<DatePicker
date={this.state.date}
onDateChange={date => this.setState({ date })}
modal
theme="light"
mode={'date'}
locale="vi-VN"
cancelText="Bỏ qua"
confirmText="Xác nhận"
/>
}
Smartphone (please complete the following information):
- OS: Android 9, 10, 13 (Google Pixel 5, Samsung Galaxy A8, A13, Oppo F9)
- React Native version 0.70.6
- react-native-date-picker version 4.2.13
Crash logs:
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
at com.henninghall.date_picker.State.getTimeZone(State.java:8)
at com.henninghall.date_picker.State.getMinimumDate(State.java:2)
at com.henninghall.date_picker.wheels.YearWheel.getStartYear(YearWheel.java:2)
at com.henninghall.date_picker.wheels.YearWheel.getValues(YearWheel.java:9)
at com.henninghall.date_picker.wheels.Wheel.init(Wheel.java:11)
at com.henninghall.date_picker.wheels.Wheel.refresh(Wheel.java:24)
at com.henninghall.date_picker.wheelFunctions.Refresh.apply(Refresh.java)
at com.henninghall.date_picker.ui.Wheels.applyOnAll(Wheels.java:20)
at com.henninghall.date_picker.ui.UIManager.updateDisplayValues(UIManager.java:7)
at com.henninghall.date_picker.PickerView.update(PickerView.java:206)
at com.henninghall.date_picker.DatePickerModule.createPicker(:49)
at com.henninghall.date_picker.DatePickerModule.openPicker()
at java.lang.reflect.Method.invoke(Method.java)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(:148)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(:147)
at com.facebook.jni.NativeRunnable.run(SourceFile)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage()
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(:37)
at java.lang.Thread.run(Thread.java:1012)
I wonder how many apps are straight up broken because of this. We're seeing the same issue. Any known workarounds?
Hi @Joshuapwilley Here's the patch I'm applying:
diff --git a/node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/State.java b/node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/State.java
index d8ea35f..5b986a7 100644
--- a/node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/State.java
+++ b/node_modules/react-native-date-picker/android/src/main/java/com/henninghall/date_picker/State.java
@@ -24,6 +24,7 @@ import java.util.Calendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.TimeZone;
+import android.util.Log;
public class State {
@@ -99,16 +100,23 @@ public class State {
return Utils.isoToCalendar(maximumDateProp.getValue(), getTimeZone());
}
+
public TimeZone getTimeZone() {
- Integer offset = timezoneOffsetInMinutesProp.getValue();
- if(offset == null) return TimeZone.getDefault();
- int totalOffsetMinutes = Math.abs(offset);
- char offsetDirection = offset < 0 ? '-' : '+';
- int offsetHours = (int) Math.floor(totalOffsetMinutes / 60f);
- int offsetMinutes = totalOffsetMinutes - offsetHours * 60;
- String timeZoneId = "GMT" + offsetDirection + offsetHours + ":" + Utils.toPaddedMinutes(offsetMinutes);
- TimeZone zone = TimeZone.getTimeZone(timeZoneId);
- return zone;
+ try {
+ Integer offset = timezoneOffsetInMinutesProp.getValue();
+ if(offset == null) return TimeZone.getDefault();
+ int totalOffsetMinutes = Math.abs(offset);
+ char offsetDirection = offset < 0 ? '-' : '+';
+ int offsetHours = (int) Math.floor(totalOffsetMinutes / 60f);
+ int offsetMinutes = totalOffsetMinutes - offsetHours * 60;
+ String timeZoneId = "GMT" + offsetDirection + offsetHours + ":" + Utils.toPaddedMinutes(offsetMinutes);
+ TimeZone zone = TimeZone.getTimeZone(timeZoneId);
+ return zone;
+ }
+ catch (Exception ex) {
+ Log.e("RNDatePicker", "getTimeZone() failed", ex);
+ return TimeZone.getDefault();
+ }
}
public String getIsoDate() {
You are not using a valid combination of props, when using the modal you need to use onConfirm and onCancel, see example https://github.com/henninghall/react-native-date-picker#example-1-modal
If you still have this issue after adding those props, let us know and I'll reopen the issue.
I have both props and had this issue. The proposed patch worked for me, however.
Are you using proguard? In that case, have you added the lines as described in readme?
I was able to reproduce this too when upgrading the library from 4.2.2 to 4.2.14, only on release mode on a physical device. I fixed it by downgrading from 4.2.14 to 4.2.2 to avoid patching this package.
You are not using a valid combination of props, when using the modal you need to use onConfirm and onCancel, see example https://github.com/henninghall/react-native-date-picker#example-1-modal
If you still have this issue after adding those props, let us know and I'll reopen the issue.
Hi @henninghall Sorry for the late reply
I had all the required props, just deleted them when posting here because of some inner processing. I also updated the progard-rules as described in README.
I was able to reproduce this too when upgrading the library from 4.2.2 to 4.2.14, only on release mode on a physical device. I fixed it by downgrading from 4.2.14 to 4.2.2 to avoid patching this package.
thank y, downgrade version helped me in my case.
I was able to reproduce this too when upgrading the library from 4.2.2 to 4.2.14, only on release mode on a physical device. I fixed it by downgrading from 4.2.14 to 4.2.2 to avoid patching this package.
Downgrading to 4.2.2 helped me. In my case, the problem was related to the day picker re-rendering
A similar issue was solved by clearing the cache on the phone for the specific app.
A fix for this is released in 4.3.4. Let me know if you still are seeing this after that version update.