[Solved] Execution failed for task ‘:app:compileDebugJavaWithJavac’:

When I try $ react-native run-android on android emulator, I get this error:

/home/user/app/android/app/src/main/java/com/package/ error: a type with the same simple name is already defined by the single-type-import of RNAWSCognitoPackage
import com.airlabsinc.RNAWSCognitoPackage;
1 error
Incremental compilation of 1 classes completed in 0.448 secs.
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.


Total time: 10.964 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:

Then I have 2 imports with the same name in my /home/user/app/android/app/src/main/java/com/package/
May this cause the issue?
Is this the issue with RN?

package com.package;


import com.facebook.react.ReactApplication;
import com.amazonaws.RNAWSCognitoPackage; // 1
import com.amazonaws.amplify.pushnotification.RNPushNotificationPackage;
import com.airlabsinc.RNAWSCognitoPackage; // 2
import com.horcrux.svg.SvgPackage;
import com.toast.ToastPackage;
import com.vdi.VDIPackage;
import com.BV.LinearGradient.LinearGradientPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;

import java.util.Arrays;
import java.util.List;

My env:

  * OS: Linux 4.13
  * Node: 8.9.4
  * Yarn: Not Found
  * npm: 5.6.0
  * Watchman: Not Found
  * Xcode: N/A
  * Android Studio: Not Found

**Packages**: (wanted => installed)
  * react: 16.3.0-alpha.2 => 16.3.0-alpha.2
  * react-native: 0.54.2 => 0.54.2
Enquirer: Green


Solution #1:

You cannot import the same class from different packages in JAVA, I suggest you remove the first import :

- import com.amazonaws.RNAWSCognitoPackage; // 1 (remove this line)
Respondent: Drea Zener

Solution #2:

  1. Delete the build file in the android folder
  2. Delete the build file in android>app
  3. run react-native run-android
Respondent: Zaid Raddad

Solution #3:

There are couple of possibilities, try which one is suitable,

  1. You might have missed some initial setup for the package RNAWSCognitoPackage and its related services whatever you used. So check out the installation setup once.

  2. If everything is fine, then another case, android stores cache to build faster. Everytime you install a new packages, you should clean the code and run it again.

    remove node_modules and Package-lock.json and run the following commands

    cd android
    ./gradlew clean
    ./gradlew cleanBuildCache
    npm install

Some rare cases, you need to try this,

npx react-native-clean-project clean-project-auto

Respondent: Dhevendhiran M

Solution #4:

Not sure if this is the right solution. Can you try it out once!

  1. Open your project in Android Studio. Go to File menu and click on Invalidate caches/Restart.
  2. Rebuild your project.
  3. Execute npm run android or react-native run-android
Respondent: Prameela K

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy