Reputation: 129
I've been working on an app, and I have been using both the Android emulator and my Android device for testing using Expo.
It works great, everything goes perfect. However, I just built an Android APK (I executed expo build:android
), and I can see the login of my app, but after introducing credentials, it kinda shows like it closes the app and then restores it, but now it keeps showing just a blank screen.
Here is a gif showing you exactly what happens.
https://giphy.com/gifs/hdtXNeM2s5Dx7FnbNJ
Also, here's the code of my App.js, which works showing the <AuthNavigator />
(The login screen), but it stops working when a user is set and then <AppNavigator />
does not appear.
import React, { useState } from "react";
import { StyleSheet } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { AppLoading } from "expo";
import AppNavigator from "./app/navigation/AppNavigator";
import AuthNavigator from "./app/navigation/AuthNavigator";
import AuthContext from "./app/auth/context";
import authStorage from "./app/auth/storage";
export default function App() {
const [user, setUser] = useState();
const [isReady, setIsReady] = useState(false);
const restoreUser = async () => {
const user = await authStorage.getUser();
if (user) setUser(user);
};
if (!isReady) {
return (
<AppLoading startAsync={restoreUser} onFinish={() => setIsReady(true)} />
);
}
return (
<AuthContext.Provider value={{ user, setUser }}>
<NavigationContainer>
{user ? <AppNavigator /> : <AuthNavigator />}
</NavigationContainer>
</AuthContext.Provider>
);
}
Also my app.json, just in case it's needed:
{
"expo": {
"name": "Agro-Mobile",
"slug": "Agro-Mobile",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./app/assets/icon.png",
"splash": {
"image": "./app/assets/splash.png",
"resizeMode": "cover",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true
},
"android": {
"package": "com.smartbase.agrocognitive",
"versionCode": 1
},
"web": {
"favicon": "./app/assets/favicon.png"
},
"description": ""
}
}
Upvotes: 2
Views: 9550
Reputation: 21
"I resolved this issue by running the following command:
npm install react-native-screens react-native-safe-area-context
This fixed the problem."
As of November 10, 2024, I ran npx expo run:android --device
to test the app. It helped identify missing packages and other issues. After addressing those, I was able to get everything working properly
Upvotes: 1
Reputation: 21
Problem: Expo build APK not working or crash issue
Solution: If you're facing issues with building an APK in Expo, try the following steps:
First, make sure to install the required dependencies. Run the following command in your terminal:
npm install react-native-screens react-native-safe-area-context
These libraries are essential for your project, so ensure they are installed properly.
After that, navigate to your app.json
or App.js
file and add or update the versionCode
property under the Android configuration. This ensures versioning is correctly set up for your APK. Here's an example:
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"package": "com.sachin1203.ConnectSolutions",
"versionCode": 1
}
By following these steps, you should be able to resolve the APK build issue. Let me know if this helps your Sachin Pandey
Upvotes: 0
Reputation: 11
Installing the packages react-native-screens
and react-native-safe-area-context
solved the issue for me.
npm install react-native-screens react-native-safe-area-context
Upvotes: 1
Reputation: 21
In app.json you need change:
"android": {
"package": "com.smartbase.agrocognitive",
"versionCode": 1
for this
"android": {
"package": "com.agrocognitive.agrocognitive",
"versionCode": 1
in other words you need only change the name of company for the name of your app, make sure use only lowercase characters without simbol. The folder that your create have the same name of your app. And for other people delete any commentary in App.js.
This works for me in bluestacks emulator and in my phone running apk file I hope help you
Upvotes: 2