joshuapinter / react-native-unified-contacts

Your best friend when working with the latest and greatest Contacts Framework in iOS 9+ in React Native.
MIT License
158 stars 56 forks source link

[Android] Pointer issue #70

Closed paintedbicycle closed 6 years ago

paintedbicycle commented 6 years ago

Hey,

When I use the exampleApp everything works fine, so it's definitely something I'm doing. Additionally, my iOS app is also working fine - but I'm having some trouble with my android app. My app loads but crashes when I interact with it.

Does the below stack trace point you in any direction? I'm not strong with Java and so have been struggling with this and getting nowhere.

screen shot 2018-05-10 at 1 10 58 pm
joshuapinter commented 6 years ago

Hmm, is this on master? Did this just start happening after a fresh pull from master?

What ReactNativeUnifiedContacts commands are you calling from your app? Have you isolated the problematic method?

I'll know move from the above questions, but also check the following in your MainActivity:

  1. Make sure your MainActivity implements ActivityCompat.OnRequestPermissionsResultCallback. It should look something like this:
public class MainActivity extends ReactActivity implements ActivityCompat.OnRequestPermissionsResultCallback {
  1. Add the following override method:
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {

  RNUnifiedContactsPackage.onRequestPermissionsResult( requestCode, permissions, grantResults );

}
paintedbicycle commented 6 years ago

I added the lines you mention above, but it didn't solve the problem. Same error.

screen shot 2018-05-10 at 8 00 16 pm

The issue isn't new to this new build, no. Yes I'm currently using master.

joshuapinter commented 6 years ago

That looks like a different error, no?

paintedbicycle commented 6 years ago

Hmm, yes I guess so. They're both pointer issues and both from working on this today and are from crashes at the same point in the app. But they affect different lines. The second one is after changing the lines that you mentioned.

I can keep working on it myself but to be honest I'm out of ideas. I've sunk more than a day of effort into it. I've commented out most of the RNUnifedContacts calls in my app and still experiencing it. Super strange. Let me know what those line numbers make you think of and I can investigate.

joshuapinter commented 6 years ago

Do you know what line of your code triggers this error?

paintedbicycle commented 6 years ago

I haven't been able to pinpoint it yet - it's not even coming from the page that contains the contacts, which is why I'm having so much trouble with it. I've commented out the Contacts method calls and tried commenting out various views across the app. Sort of driving me crazy. The app loads but an unrelated action crashes the app and when I look at the logs, it mentions your module even though I wasn't interacting with contacts on that page and don't call your module at all.

I guess I'll need to start ripping RNUnifiedContacts out of my app and putting it back in. So frustrating that iOS is working fine.

My original thought was that it was because I was using one method you haven't put into Android yet (alreadyRequestedAccessToContacts) but I've removed that and it doesn't solve it.

joshuapinter commented 6 years ago

Ugh, I know that feeling. Super frustrating!

Are you using selectContact at all?

joshuapinter commented 6 years ago

I properly added/fixed the selectContact in Android, which might fix your issue. It's in master so give it a try and let me know how it goes.

This marks the first method in Android that isn't available in iOS. Whoop! 😜

paintedbicycle commented 6 years ago

No, I wasn't using it. But we can close this until I learn more.

I am using alreadyRequestedAccessToContacts though. I commented it out, but would be good to get it added to finalize the permissions on Android. I believe Android has the same states as iOS - I think there is an UNDEFINED state we can check for. I couldn't quite get my patch to work but let me know if you find out a good way to do it.

joshuapinter commented 6 years ago

Dang. I'm going to re-open this and if I can get you to track down the line of your code that is causing the error in Android, that would be great. I don't want to ignore this as other people might run into, too, so I'd like a paper trail of a solution.

paintedbicycle commented 6 years ago

Could it be anything about installation? It was working totally fine for me, but I have changed quite a few things in my app.

The reason I ask is that my app opens fine but when I interact with my app (in my case taking a photo), the photo gets taken, but then my app crashes. There is no use of contacts here and contacts aren't even called in that component. So it seems very, very strange. And remember that everything is totally fine in iOS, no issues.

joshuapinter commented 6 years ago

Kay, I think I know what the issue is related to.

With Android, they use onActivityResult to handle situations where you're asking the user or the operating system to do something and then return something afterwards.

For example, this happens in selectContact when we launch and Intent to open the Contacts app and allow the user to select a Contact. After they select a Contact, it returns the details to a method called onActivityResult.

This also happens when taking a photo. It creates an Intent to open up the camera app and when the photo is taken (and accepted) it returns it to the onActivityResult.

Because React Native is kind of a special beast, there might be a collision of the library you're using for capturing photos (e.g. react-native-camera) and the Unified Contacts.

Until we can diagnose this a bit more, I'm going to disable the selectContact in Android, push that to master and I want you to try that to see if it works.

Sound good?

paintedbicycle commented 6 years ago

Very interesting. Ok, sure. Keep in mind I'm not using select contact. It's been an issue for me for about a month now. But I'm definitely willing to keep trying to get this working this weekend!

joshuapinter commented 6 years ago

If there's a collision with onActivityResult then it would happen even without using selectContact because the methods are still defined.

The reason the ExampleApp would still work fine is because there are no other react native libraries being included.

What camera library are you using?

paintedbicycle commented 6 years ago

Ok exciting. This has been a very difficult bug for me that has basically meant I've stopped work on Android version.

I'm using React Native Image Crop Picker: https://github.com/ivpusic/react-native-image-crop-picker

joshuapinter commented 6 years ago

I wish I knew about this earlier, we could have fixed it up! :)

Okay, pushed a new commit to master that disables selectContact and the use of onActivityResult.

I'm not sure if this will resolve the issue you're seeing but it should.

If you can use the fresh version from master in your app and test it out on Android, that would be great!

paintedbicycle commented 6 years ago

Sure thing, thanks for doing that. I'm at the end of the day here (GMT+2), but I'll happily do it tomorrow and report back.

joshuapinter commented 6 years ago

Sounds good! Have a great night.

paintedbicycle commented 6 years ago

Wow - just did a quick test and things are looking better. It didn't crash and I moved past that point in my app. I think that might have done the trick. An unrelated bug is happening that I'll try to fix tomorrow and let you know if it's an "all clear", but it does indeed appear to be fixed and that the new bug is part of my db, not the contacts. Thanks for the time working through this.

joshuapinter commented 6 years ago

celebrate

paintedbicycle commented 6 years ago

We're good. Thanks!

joshuapinter commented 6 years ago

👍