【问题标题】:Process cannot access the file because it is being used by another process [Android] [Gradle]进程无法访问该文件,因为它正被另一个进程使用 [Android] [Gradle]
【发布时间】:2019-11-22 09:09:51
【问题描述】:

每当尝试运行颤振应用程序时,都会遇到此错误。

* 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.

我尝试添加:

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

到我的构建 gradle 文件并重新启动 android studio 但是错误仍然发生。

我的 /app/build.gradle 看起来像这样:

`

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'

`

【问题讨论】:

    标签: android firebase gradle flutter


    【解决方案1】:

    对我有用的是关闭 Android Studio,在文件资源管理器中转到我的工作区并删除 {project}/app/build.然后重新打开 Android Studio。

    【讨论】:

      【解决方案2】:

      我加了

          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")
          }
      

      在我的 app/build.gradle 文件的 android 部分,然后我进入 FileExplorer [myproject]/app 并删除了标题为“build”的整个目录

      【讨论】:

        【解决方案3】:

        试试这个
        Android 工作室:

        File -> Invalidate Caches / Restart.. > Invalidate/ Restart
        

        或终端:

        flutter clean
        

        【讨论】:

        • 我尝试了flutter clean,但出现错误'flutter' is not recognized as an internal or external command, operable program or batch file.
        【解决方案4】:

        app\build.grade中添加一个multiDexEnabled

        defaultConfig {
                .......
                minSdkVersion 21
                targetSdkVersion 28 
                multiDexEnabled true
                .......
            }
        dependencies {
            .....
            implementation 'com.google.firebase:firebase-core:16.0.9'
            compile  'com.android.support:multidex:1.0.3'
        }
        

        【讨论】:

          【解决方案5】:

          当我开始从 Windows 更新我的项目时,我遇到了同样的问题。同一个项目运行良好,并且能够在 mac os 中构建 apk。

          在我的情况下,问题是由于堆分析造成的。如果您不想使用堆分析,请在 build.gradle 中禁用堆并删除相关依赖项。 或者,如果这是一个要求,请在下面查看我的解决方案。

          当前系统操作系统:Windows 10


          我的解决方案:

          1. 使用最新版本更新了所有依赖项(仅更新 lib 不能解决问题:但建议这样做)。
          2. 在项目级别build.gradle 中更新'com.heapanalytics.android' 版本(**非常重要)。就我而言,我更新到版本“1.7.0”
          3. 在项目级别更新 google play 服务版本build.gradle
          4. 如果之前未包含在清单中添加android.permission.WAKE_LOCK 权限。这是为了 firebase 分析实例。

          使缓存无效并重新启动,然后重建您的项目。

          Nb: It will be helpful if anyone struggling with same scenario. That's why i'm posting here. Thanks.

          【讨论】:

            【解决方案6】:

            可能的问题:问题是 Java 服务/进程被您的调试文件夹中的文件卡住(这就是错误消息指向您的 .jar 文件的原因),

            可能的解决方案:您必须重新启动或终止 Java 服务/进程。

            这样我就可以解决问题了,希望对你有帮助

            【讨论】:

              【解决方案7】:

              将我的文件夹移出我的 Dropbox 文件夹并执行 flutter clean 为我修复了类似的问题。

              【讨论】:

                猜你喜欢
                • 2010-12-10
                相关资源
                最近更新 更多