Android重复文件错误

Android重复文件错误

本文介绍了生成apk时React Native Android重复文件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 ./gradlew installRelease 生成 android apk 时,我在控制台中收到此错误:

When I am trying to generate android apk by using ./gradlew installRelease, I get this error in console:

~/React-Native/mockingbird/android/app/build/intermediates/res/merged/release/drawable-mdpi-v4/src_resources_img_loading.gif: error: Duplicate file.
~/React-Native/mockingbird/android/app/build/intermediates/res/merged/release/drawable-mdpi/src_resources_img_loading.gif: Original is here. The version qualifier may be implied.

我通过 Android Studio 尝试了 Build->Clean Project 并再次运行 ./gradlew installRelease;它也不起作用.

I tried Build->Clean Project via Android Studio and ran ./gradlew installRelease again; it didn't work either.

此外,我尝试删除 build 文件夹,但也无济于事.

Also, I tried deleting the build folder, but it doesn't help either.

推荐答案

给你一些提示,希望有用.

Give some tips for you, hope it's work.

更新为 "react": "16.7.0", "react-native": "0.57.8"

Update with "react": "16.7.0", "react-native": "0.57.8"

自定义node_modules/react-native/react.gradle,完美解决重复文件错误.将以下代码添加到currentBundleTask的创建块中(在doFirst块之后)

Custom node_modules/react-native/react.gradle to solve the Duplicate file error perfectly. Add following code into currentBundleTask's creation block (after doFirst block)

doLast {
    def moveFunc = { resSuffix ->
        File originalDir = file("${resourcesDir}/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()
}

您可以创建脚本来自动执行此操作.


You can create script to do it automatically.

  1. 创建android-react-gradle-fix 文件
  2. 创建脚本 android-release-gradle-fix.js 文件
  3. 更新 package.json 文件:

脚本":{"postinstall": "节点 ./android-release-gradle-fix.js"},

就是这样!运行 npm install 以获得很棒的效果.

That's it! Run npm install to get awesome.

注意:如果你像 jenkins 一样在 ci 上运行 npm install,你可能会得到错误:postinstall: cannot run in wd %s %s (wd=%s) node => 只需使用 npm install --unsafe-perm 代替

Note: If you run npm install on ci like jenkins, you may get error: postinstall: cannot run in wd %s %s (wd=%s) node => just use npm install --unsafe-perm instead

这篇关于生成apk时React Native Android重复文件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 02:56