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

React Native集成Expo后打包Release APK遇AssertionError求助

解决React Native集成Expo包后Release构建APK报错问题

错误信息

AssertionError [ERR_ASSERTION]: Assets must have hashed files. Ensure the expo-asset plugin is installed.

Task :app:createBundleReleaseJsAndAssets FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:createBundleReleaseJsAndAssets'.

Process 'command 'node'' finished with non-zero exit value 1

  • Try:

Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.3/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 2m 17s

解决方案

  • 安装并配置expo-asset插件
    1. 安装依赖:
      npx expo install expo-asset
      
    2. 修改babel.config.js,添加插件:
      module.exports = {
        presets: ['module:metro-react-native-babel-preset'],
        plugins: ['expo-asset/babel'],
      };
      
  • 配置Metro以处理Expo资产
    在metro.config.js中更新配置,确保资产解析正确:
    const { getDefaultConfig } = require('expo/metro-config');
    const config = getDefaultConfig(__dirname);
    
    // 根据你的项目资产类型添加对应的扩展名
    config.resolver.assetExts.push('db', 'mp3', 'ttf', 'png');
    module.exports = config;
    
  • 清理构建缓存
    执行命令清除旧缓存:
    npx react-native clean
    cd android && ./gradlew clean
    
  • 重新构建Release包
    清理完成后重新执行构建:
    cd android && ./gradlew assembleRelease
    

内容的提问来源于stack exchange,提问作者Engr.Aftab Ufaq

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 20:00:10