Process cannot access the file because it is being used by another process [Android] [Gradle]

9,041

Solution 1

What works for me is to close Android Studio, go to my workspace in the File Explorer and delete {project}/app/build. Then reopen Android Studio.

Solution 2

I added

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/*'
        exclude("META-INF/*.kotlin_module")
    }

in the android portion of my app/build.gradle file, and then I went into FileExplorer [myproject]/app and deleted the entire directory titled "build"

Share:
9,041
Chops
Author by

Chops

Updated on December 03, 2022

Comments

  • Chops
    Chops over 1 year

    Whenever trying to run a flutter app I am greeted with this error.

    * What went wrong: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. java.nio.file.FileSystemException: D:\Projects\buisnesscard\build\app\intermediates\transforms\mergeJavaRes\debug\0.jar: The process cannot access the file because it is being used by another process.

    I tried adding:

    packagingOptions { exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' }

    to my build gradle file and restarting android studio however the error still occurs.

    My /app/build.gradle looks like this:

    `

    def localProperties = new Properties()
    def localPropertiesFile = rootProject.file('local.properties')
    if (localPropertiesFile.exists()) {
        localPropertiesFile.withReader('UTF-8') { reader ->
            localProperties.load(reader)
        }
    }
    
    def flutterRoot = localProperties.getProperty('flutter.sdk')
    if (flutterRoot == null) {
        throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
    }
    
    def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
    if (flutterVersionCode == null) {
        flutterVersionCode = '1'
    }
    
    def flutterVersionName = localProperties.getProperty('flutter.versionName')
    if (flutterVersionName == null) {
        flutterVersionName = '1.0'
    }
    
    apply plugin: 'com.android.application'
    apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    android {
        compileSdkVersion 28
    
        lintOptions {
            disable 'InvalidPackage'
        }
    
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.seandiacono.buisnesscard"
            minSdkVersion 21
            targetSdkVersion 27
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig signingConfigs.debug
            }
        }
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.google.firebase:firebase-core:17.0.0'
    }
    
    apply plugin: 'com.google.gms.google-services'
    

    `

  • Sam
    Sam over 4 years
    I tried flutter clean but I got error 'flutter' is not recognized as an internal or external command, operable program or batch file.
  • Doug
    Doug almost 2 years
    Ran across something similar in Expo, also worked here.