react-native在打包apk时,可能会遇到图片资源编译报错的情况,如下:
android\app\build\intermediates\res\merged\release\drawable-hdpi-v4\node_modules_reactnavigationstack_dist_views_assets_backicon.png:
 error: uncompiled PNG file passed as argument. Must be compiled first into .flat file..
 
接下来说一声个人的几种解决方案,仅供参考:
1.直接尝试替换此图片资源,有时候出现这个问题往往是图片资源的格式在AS上编译校验不通过的原因;


2.在gradle.properties文件中添加 android.enableAapt2=false


3.在build.gradle文件中添加
    android {

        //添加这两行
        aaptOptions.cruncherEnabled = false
        aaptOptions.useNewCruncher = false
    }


4.更改assetPathUtil.js文件代码:(文件路径是 node_modules\react-native\local-cli\bundle\assetPathUtils.js)
之前:

function getAndroidAssetSuffix(scale: number): string {
   switch (scale) {
     case 0.75: return 'ldpi';
     case 1: return 'mdpi';
     case 1.5: return 'hdpi';
     case 2: return 'xhdpi';
     case 3: return 'xxhdpi';
     case 4: return 'xxxhdpi';
   }
   throw new Error('no such scale');
}
改后:


function getAndroidAssetSuffix(scale) {
   switch (scale) {
      case 0.75: return 'ldpi-v4';
      case 1: return 'mdpi-v4';
      case 1.5: return 'hdpi-v4';
      case 2: return 'xhdpi-v4';
      case 3: return 'xxhdpi-v4';
      case 4: return 'xxxhdpi-v4';
   }
}
然后重新打bundle包,重新编译打release包。
希望以上对你有所帮助~

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐