简体   繁体   English

类型 androidx.appcompat.resources.R$dimen 被定义多次

[英]Type androidx.appcompat.resources.R$dimen is defined multiple times

We have a React Native app where after upgrading to Android Studio 3.6.1 and Gradle plugin 3.6.1 we are seeing this compilation error:我们有一个 React Native 应用程序,在升级到 Android Studio 3.6.1 和 Gradle 插件 3.6.1 后,我们看到了这个编译错误:

Type androidx.appcompat.resources.R$dimen is defined multiple times: /Users/andrew/Software/project/android/app/build/intermediates/project_dex_archive/productionRelease/out/androidx/appcompat/resources/R$dimen.dex, /Users/andrew/Software/project/android/app/build/intermediates/project_dex_archive/productionRelease/out/15bdf8225afad69777cd7f9bd328ab094900c8289014e0107b56c5c62099dfea_3.jar:classes.dex

Here are our dependencies:这是我们的依赖项:

"dependencies": {
    "@dblackker/cameraroll": "^1.3.4",
    "@react-native-community/async-storage": "^1.7.1",
    "@react-native-community/geolocation": "^2.0.2",
    "@react-native-community/netinfo": "^4.4.0",
    "@react-native-community/push-notification-ios": "^1.0.6",
    "@react-native-firebase/analytics": "^6.2.0",
    "@react-native-firebase/app": "^6.2.0",
    "@react-native-firebase/crashlytics": "^6.2.0",
    "@react-native-firebase/perf": "^6.2.0",
    "appcenter": "^2.6.1",
    "appcenter-analytics": "^2.6.1",
    "appcenter-crashes": "^2.6.1",
    "axios": "^0.18.0",
    "clone": "^2.1.2",
    "immutability-helper": "^2.8.1",
    "lodash": "^4.17.14",
    "memoize-one": "^5.1.1",
    "moment": "^2.22.2",
    "prop-types": "^15.7.2",
    "react": "16.9.0",
    "react-custom-validation": "^0.5.7",
    "react-native": "0.61.5",
    "react-native-add-calendar-event": "^3.0.0",
    "react-native-app-intro-slider": "^3.0.0",
    "react-native-appearance": "^0.3.1",
    "react-native-camera": "^3.8.0",
    "react-native-contacts": "^5.0.6",
    "react-native-device-info": "^4.0.1",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-heic-converter": "^1.3.0",
    "react-native-image-crop-picker": "^0.26.1",
    "react-native-image-resizer": "^1.0.1",
    "react-native-inappbrowser-reborn": "^3.1.0",
    "react-native-iphone-x-helper": "^1.2.1",
    "react-native-keyboard-aware-scroll-view": "^0.7.4",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-maps": "0.26.1",
    "react-native-modal": "^7.0.2",
    "react-native-modal-datetime-picker": "^7.6.1",
    "react-native-parsed-text": "^0.0.21",
    "react-native-permissions": "^2.0.9",
    "react-native-push-notification": "^3.1.9",
    "react-native-reanimated": "^1.3.0",
    "react-native-section-list-get-item-layout": "^2.2.3",
    "react-native-shadow": "^1.2.2",
    "react-native-share": "^2.0.0",
    "react-native-svg": "^9.12.0",
    "react-native-svg-uri": "^1.2.3",
    "react-native-tab-view": "^2.3.0",
    "react-native-version-number": "^0.3.6",
    "react-navigation": "3.12.0",
    "react-navigation-tabs": "^2.1.2",
    "react-redux": "^5.0.7",
    "redux": "^4.0.4",
    "redux-thunk": "^2.3.0",
    "rn-fetch-blob": "^0.11.2",
    "validator": "^10.8.0"
  }

Can anyone help figure out what the issue is, and how could we debug this type of issue in the future?任何人都可以帮助找出问题所在,以及我们将来如何调试此类问题? Thank you!谢谢!

遇到同样的问题,只需清理项目并再次重建。

I had same issue after updating gradle version to 3.6.3 from 3.5.2 in Android Studio.在 Android Studio 中将 gradle 版本从 3.5.2 更新到 3.6.3 后,我遇到了同样的问题。

I have multiple Build Variants.我有多个构建变体。

I fixed the issue by first deleting .gradle folder from the project and did Clean Project and Rebuild Project.我通过首先从项目中删除 .gradle 文件夹并执行 Clean Project 和 Rebuild Project 来解决该问题。

If you have multiple build variant you may have to do same thing for each one when you change build variants from one to another.如果您有多个构建变体,当您将构建变体从一个更改为另一个时,您可能必须对每个构建变体执行相同的操作。

Igor Montella 对我的问题的评论解决了这个问题——降级到 gradle 插件 3.5.0。

我删除了android/app/build文件夹,因为我的重复项就在那里。

My errors were similar, with a "is defined multiple times" message.我的错误是类似的,带有“多次定义”的消息。

I solved it by downgrading the Gradle plugin to 3.5.0, running the app — or at least trying to — then upgrading to Gradle plugin 3.6.2 again.我通过将 Gradle 插件降级到 3.5.0,运行应用程序——或者至少尝试——然后再次升级到 Gradle 插件 3.6.2 来解决它。

I am not sure why, but this seemed to have cleared some caches or dependencies I was not aware of.我不确定为什么,但这似乎清除了一些我不知道的缓存或依赖项。

Removing ~/.gradle or android/.gradle did not help.删除~/.gradleandroid/.gradle没有帮助。

I just run following built in routine in Android Studio:我只是在Android Studio 中运行以下内置例程

  • File > Sync Project with Gradle Files文件 > 将项目与 Gradle 文件同步

And then it worked again :-)然后它又起作用了:-)

While I was coding on the android studio on native android.Got the same problem当我在原生 android 上的 android studio 上编码时,遇到了同样的问题

Type androidx.appcompat.resources.R$dimen is defined multiple times:类型 androidx.appcompat.resources.R$dimen 被定义多次:

The problem is because of the Duplication of the BuildConfig which is present inside the JAVA (Generated) Directory问题是因为存在于JAVA(生成)目录中的 BuildConfig 重复

Here is the solution to fix the problem.这是解决问题的解决方案。

You have to delete the duplicate BuildConfig from the android studio by this process您必须通过此过程从 android studio 中删除重复的 BuildConfig

  1. Click on java(generated) on the Left side单击左侧的java(generated)

在此处输入图片说明

  1. The problem is extra Build Config Created问题是额外的构建配置创建

在此处输入图片说明

  1. When you click any of the BuildConfig, it will show the same error display in the picture当你点击任何一个 BuildConfig 时,它会在图片中显示相同的错误显示

在此处输入图片说明

  1. Delete the extra BuildConfig and keep the original BuildConfig.删除多余的 BuildConfig,保留原来的 BuildConfig。

Problem Solved问题解决了

在此处输入图片说明

文件->无效缓存/重启

I deleted ~/.gradle/caches我删除了~/.gradle/caches

seems to work good.似乎效果很好。 I did this because I saw ~/.gradle/caches in my error.我这样做是因为我在错误中看到了~/.gradle/caches

Type androidx.legacy.app.ActionBarDrawerToggle$Delegate is defined multiple times:
/Users/me/.gradle/caches/transforms-3/08344aeb2253f0dce062ee9436d14235/transformed/legacy-support-core-ui-1.0.0-runtime/classes.dex,
/Users/me/.gradle/caches/transforms-3/bde9e50d97f78024fdfcb4b5869842c8/transformed/legacy-support-core-ui-1.0.0-runtime/classes.dex

These answers are all outdated.这些答案都已经过时了。 I used 4.1.2.我用的是 4.1.2。 If you look at the path given in AS, it should point to \\app\\build\\intermediates\\project_dex_archive\\debug\\out.如果查看 AS 中给出的路径,它应该指向 \\app\\build\\intermediates\\project_dex_archive\\debug\\out。 Go to this path, delete all the *.jar files, leaving the most recent one.到这个路径,删除所有的*.jar文件,留下最近的一个。 I tried this and my project worked perfectly.我试过了,我的项目运行良好。

Don't bother with invalidates caches / restart as it won't work.不要打扰无效缓存/重新启动,因为它不起作用。

在我的情况下我也有同样的问题你有升级依赖它也适用于我

For Googlers:对于 Google 员工:
In my case, I've created a benchmark module (with plugin "com.android.library" ) and made it depend on the app module (with plugin "com.android.application" ).就我而言,我创建了一个基准模块(带有plugin "com.android.library" )并使其依赖于应用程序模块(带有plugin "com.android.application" )。
But library module can not depend on the application module, as Gradle does not support it.但是库模块不能依赖于应用程序模块,因为 Gradle 不支持它。
Here some info: https://www.reddit.com/r/androiddev/comments/boi4xg/modularization_help_android_library_module/这里有一些信息: https : //www.reddit.com/r/androiddev/comments/boi4xg/modularization_help_android_library_module/

@Wito Divaro, his answer helped me. @Wito Divaro,他的回答帮助了我。 If you are bothered by "R is defined multiple times.", just try to get rid of 'android/app/buid'.如果您对“R 被多次定义”感到困扰,请尝试摆脱“android/app/buid”。 Furthermore, I added this below line to app/build.gradle.此外,我将下面这行添加到 app/build.gradle。 If you want to try, try this.如果你想尝试,试试这个。

defaultConfig {
   ..............
   multiDexEnabled true
}

dependencies {
    ..............
    implementation 'androidx.multidex:multidex:2.0.1'
}

public class MyApplication extends MultiDexApplication {
    ..............
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM