为什么在 expo build:android 之后图像没有显示在 apk 上?(反应原生) [英] Why are images not showing on apk after expo build:android? (React Native)

查看:26
本文介绍了为什么在 expo build:android 之后图像没有显示在 apk 上?(反应原生)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个应用程序(使用 React Native Expo),其中包含一些图像,例如:

I created an app (using React Native Expo) that has some images like:

<图片来源={require('../assets/facebook_button.png')}/>

图像位于资产目录中,我可以使用 npm publishnpm start 功能查看它们.

The images are in the assets directory and I can see them using the npm publish or the npm start functionalities.

问题是在使用 exp build:android 构建应用程序时,现在 apk 显示静态图像(但我正在从正在显示 Internet).

The problem is when building the app with exp build:android, now the apk is not showing the static images (but some other images I'm loading from the Internet are being showed).

这是我的 app.json:

This is my app.json:

{
  "expo": {
    "name": "my-interesting-app",
    "description": "My Interesting App",
    "slug": "my-interesting-app",
    "privacy": "public",
    "sdkVersion": "29.0.0",
    "platforms": ["ios", "android"],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*",
      "assets/*"
    ],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.myinteresting.myinterestingapp"
    },
    "android": {
      "package": "com.myinteresting.myinterestingapp"
    },
    
  }
}

感谢您的帮助

推荐答案

加载前尝试缓存图片.

import React from 'react';
import { Image, Text, View } from 'react-native';
import { Asset, AppLoading } from 'expo';

export default class App extends React.Component {
  state = {
    isReady: false,
  };

  render() {
    if (!this.state.isReady) {
      return (
        <AppLoading
          startAsync={() => this._cacheResourcesAsync()}
          onFinish={() => this.setState({ isReady: true })}
          onError={console.warn}
        />
      );
    }

    return (
      <View style={{ flex: 1 }}>
        <Image source={require('./assets/images/expo-icon.png')} />
        <Image source={require('./assets/images/slack-icon.png')} />
      </View>
    );
  }

  async _cacheResourcesAsync() {
    return Asset.loadAsync([
      require('./assets/images/expo-icon.png'),
      require('./assets/images/slack-icon.png'),
    ]);
  }
}

参考资料:

这篇关于为什么在 expo build:android 之后图像没有显示在 apk 上?(反应原生)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆