henninghall / react-native-date-picker

React Native Date Picker is datetime picker for Android and iOS. It includes date, time and datetime picker modes. The datepicker is customizable and is supporting different languages. It's written with native code to achieve the best possible look, feel and performance.
MIT License
2.25k stars 344 forks source link

Android app crash when open the datepicker #165

Closed sindu12jun closed 4 years ago

sindu12jun commented 4 years ago

Describe the bug When open the screen contains the date picker in App in Android, the app will instantly crash and exit

Expected behavior The app should display the date picker without crashing

To Reproduce Add example code that reproduces the behavior.

        <ReactDatePicker
          mode={mode}
          date={tempMomentValue.toDate()}
          onDateChange={(date) => {
            setTempMomentValue(moment(date))
          }}/>

Smartphone (please complete the following information):

Error Log This is the error log in android studio

2020-02-19 11:19:20.605 11528-11528/com.billiapprn6 E/AndroidRuntime: FATAL EXCEPTION: main Process: com.billiapprn6, PID: 11528 java.lang.NoClassDefFoundError: Failed resolution of: Lnet/time4j/android/ApplicationStarter; at com.henninghall.date_picker.DatePickerManager.createViewInstance(DatePickerManager.java:32) at com.henninghall.date_picker.DatePickerManager.createViewInstance(DatePickerManager.java:16) at com.facebook.react.uimanager.ViewManager.createViewInstance(ViewManager.java:139) at com.facebook.react.uimanager.ViewManager.createView(ViewManager.java:82) at com.facebook.react.uimanager.NativeViewHierarchyManager.createView(NativeViewHierarchyManager.java:269) at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute(UIViewOperationQueue.java:179) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.dispatchPendingNonBatchedOperations(UIViewOperationQueue.java:972) at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:943) at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:28) at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:174) at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:84) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:947) at android.view.Choreographer.doCallbacks(Choreographer.java:761) at android.view.Choreographer.doFrame(Choreographer.java:693) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7050) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965) Caused by: java.lang.ClassNotFoundException: Didn't find class "net.time4j.android.ApplicationStarter" on path: DexPathList[[zip file "/data/app/com.billiapprn6-jfs-cyvifH4UlZBlt6kj0Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.billiapprn6-jfs-cyvifH4UlZBlt6kj0Q==/lib/arm64, /data/app/com.billiapprn6-jfs-cyvifH4UlZBlt6kj0Q==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

henninghall commented 4 years ago

Hi! Does it only happen in production when you're using proguard? In that case see https://github.com/henninghall/react-native-date-picker/blob/master/README.md#why-does-the-android-app-crash-in-production

henninghall commented 4 years ago

In other cases, could you provide an example where the values of the variables are visible?

sindu12jun commented 4 years ago

Hi, sorry about that, here's the simpler one case which will crash:

<ReactDatePicker mode={'date'} date={new Date()} onDateChange={(date) => { console.log(date); }}/>

And, I am running in develop mode, also tried the suggestion in https://github.com/henninghall/react-native-date-picker/blob/master/README.md#why-does-the-android-app-crash-in-production, but still the same

henninghall commented 4 years ago

Ok thanks, could you try these solutions?

  1. https://stackoverflow.com/a/45320244/3522683

  2. https://stackoverflow.com/a/22959847/3522683

  3. https://stackoverflow.com/a/56875424/3522683

sindu12jun commented 4 years ago

Thank you for your suggestion, I tried but doesn't change, it might not be an issue with this library anyway, I might change it to a mask input, thank you

henninghall commented 4 years ago

Hmm it feels like it has to do with some Android config and related to the time4j library that datepicker is dependent on. I'm happy to try to figure it out if you want!

What is your targetsdkverion, compilesdkversion and which android version are you running on the phone?

sindu12jun commented 4 years ago

Hi, thank you very much!

Here is my compile configuration: buildToolsVersion = "28.0.3" minSdkVersion = 23 compileSdkVersion = 28 targetSdkVersion = 28 I am running on android 9, thanks again!

virendravidyarthee commented 4 years ago

@henninghall Getting the same issue on android pie and up. Any updates on this?

felixspitzer commented 4 years ago

https://stackoverflow.com/questions/21814825/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity

Try this one ! It fixed the issue for me. Don't forget to clean and rebuild the project

felixspitzer commented 4 years ago

@sindu12jun @virendravidyarthee Have a look at my comment above

henninghall commented 4 years ago

I haven't managed to reproduce this so far. If anyone could share a full example where this is present it would help a lot!

felixspitzer commented 4 years ago

For me it was a missing style at the activity in the AndroidManifest.xml of my project. So maybe if you remove that, you can reproduce it. It became an error after installing your package. Maybe it relies on some resources of AppCompat ?

henninghall commented 4 years ago

Did you get the same error as in the Stackoverflow thread? ie the

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

Seems like a different error than the one sindu12jun got:

java.lang.NoClassDefFoundError: Failed resolution of: Lnet/time4j/android/ApplicationStarter
felixspitzer commented 4 years ago

You are right. Maybe it is unrelated to the mentioned error. The behaviour was the same though.

virendravidyarthee commented 4 years ago

@henninghall @felixspitzer Thanks for your responses. Turns out, it was crashing due to an old gradle plugin version. Updated our gradle and it started working like a charm.

henninghall commented 4 years ago

Great to hear! Thanks for letting us know 🙂