birkir / react-native-carplay

CarPlay with React Native
https://birkir.dev/react-native-carplay/
MIT License
669 stars 111 forks source link

Crashes on Android if imported #35

Closed nixolas1 closed 3 years ago

nixolas1 commented 3 years ago

Hey! We have an app for android and iOS and wanted to try this out for iOS, but the app crashes for Android if one imports CarPlay, even if no functions are run. Would be nice if it just didn't do anything when run on Android!

I'll try some conditional requires, but not sure if that will work.

Error when app inits on android: TypeError: Cannot read property 'checkForConnection' of null, js engine: hermes

Other than that, does the Point of Interest Template work at all?

nixolas1 commented 3 years ago

Made conditional require work, at least for the startup stuff! useEffect(() => { if (isIos) { return require("../components/carPlay/carPlay").startup() } })

birkir commented 3 years ago

Would it work if we included an empty “index.android.js” with the npm package? Or should we maybe only ship index.ios.js

lostchopstik commented 3 years ago

Hey there. We ran into the same issue with an Android and iOS app implementation. I cloned down this repo and tried out the local android example and it fails as well. Changing the index.ts to index.ios.ts didn't seem to work, the example project still crashed. Also tried creating a blank index.android.ts next to the index.ios.ts but that didn't change anything either.

I'll keep playing with it to see if I can find a package-side solution before implementing a project-side one, but it's certainly not my area of expertise 😁

nixolas1 commented 3 years ago

Did you find a solution in the end, @lostchopstik ?

lostchopstik commented 3 years ago

@nixolas1 sadly no, we ended up implementing a fully native CarPlay implementation of our own.

nixolas1 commented 3 years ago

Figured it out: const {CarPlayApp} = isIos ? require("../views/carPlay/CarPlayApp") : {CarPlayApp: () => null}

Where CarPlayApp is something like App in the example