为什么在expo build:android之后,apk上没有显示图像? (反应本机)

时间:2018-08-04 14:14:15

标签: reactjs react-native native expo

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

<Image source={require('../assets/facebook_button.png')} />

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

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

这是我的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"
    },
    
  }
}

感谢您的帮助

2 个答案:

答案 0 :(得分:2)

尝试在加载之前缓存图像。

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'),
    ]);
  }
}

参考文献:

答案 1 :(得分:-1)

是否存在可以发布快照的错误或捕获?当您不知道是什么原因导致修复时,真的很难。