Sho*_*gsu 57 android apk react-native
当我试图通过使用生成android apk时./gradlew installRelease,我在控制台中收到此错误:
~/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.
Run Code Online (Sandbox Code Playgroud)
我尝试Build->Clean Project通过Android Studio ./gradlew installRelease再次运行; 它也没用.
此外,我尝试删除该build文件夹,但它也没有帮助.
Nha*_*Cao 132
给你一些提示,希望它的工作.
用"react"更新:"16.7.0","react-native":"0.57.8"
自定义node_modules/react-native/react.gradle以完美地解决重复文件错误.将以下代码添加到currentBundleTask的创建块中(在doFirst块之后)
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()
}
Run Code Online (Sandbox Code Playgroud)
您可以创建脚本以自动执行此操作.
android-react-gradle-fix文件android-release-gradle-fix.js文件更新package.json文件:
"scripts":{ "postinstall":"node ./android-release-gradle-fix.js" },
而已!运行npm install得到真棒.
注意:如果你运行npm install像詹金斯词,你可能会得到错误:postinstall: cannot run in wd %s %s (wd=%s) node=>只是使用npm install --unsafe-perm替代
小智 37
删除您可能拥有的文件:
android/app/src/main/res/drawable-mdpi/
android/app/src/main/res/drawable-xhdpi/
android/app/src/main/res/drawable-xxhdpi/
Run Code Online (Sandbox Code Playgroud)
再次运行Build,这为我解决了这个问题.
Map*_*psy 26
在撰写本文时,更新版本的React Native(> 0.57.0)已将Gradle包装器级别增加到4.4并将Gradle插件增加到3.1.4,如更改日志所示.这样可以使Gradle构建过程将AAPT的结果(现在需要)存储在与以前不同的目录中.
就Nhan Cao的强大解决方法而言,我们需要稍作修改以防止重复的资源冲突,因为它看起来是指向旧目录而不是应用程序的generated目录.通过在生成资源后更改将这些重复文件合并在一起的目标目录,我们仍然可以对资源进行重复数据删除.
现有的react.gradle是指以下路径:
$buildDir === <project-working-directory>/android/app/build
Run Code Online (Sandbox Code Playgroud)
重复的文件路径可以出现在:
file("$buildDir/../src/main/res/drawable-${resSuffix}")
file("$buildDir/generated/res/react/release/drawable-${resSuffix}")
Run Code Online (Sandbox Code Playgroud)
作为一种变通方法,我们可以作如下更新仁的解决方案(一定要包括该范围内的currentBundleTask申报后doFirst在react.gradle:
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()
}
Run Code Online (Sandbox Code Playgroud)
Jos*_*ter 18
react-native bundle先跑./gradlew assembleRelease.对我自己来说,我在跑步react-native bundle前跑步./gradlew assembleRelease.
我收到了一个类似的重复错误消息,其中包含我的一个资产.
看一下./gradlew assembleRelease输出,我可以告诉它自己构建JS包(感谢apply from: "../node_modules/react-native/react.gradle"你的build.gradle文件)所以没有必要手动运行react-native bundle.
如果我在运行react-native bundle之前根本没有运行./gradlew assembleRelease一切都很好.
我测试了Release APK和JS捆绑加载,包括所有图像.
我唯一关心的是是否--sourcemap-output会创建源映射(用于Bugsnag).如果没有,我相信也有办法./gradlew assembleRelease生成这些.我还没有测试过它.
小智 6
为了使我的构建适用于React Native 0.57.5,我使用了Mapsy的答案并做了一些小的改进。我需要能够针对多种口味进行构建,并且通常我会尝试避免对事物进行硬编码。浏览react.gradle文件时,我发现它定义了以下变量:
def resourcesDir = file("$buildDir/generated/res/react/${targetPath}")
Run Code Online (Sandbox Code Playgroud)
因此,与其像这样在路径中对构建类型/风味进行硬编码,不如:
File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
Run Code Online (Sandbox Code Playgroud)
我改用resourcesDir变量来设置originalDir路径,如下所示:
File originalDir = file("${resourcesDir}/drawable-${resSuffix}");
Run Code Online (Sandbox Code Playgroud)
结果,我doLast看起来像这样:
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()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34046 次 |
| 最近记录: |