IOException cannot delete path

I get this error in one of my projects.

FAILURE: Build failed with an exception.

  • What went wrong:

    Execution failed for task ':app:transformClassesWithDesugarForDevServerDebug'. com.android.build.api.transform.TransformException: java.io.IOException: Could not delete path 'D:\Android\Projects\uralenergo\app\build\intermediates\transforms\desugar\devServer\debug\1.jar'.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

    BUILD FAILED in 9s

I very often work on this project, and I'm tired of seeing this error in 40% of the cases when I trying to run my app on my phone.

If I do Rebuild Project, the error disappears and the application is compiled. But after 2-3 times to build the application, this error appears again.

The project is very large, and I can not waste my time on the Rebuild Project. I tried to delete this folder manually. But it did not help me.

build.gradle file:

buildscript {
    ext.kotlin_version = '1.2.3-1'
    repositories {
        jcenter()
        mavenCentral()
        maven { url 'https://maven.fabric.io/public' }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath "io.realm:realm-gradle-plugin:3.7.1"
        classpath 'io.fabric.tools:gradle:1.24.4'
        classpath 'com.google.gms:google-services:3.2.0'
    }
}

allprojects{
    repositories{
        jcenter()
        google()
    }
}

apply plugin: 'idea'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'

repositories {
    jcenter()
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
    maven { url 'https://jitpack.io' }
    maven { url 'https://maven.google.com' }
    google()
}

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    flavorDimensions "versionCode"
    defaultConfig {
        applicationId "com.softjet.uralenergo"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 122
        versionName "1.1.5"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled true
    }


    dexOptions {
        javaMaxHeapSize "4g"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        exclude 'META-INF/rxjava.properties'
    }

    signingConfigs {
        debug {
            storeFile file("keys\\debug_key.jks")
            storePassword "xxx"
            keyAlias "xxx"
            keyPassword "xxx"
        }
        release {
            def keystorePropertiesFile = file("keys\\release.properties")
            if (keystorePropertiesFile.exists()) {
                def keystoreProperties = new Properties()
                keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

                keyAlias keystoreProperties['keyAlias']
                keyPassword keystoreProperties['keyPassword']
                storeFile file(keystoreProperties['storeFile'])
                storePassword keystoreProperties['storePassword']
            } else {
                return null
            }
            keyAlias 'xxx'
            keyPassword 'xxx'
            storeFile file('D:/Android/Projects/uralenergo/keystore/release_key.jks')
            storePassword 'xxx'
        }
    }

    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {
        devServer {
            applicationIdSuffix ".debug"
        }
        prodServer {
            applicationIdSuffix ""
        }
    }

    configurations.all {
        resolutionStrategy {
            force 'com.google.guava:guava:24.1-jre'
            force 'com.google.guava:guava-gwt:24.1-jre'
        }
    }
}

def renameAPK(variant) {
    variant.outputs.each { output ->
        def file = output.packageApplication.outputFile
        def lastSuffix = getVersionNameSuffix(variant)
        def fileName = rootProject.name + " v" + variant.versionName + lastSuffix + ".apk"
        output.packageApplication.outputFile = new File(file.parent, fileName)
    }
}

static def getVersionNameSuffix(variant) {
    def flavorName = variant.flavorName
    def buildType = variant.buildType.name

    if (buildType == "debug") {
        if (flavorName == "prodServer")
            return "a"
        if (flavorName == "devServer")
            return "-debug"
    }
    if (buildType == "release") {
        if (flavorName == "prodServer")
            return "-release"
        if (flavorName == "devServer")
            return "-debug-signed"
    }
    throw new RuntimeException("Unsupported variant: build type=" + buildType + " and flavorName=" + flavorName)
}

task assembleDevServerDebugAndProdServerRelease {
    group = 'custom_assemble'
    dependsOn 'assembleDevServerDebug'
    dependsOn 'assembleProdServerRelease'
}

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '27.1.1'
            }
        }
    }
}

ext {
    supportLibraryVersion = "27.1.1"
    googlePlayServicesVersion = "12.0.1"
    daggerVersion = "2.11"
    okhttpVersion = "3.5.0"
    retrofitVersion = "2.1.0"
    butterKnifeVersion = "8.8.1"
    permissionsDispatcherVersion = "2.4.0"
    glideVersion = "4.1.1"
    materialDialogsVersion = "0.9.4.7"
    flipboardBottomSheetVersion = "1.5.3"
    junitVersion = "4.12"
}

dependencies {

    //Jars
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    //Support Libs
    implementation "com.android.support:support-v4:$supportLibraryVersion"
    implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
    implementation "com.android.support:design:$supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$supportLibraryVersion"
    implementation "com.android.support:gridlayout-v7:$supportLibraryVersion"
    implementation 'com.android.support:multidex:1.0.3'

    //Google
    implementation "com.google.android.gms:play-services-gcm:$googlePlayServicesVersion"
    implementation "com.google.android.gms:play-services-maps:$googlePlayServicesVersion"

    //Firebase
    implementation "com.google.firebase:firebase-core:$googlePlayServicesVersion"
    implementation "com.google.firebase:firebase-messaging:$googlePlayServicesVersion"

    //Dagger2
    implementation "com.google.dagger:dagger:$daggerVersion"
    annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"

    //Rx
    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'io.reactivex:rxjava:1.3.0'

    //Ok Http
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
    implementation "com.squareup.okhttp3:okhttp:$okhttpVersion"
    implementation "com.squareup.okhttp3:okhttp-urlconnection:$okhttpVersion"

    //Retrofit2
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation("com.squareup.retrofit2:converter-simplexml:$retrofitVersion") {
        exclude group: 'xpp3', module: 'xpp3'
        exclude group: 'stax', module: 'stax-api'
        exclude group: 'stax', module: 'stax'
    }

    //    //Pushbots

    //    implementation 'com.pushbots:pushbots-lib:3.0.1@aar'

    //Butter Knife
    implementation "com.jakewharton:butterknife:$butterKnifeVersion"
    annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnifeVersion"

    //Realm
    annotationProcessor 'dk.ilios:realmfieldnameshelper:1.1.1'

    //Permissions Dispatcher
    implementation "com.github.hotchemi:permissionsdispatcher:$permissionsDispatcherVersion"
    annotationProcessor "com.github.hotchemi:permissionsdispatcher-processor:$permissionsDispatcherVersion"

    //Crashlytics
    implementation('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
        transitive = true
    }

    //Picasso
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'

    //Glide
    implementation "com.github.bumptech.glide:glide:$glideVersion"
    annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion"
    implementation "com.github.bumptech.glide:okhttp3-integration:$glideVersion"

    //GestureImageView
    implementation 'com.alexvasilkov:gesture-views:2.4.1'

    //Material Design Additional Libs

    //--Dialogs
    implementation "com.afollestad.material-dialogs:core:$materialDialogsVersion"
    implementation "com.afollestad.material-dialogs:commons:$materialDialogsVersion"

    //--Better Spinner
    implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'

    //--Search View
    implementation 'com.miguelcatalan:materialsearchview:1.4.0'

    //--Help Screen
    implementation 'com.github.apl-devs:appintro:v4.2.2'

    //Shape ImageView
    implementation 'com.github.siyamed:android-shape-imageview:0.9.3@aar'

    //Circular Image View
    implementation 'com.mikhaellopez:circularimageview:3.0.2'

    //Animations
    implementation 'com.daimajia.easing:library:2.0@aar'
    implementation 'com.daimajia.androidanimations:library:2.2@aar'

    //Input Mask
    implementation 'com.redmadrobot:inputmask:2.2.1'

    //Autofit Text View
    implementation 'me.grantland:autofittextview:0.2.1'

    //View Pager Indicator
    implementation 'com.romandanylyk:pageindicatorview:0.1.2@aar'

    //Expandable Layout
    implementation 'com.github.aakira:expandable-layout:1.6.0@aar'

    //Multi Slider
    implementation 'io.apptik.widget:multislider:1.3'

    //Pdf Viewer
    implementation 'com.github.barteksc:android-pdf-viewer:2.5.1'

    //Barcode (QR) scanner
    implementation 'me.dm7.barcodescanner:zxing:1.9.4'

    //Bottom Sheet
    implementation "com.flipboard:bottomsheet-core:$flipboardBottomSheetVersion"
    implementation "com.flipboard:bottomsheet-commons:$flipboardBottomSheetVersion"

    //Metricas
    implementation 'com.yandex.android:mobmetricalib:2.76'

    //Unit Tests
    testImplementation "junit:junit:$junitVersion"
    implementation "junit:junit:$junitVersion"

    //Android Tests
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
        exclude module: 'jsr305'
    })
}

//must be on the bottom
apply plugin: 'com.google.gms.google-services'

Upvotes: 5

Views: 15559

Answers (5)

Hossein Mourdzadeh
Hossein Mourdzadeh

Reputation: 1

if error is Disallow the Fast IO path for this operation in android studio

Do :

disable your antivirus or remove antivirus

Antivirus prevents the process from being completed

Upvotes: -1

Apurv Thakkar
Apurv Thakkar

Reputation: 10158

This happens because of multiple reasons like when you upgrade OS or change the path of project or download studio again and the previous files in the build folder need to be removed. So, in this case, start the Android studio as --> Run as administrator.

Then right-click on build folder from the studio project and click show in explorer. Now delete the build folder. If it requires admin permission click on the checkbox and delete it. Now rebuild the project and run the project.

Upvotes: 4

Thank you all for your answers. I solved the problem by deleting Java 9, and installed Java 8. When I installed Java 10 the problem did not disappear. I think that we need to wait for the update of the Android Studio.

Upvotes: 0

Luís Henriques
Luís Henriques

Reputation: 634

This happens to me all the time. Don't worry. There's an easy fix. Just go to that folder (\debug) and simply delete it. Then clean and rebuild your project.

Upvotes: 0

guipivoto
guipivoto

Reputation: 18677

This error happens because some process from previous build did not ended and is now locking that file/folder.

You can use Windows Process Explorer to check which process is locking that folder/file. Then, you just need to kill that process (windows task manager).

Link for Windows Process Explorer

If you don't want to use that Process Explorer, you can try to close Android Studio and the process may finish too. Or, you can just reboot your machine to kill all process.

I often use Windows Process Explorer. This way, I can find and kill the task without rebooting the PC...

Upvotes: 0

Related Questions