IOException не может удалить путь

Я получаю эту ошибку в одном из моих проектов.

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

Я очень часто работаю над этим проектом, и мне надоело видеть эту ошибку в 40% случаев, когда я пытаюсь запустить приложение на своем телефоне.

Если я сделаю Rebuild Project, ошибка исчезнет, ​​и приложение будет скомпилировано. Но после 2-3 раз сборки приложения эта ошибка появляется снова.

Проект очень большой, и я не могу тратить свое время на Rebuild Project. Я пытался удалить эту папку вручную. Но мне это не помогло.

build.gradle файл:

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'

часть кода, вы можете вставить ее сюда?

Na-In Hae 09.04.2018 12:52

попробуйте перестроить свой проект

Jyoti JK 09.04.2018 13:04

@Sam Какую часть кода вы хотите увидеть?

Николай Медведев 09.04.2018 13:12

@JyotiJK Я делаю это все время. Я об этом писал ...

Николай Медведев 09.04.2018 13:12
2
4
6 848
4
Перейти к ответу Данный вопрос помечен как решенный

Ответы 4

Эта ошибка возникает из-за того, что какой-то процесс из предыдущей сборки не завершился и теперь блокирует этот файл / папку.

Вы можете использовать Windows Process Explorer, чтобы проверить, какой процесс блокирует эту папку / файл. Затем вам просто нужно убить этот процесс (диспетчер задач Windows).

Ссылка для Windows Process Explorer

Если вы не хотите использовать этот Process Explorer, вы можете попробовать закрыть Android Studio, и процесс тоже может завершиться. Или вы можете просто перезагрузить компьютер, чтобы убить весь процесс.

Я часто использую Windows Process Explorer. Таким образом, я могу найти и убить задачу, не перезагружая компьютер ...

Со мной такое случается постоянно. Не волнуйся. Есть простое решение. Просто перейдите в эту папку (\ debug) и просто удалите ее. Затем очистите и перестройте свой проект.

Ответ принят как подходящий

Спасибо всем за ответы. Я решил проблему, удалив Java 9 и установив Java 8. Когда я установил Java 10, проблема не исчезла. Думаю, нам нужно дождаться обновления Android Studio.

Это происходит по нескольким причинам, например, когда вы обновляете ОС, меняете путь к проекту или снова загружаете студию, а предыдущие файлы в папке сборки необходимо удалить. Итак, в этом случае запустите Студия Android как -> Запуск от имени администратора.

Затем щелкните правой кнопкой мыши папку сборки из проекта студии и выберите Показать в проводнике. Теперь удалите папку сборки. Если для этого требуется разрешение администратора, установите флажок и удалите его. Теперь перестройте проект и запустите проект.

Другие вопросы по теме