Skip to content

Commit c2711bf

Browse files
feat(posts): add 'How to fix Android React Native error "Duplicate class"'
Post: 2025-04-02-how-to-fix-android-react-native-error-duplicate-class.md
1 parent 4bd0ef9 commit c2711bf

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
layout: post
3+
title: How to fix Android React Native error "Duplicate class"
4+
date: 2025-04-02 16:47:21
5+
excerpt: How to fix Android React Native error "Duplicate class".
6+
categories: expo react native android error
7+
---
8+
9+
## Problem
10+
11+
If you're getting the error when running [React Native](https://reactnative.dev/) or [Expo](https://expo.dev/) for [Android](https://www.android.com/):
12+
13+
```
14+
FAILURE: Build failed with an exception.
15+
16+
* What went wrong:
17+
Execution failed for task ':app:checkDebugDuplicateClasses'.
18+
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
19+
> Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.13.1.aar -> core-1.13.1-runtime (androidx.core:core:1.13.1) and support-compat-26.1.0.aar -> support-compat-26.1.0-runtime (com.android.support:support-compat:26.1.0)
20+
21+
Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.
22+
23+
* Try:
24+
> Run with --stacktrace option to get the stack trace.
25+
> Run with --info or --debug option to get more log output.
26+
> Run with --scan to get full insights.
27+
> Get more help at https://help.gradle.org.
28+
29+
BUILD FAILED in 13s
30+
Error: ./android/gradlew app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=arm64-v8a exited with non-zero code: 1
31+
```
32+
33+
The build fails because there are duplicated classes in 2+ dependencies and the compiler doesn't know which one to use during runtime.
34+
35+
This happens when you're importing modules that carry their own required libraries, which leads to transitive dependencies.
36+
37+
## Solution
38+
39+
The solution is to exclude duplicated classes from libraries in `android/app/build.gradle`:
40+
41+
```gradle
42+
apply plugin: "com.android.application"
43+
// ...
44+
45+
android {
46+
// ...
47+
configurations {
48+
all {
49+
exclude group: "com.android.support"
50+
exclude module: "appcompat-v7"
51+
exclude module: "support-v4"
52+
}
53+
}
54+
}
55+
```
56+
57+
See Stackoverflow answers [1](https://stackoverflow.com/a/56029604) and [2](https://stackoverflow.com/a/56334710).

0 commit comments

Comments
 (0)