I made a react app and it was working fine using the expo app to test it. I built in for production and on my phone I found it would open once and crash every other time if it would open after building. (I am using android 13) I sent it to a friend using android 11 and it works perfectly. I believe the problem is with one of the packages I am using.
So I have changed and some of the packages and added information in the app.json
file as I have seen on other stackoverflow posts but have not had any luck.
app.json
{
"expo": {
"name": "Finder",
"slug": "finder",
"version": "2.3.1",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "apple.spoonfinder.ml"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
},
"package": "com.im_the_tea_drinker.spoon_finder"
},
"web": {
"favicon": "./assets/icon.png"
},
"extra": {
"eas": {
"projectId": "2f14cfae-f990-4aab-9d8e-ca06ea8bec1d"
}
}
}
}
These are the packages that I am using
{
"name": "finder",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"expo": "~47.0.8",
"expo-cli": "^6.0.8",
"expo-location": "~15.0.1",
"expo-permissions": "~14.0.0",
"expo-sensors": "~12.0.1",
"expo-status-bar": "~1.4.2",
"geolib": "^3.3.3",
"react": "18.1.0",
"react-dom": "18.1.0",
"react-native": "0.70.5"
},
"devDependencies": {
"@babel/core": "^7.19.3"
},
"private": true
}
Does any one know what could be causing this and how I can fix it?
So the problem was the expo sensor functions were some times returning undefined, to all we had to do is check if it was true. This was the fix.
DeviceMotion.setUpdateInterval(200);
DeviceMotion.addListener((motion) => {
let heading = 0
//check if heading is available
if ( motion?.rotation?.alpha ) {
heading = motion.rotation.alpha;
heading = heading * (180 / Math.PI);
heading = heading - angle;
if (heading < 0) {
heading = 360 + heading;
}
heading -= 90;
setAngle(heading);
}
});