【问题标题】:React Native Error: Duplicate resources, assets coming in some screens and not coming in others in android release APKReact Native 错误:在 android 版本 APK 中重复资源、资产进入某些屏幕而其他屏幕没有出现
【发布时间】:2018-10-05 15:05:15
【问题描述】:

我正在使用 Gradle 版本 3.2.0compileSdkVersion 28 在 Android 中构建我的 React Native 应用的发布 APK。我正在运行以下命令:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
cd android && ./gradlew clean && ./gradlew assembleRelease && ./gradlew installRelease

我的文件夹结构是:

我的package.json 是:

{
  "name": "App",
  "version": "2.0.0",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "native-base": "^2.8.0",
    "prop-types": "^15.6.2",
    "qs": "^6.5.2",
    "react": "^16.5.2",
    "react-native": "0.57.0",
    "react-native-animatable": "^1.3.0",
    "react-native-animated-icons": "^1.0.5",
    "react-native-appsee": "^2.4.14",
    "react-native-blur": "^3.2.2",
    "react-native-cast-chrome": "1.0.0",
    "react-native-cast-ui": "1.0.0",
    "react-native-device-info": "^0.22.3",
    "react-native-dialog": "^5.1.0",
    "react-native-elements": "^0.19.1",
    "react-native-email": "^1.0.1",
    "react-native-fast-image": "^5.0.3",
    "react-native-fbsdk": "^0.8.0",
    "react-native-flurry-analytics": "^3.0.2",
    "react-native-gridview": "^0.1.2",
    "react-native-iap": "^2.2.1",
    "react-native-iphone-x-helper": "^1.0.3",
    "react-native-keyboard-aware-scroll-view": "^0.7.0",
    "react-native-kochava-tracker": "^1.0.0",
    "react-native-linear-gradient": "^2.4.0",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-modal": "^6.5.0",
    "react-native-orientation": "^3.1.3",
    "react-native-photo-upload": "^1.3.0",
    "react-native-scrollable-tab-view": "^0.8.0",
    "react-native-snap-carousel": "^3.7.4",
    "react-native-tab-view": "^1.2.0",
    "react-native-underline-tabbar": "^1.3.6",
    "react-native-vector-icons": "^5.0.0",
    "react-native-video": "^3.2.1",
    "react-native-video-controls": "^2.2.3",
    "react-navigation": "^2.11.2",
    "react-navigation-backhandler": "^1.1.1",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "@babel/plugin-external-helpers": "^7.0.0",
    "ajv": "^6.5.2",
    "babel-eslint": "^9.0.0",
    "babel-jest": "23.4.2",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "eslint": "^5.3.0",
    "eslint-config-airbnb": "^17.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-jsx-a11y": "^6.1.1",
    "eslint-plugin-react": "^7.11.0",
    "jest": "23.4.2",
    "metro-react-native-babel-preset": "^0.45.4",
    "react-test-renderer": "16.4.1",
    "schedule": "^0.4.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

在运行命令时,我的所有资产在Task :app:mergeReleaseResources FAILEDError: Duplicate resources 上出现错误。从我的可绘制文件夹中删除资产时,应用程序会构建。

但是在运行发布版 APK 时,一些图像根本没有出现,而另一些则出现了。此外,相同的图像出现在某些地方,而没有出现在其他地方。从 JS 服务器运行调试应用程序时,这些问题都不会发生。这个问题在 iOS 中没有发生。

我该如何解决这个问题?

【问题讨论】:

  • 你能添加你正在使用的文件夹结构吗?
  • 您是否尝试过删除两个构建文件夹并检查是否存在重复的命名图像?

标签: android react-native gradle android-gradle-plugin


【解决方案1】:

根据 RN 0.57 变更日志:

Android 工具已更新以匹配较新的配置 要求(SDK 27、gradle 4.4 和支持库 27);建造 由于 gradle 脚本,Android 插件 3.2 不起作用,所以 请暂时使用 Android Studio 3.1

1) 尝试根据 RN change log 进行设置

com.android.tools.build:gradle:3.1.4 应该可以工作

2) 尝试删除 android build 文件夹并仅运行 ./gradlew assembleRelease 而无需任何捆绑

我也在使用 RN 0.57,并且在没有捆绑的情况下生成 apk 对我来说可以。

如果您仍然有问题并想使用捆绑尝试检查:

React Native Android Duplicate file error when generating apk

这些答案应该可以解决问题:

https://stackoverflow.com/a/52750886/1979861

https://stackoverflow.com/a/50876742/1979861

更多关于 0.57 安卓更新的信息在这里:

https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md

【讨论】:

  • 我试过了,但没用。我已经添加了我的项目结构。
  • 将你的 package.json 依赖添加到你的问题中,至少是 RN 版本和 babel 的东西
  • 添加了 package.json
猜你喜欢
  • 1970-01-01
  • 2016-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多