You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo 49迁移至51后Android本地图片无法显示的问题求助

问题:Expo 51迁移后Android本地图片无法显示

背景

基于Expo 49构建的React Native应用,原可通过expo-image组件正常显示本地图片和expo-vector-icons图标。迁移至Expo 51后,Android和iOS端的本地图片、图标均无法显示。

已解决的图标问题

切换为lucide-react-native库后,图标显示问题已修复。

未解决的本地图片问题

  • 在app.json中配置expo-asset插件,指定构建时加载的图片:
{
  "expo": {
    "plugins": [
      [
        "expo-asset",
        {
          "assets": ["./assets/images/google.png"]
        }
      ]
    ]
  }
}
  • 执行npx expo run:ios后,iOS端图片显示恢复正常,但Android端本地图片仍无法加载。

项目依赖

"dependencies": {
    "@babel/runtime": "^7.25.4",
    "@expo/config-plugins": "~8.0.0",
    "@expo/prebuild-config": "~7.0.0",
    "@expo/vector-icons": "^14.0.2",
    "@gorhom/bottom-sheet": "^4.5.1",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-native-community/netinfo": "11.3.1",
    "@react-native/assets-registry": "^0.74.83",
    "@react-navigation/material-top-tabs": "^6.6.13",
    "@shopify/flash-list": "1.6.4",
    "@tanstack/react-query": "^5.40.0",
    "algoliasearch": "^4.24.0",
    "axios": "^1.7.2",
    "babel-plugin-module-resolver": "^5.0.2",
    "cloudinary-react-native": "^1.0.0",
    "dayjs": "^1.11.12",
    "deprecated-react-native-prop-types": "^5.0.0",
    "expo": "^51.0.31",
    "expo-asset": "~10.0.10",
    "expo-auth-session": "~5.5.2",
    "expo-av": "~14.0.6",
    "expo-constants": "~16.0.2",
    "expo-crypto": "~13.0.2",
    "expo-dev-client": "~4.0.26",
    "expo-device": "~6.0.2",
    "expo-font": "~12.0.10",
    "expo-image": "~1.12.15",
    "expo-image-picker": "~15.0.7",
    "expo-linear-gradient": "~13.0.2",
    "expo-linking": "~6.3.1",
    "expo-localization": "~15.0.3",
    "expo-notifications": "~0.28.15",
    "expo-router": "~3.5.23",
    "expo-secure-store": "~13.0.2",
    "expo-splash-screen": "~0.27.5",
    "expo-status-bar": "~1.12.1",
    "expo-tracking-transparency": "~4.0.2",
    "expo-web-browser": "~13.0.3",
    "graphql": "^16.9.0",
    "i18next": "^23.11.5",
    "lottie-react-native": "6.7.0",
    "lucide-react-native": "^0.435.0",
    "mime": "^4.0.3",
    "punycode": "^2.3.1",
    "react": "18.2.0",
    "react-content-loader": "^6.2.1",
    "react-hook-form": "^7.48.2",
    "react-i18next": "^14.1.2",
    "react-instantsearch-core": "^7.12.4",
    "react-native": "0.74.5",
    "react-native-bouncy-checkbox": "^3.0.7",
    "react-native-calendars": "^1.1302.0",
    "react-native-gesture-handler": "~2.16.1",
    "react-native-google-places-autocomplete": "^2.5.6",
    "react-native-maps": "1.14.0",
    "react-native-markdown-display": "^7.0.2",
    "react-native-pager-view": "6.3.0",
    "react-native-reanimated": "~3.10.1",
    "react-native-safe-area-context": "4.10.5",
    "react-native-screens": "3.31.1",
    "react-native-svg": "15.2.0",
    "react-native-tab-view": "^3.5.2",
    "react-native-toast-message": "^2.2.0",
    "react-native-web": "~0.19.10",
    "vexo-analytics": "^1.3.16",
    "zustand": "^4.5.2"
  }

运行时加载图片的尝试及错误

尝试使用expo-asset的useAssets钩子在运行时加载图片:

import { Asset, useAssets } from 'expo-asset'

const GetStarted = () => {
    const [img, error] = useAssets([
        require('../assets/hero_section_img.png'),
        require('../assets/google.png'),
      ])
    // 业务代码
}

执行后,iOS和Android端均抛出错误:

TypeError: Cannot read property 'uri' of null 

Expo Doctor版本警告

运行npx expo-doctor@latest时,检测到版本不匹配问题:

Expected package @expo/config-plugins@~8.0.0
Found invalid:
  @expo/config-plugins@7.6.0

该问题由cloudinary-react-native包引发,但移除该包、删除package-lock.json并重新构建,甚至删除node_modules后,版本不匹配问题仍未解决。

内容的提问来源于stack exchange,提问作者invictus falok

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 12:47:09