简体   繁体   English

使用 Expo React Native 构建后,Android APK 无法正常工作

[英]Android APK not working properly after build using Expo React Native

I've been working on an app, and I have been using both the Android emulator and my Android device for testing using Expo.我一直在开发一个应用程序,我一直在使用 Android 模拟器和我的 Android 设备来使用 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.但是,我刚刚构建了一个Android APK(我执行了expo build:android ),并且可以看到我的应用程序的登录信息,但是在引入凭据后,它有点显示关闭应用程序然后恢复它,但现在它一直显示只是一个空白的屏幕。

Here is a gif showing you exactly what happens.这是一个 gif,向您展示会发生什么。

https://giphy.com/gifs/hdtXNeM2s5Dx7FnbNJ 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.另外,这里是我的 App.js 的代码,它可以显示<AuthNavigator /> (登录屏幕),但是当设置用户时它停止工作,然后<AppNavigator />没有出现。

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:还有我的 app.json,以防万一:

{
  "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": ""
  }
}

In app.json you need change:在 app.json 你需要改变:

"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.换句话说,您只需要更改应用程序名称的公司名称,请确保仅使用小写字符而不使用 simbol。 The folder that your create have the same name of your app.您创建的文件夹与您的应用程序同名。 And for other people delete any commentary in App.js.对于其他人,删除 App.js 中的任何评论。

This works for me in bluestacks emulator and in my phone running apk file I hope help you这适用于我在 bluestacks 模拟器和我的手机中运行 apk 文件我希望能帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 react native expo 项目中构建 android apk - Not able to build android apk in react native expo project 隐藏 android 底部按钮使用 expo 构建本机反应 - Hide android bottom buttons react native using expo build 使用具有 EXPO 的 React Native 创建 APK 构建时出错 - Error creating APK Build with React Native having EXPO Expo React Native google auth with firebase 在 android 上的已发布 apk 版本中不起作用 - Expo React Native google auth with firebase not working in published apk version on android 生成 apk 或 aab 后,React Native Webview 无法在 android 上运行 - React Native Webview is not working on android after generating apk or aab 为什么使用 React Native 和 expo 创建的 APK 体积这么大? - Why is APK created using React Native and expo so large in size? react-native apk 无法在 android 设备上运行 - react-native apk not working on the android device Expo - React Native / Firebase 应用程序,APK 与 Expo go 应用程序不同 - Expo - React Native / Firebase app, APK working different than on Expo go app React Native - 如何构建 expo 反应原生应用程序,使其不需要 Expo android 应用程序打开 - React Native - How to build expo react native app so that it does not require Expo android app to open 如何使用 React Native Expo 安装 downloaded.apk? - How to install a downloaded .apk with React Native Expo?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM