IOException 无法删除路径

Ник*_*дев 5 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获取更多帮助

    9 秒内构建失败

我经常从事这个项目,当我尝试在手机上运行我的应用程序时,我厌倦了在 40% 的情况下看到此错误。

如果我执行“重建项目”,错误就会消失并且应用程序将被编译。但在构建应用程序 2-3 次后,此错误再次出现。

这个项目非常大,我不能把时间浪费在重建项目上。我尝试手动删除该文件夹。但这对我没有帮助。

构建.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'
Run Code Online (Sandbox Code Playgroud)

Ник*_*дев 0

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