IOException无法删除路径

时间:2018-04-09 10:50:03

标签: android android-studio

我在其中一个项目中遇到此错误。

  

失败:构建因例外而失败。

     
      
  • 出了什么问题:

         

    任务':app:transformClassesWithDesugarForDevServerDebug'执行失败。   com.android.build.api.transform.TransformException:java.io.IOException:无法删除路径' D:\ Android \ Projects \ uralenergo \ app \ build \ intermediates \ transforms \ desugar \ devServer \ debug \ 1的.jar'

  •   
  • 尝试:
          使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获得全面的见解。

  •   
  • https://help.gradle.org

    获取更多帮助      

    在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'

4 个答案:

答案 0 :(得分:1)

发生这种情况是由于多种原因,例如,当您升级操作系统或更改项目的路径或再次下载studio时,需要删除build文件夹中的先前文件。因此,在这种情况下,请以<>>以管理员身份运行 Android Studio

然后右键单击studio项目中的build文件夹,然后单击在资源管理器中显示。 现在删除构建文件夹。如果需要管理员权限,请单击复选框并删除它。现在重建项目并运行该项目。

答案 1 :(得分:0)

发生此错误是因为先前构建的某些进程未结束,现在正在锁定该文件/文件夹。

您可以使用Windows Process Explorer检查哪个进程正在锁定该文件夹/文件。然后,您只需要杀死该进程(Windows任务管理器)。

Link for Windows Process Explorer

如果您不想使用该Process Explorer,可以尝试关闭Android Studio,此过程也可能完成。或者,您可以重新启动计算机以终止所有进程。

我经常使用Windows Process Explorer。这样,我可以在不重新启动PC的情况下找到并终止任务...

答案 2 :(得分:0)

这种情况一直发生在我身上。别担心。这是一个简单的解决方案。 只需转到该文件夹​​(\ debug),然后将其删除即可。然后清理并重建您的项目。

答案 3 :(得分:0)

谢谢大家的回答。我通过删除Java 9并安装了Java 8来解决了这个问题。 当我安装Java 10时,问题并没有消失。我认为我们需要等待Android Studio的更新。