Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix build gradle

Tags:

android

build

I restarted the Android Studio and an error occurred during the build

Build failed show:


C:\Users\aws hakam\Desktop\freeLance\BottleOfWater\app\build\intermediates\external_file_lib_dex_archives\debug\out

The extension it points to does not exist

The details error


    Caused by: java.nio.file.NoSuchFileException: C:\Users\aws hakam\Desktop\freeLance\BottleOfWater\app\build\intermediates\external_file_lib_dex_archives\debug\out
    at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
    at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
    at sun.nio.fs.WindowsDirectoryStream.<init>(WindowsDirectoryStream.java:86)
    at sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream(WindowsFileSystemProvider.java:518)
    at java.nio.file.Files.newDirectoryStream(Files.java:457)
    at java.nio.file.Files.list(Files.java:3451)
    at com.android.build.gradle.internal.tasks.DexMergingParams.getAllDexFiles(DexMergingTask.kt:502)
    at com.android.build.gradle.internal.tasks.DexMergingTaskRunnable.run(DexMergingTask.kt:423)
    ... 28 more


like image 315
awshakam98 Avatar asked Mar 29 '20 18:03

awshakam98


People also ask

Why is my gradle build failing?

If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.

How do I reset build gradle?

Android studio -> Settings -> build tools -> gradle -> Project-level settings -> select Use default gradle wrapper(recommended). And sync gradle and rebuild your project. It's work for me.


5 Answers

I encountered this same error in a React Native project I am working on. I was able to resolve the issue through the following. Be sure to replace <PROJECT_NAME> below with your actual project name.

  1. Within Android Studio, select File > Invalid Cache and Restart.
  2. Open your project directory in your terminal.
  3. rm -rf .gradle
  4. rm -rf android/.gradle android/.idea
  5. rm android/app/app.iml android/<PROJECT_NAME>.iml

After doing this, I was able to open my project in Android Studio and successfully build. I had tried all but step 3 a few times without success, so my belief is that step 3 and the top-level .gradle directory in my project was the primary issue. I'm not sure how it got there.

One additional note, React Native projects place all of the Android-specific code inside an android directory. So, if your project is not a React Native project, and instead a traditional Android project, the paths I outlined for removal may be different (i.e. they wouldn't be underneath android/).

like image 195
David Avatar answered Nov 04 '22 04:11

David


It helps me with Android Studio.

Delete .gradle dir in your project: rm -rf .gradle

like image 45
vkozhemi Avatar answered Nov 04 '22 03:11

vkozhemi


It took me 3 days, I finally found a simple solution:

In the android/app/build.gradle file. Add line multiDexEnabled true

android {
defaultConfig {
    ...
    targetSdkVersion 28
    multiDexEnabled true // here
}
...

}

like image 34
Doan Bui Avatar answered Nov 04 '22 02:11

Doan Bui


For me just doing

rm -rf .gradle

and Restart and invalid worked in Android Studio

like image 26
Thiago Avatar answered Nov 04 '22 03:11

Thiago


This error is usually related to xml files which could be in drawable or layout folder.

In my case there was a drawable I added and it was referring to a color "lightGray" android:drawable="@color/lightGray" which did not exist.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/lightGray" />
    <item android:drawable="@color/black_transparent"/>
</selector>
like image 22
Amir Dora. Avatar answered Nov 04 '22 04:11

Amir Dora.