React Native Android打包报错系列

1.Exception in thread "main" java.util.zip.ZipException: error in opening zip file

解决方法:
这是解压gradle-x.x-all.zip文件报错,原因是在你创建工程gradle-x.x-all包下载不完全或者没有下载。
我用的版本是:gradle-4.6-all
1.先去下载你的版本的gradle压缩包:http://services.gradle.org/distributions/
2.放在/Users/xxx/.gradle/wrapper/dists/gradle-4.6-all/bcst21l2brirad8k2ben1letg下,重新运行就行了

2.Execution failed for task ':app:mergeReleaseResources'. ...xxx_xxx_xxx.png: Error: Duplicate resources

Mapsy's answer should help https://stackoverflow.com/a/52750886
So basically you edit the /node_modules/react-native/react.gradle file
and add the doLast right after the doFirst block, manually.

doFirst { ... }
doLast {
    def moveFunc = { resSuffix ->
        File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
        if (originalDir.exists()) {
            File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
            ant.move(file: originalDir, tofile: destDir);
        }
    }
    moveFunc.curry("ldpi").call()
    moveFunc.curry("mdpi").call()
    moveFunc.curry("hdpi").call()
    moveFunc.curry("xhdpi").call()
    moveFunc.curry("xxhdpi").call()
    moveFunc.curry("xxxhdpi").call()
}

方案二:参考https://blog.csdn.net/github_34437042/article/details/81150462
在使用gradle 4.7版本进行打包的时候,node_modules_reactnavigation_src_views_assets_backicon.png会出现图片重复的问题
首先修改getAndroidAssetSuffix文件:node_modules\react-native\local-cli\bundle\assetPathUtils.js
在这里面需要修改部分代码:
文件中的原代码

function getAndroidAssetSuffix(scale) {
   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';
   }
 }
修改后代码
 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';
   }
 }

之后再将android.../res文件夹下的drawable所有文件都删除。

你可能感兴趣的:(React Native Android打包报错系列)