[英]Process cannot access the file because it is being used by another process [Android] [Gradle]
Whenever trying to run a flutter app I am greeted with this error.每当尝试运行 flutter 应用程序时,都会遇到此错误。
* 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.到我的构建 gradle 文件并重新启动 android studio 但是错误仍然存在。
My /app/build.gradle looks like this:我的 /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'
` `
What works for me is to close Android Studio, go to my workspace in the File Explorer and delete {project}/app/build.对我有用的是关闭 Android Studio,在文件资源管理器中转到我的工作区并删除 {project}/app/build。 Then reopen Android Studio.
然后重新打开 Android Studio。
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"在我的 app/build.gradle 文件的 android 部分,然后我进入 FileExplorer [myproject]/app 并删除了名为“build”的整个目录
Add a multiDexEnabled in app\\build.grade
在
app\\build.grade
添加app\\build.grade
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'
}
I've been facing the same issue when started updating my project from windows.当我开始从 Windows 更新我的项目时,我一直面临着同样的问题。 Same project works fine and able to build apk in mac os.
同一个项目运行良好,能够在 mac os 中构建 apk。
In my case the issue was due to heap analytics.就我而言,问题是由于堆分析造成的。 If you don't want to use heap analytics disable heap in build.gradle and remove related dependencies.
如果您不想使用堆分析,请在 build.gradle 中禁用堆并删除相关依赖项。 Or if it was a requirement, please go through my solution below.
或者,如果这是一项要求,请在下面查看我的解决方案。
Current System OS : Windows 10当前系统操作系统:Windows 10
My solution :
我的解决方案:
- Updated all dependencies with latest version (only updating lib doesn't resolve the issue: but its recommended).
使用最新版本更新了所有依赖项(仅更新 lib 不能解决问题:但建议这样做)。
- Update
'com.heapanalytics.android'
version (**very important) in project levelbuild.gradle
.更新项目级
build.gradle
'com.heapanalytics.android'
版本(**非常重要)。 In my case I updated to version '1.7.0'就我而言,我更新到版本“1.7.0”
- Update google play services version in project level
build.gradle
在项目级别
build.gradle
更新 google play 服务版本- Add
android.permission.WAKE_LOCK
permisiion in manifest if not previously included.如果之前未包含,请在清单中添加
android.permission.WAKE_LOCK
权限。 It was for firebase analytics instance.它用于 firebase 分析实例。
Invalidate caches and restart, then Rebuild your project.使缓存无效并重新启动,然后重建您的项目。
Nb: It will be helpful if anyone struggling with same scenario. That's why i'm posting here. Thanks.
Possible issue: the problem is that the Java service/process gets stuck with the file in your debug folder (that why the error message point to your .jar file),可能的问题:问题是 Java 服务/进程被调试文件夹中的文件卡住了(这就是为什么错误消息指向您的 .jar 文件的原因),
Possible solution: you have to restart or kill the Java service/process.可能的解决方案:您必须重新启动或终止 Java 服务/进程。
With that I was able to solve the problem, I hope it helps you有了这个我能够解决问题,我希望它可以帮助你
将我的文件夹从我的Dropbox文件夹中移出并执行flutter clean
为我修复了类似的问题。
This always works for me on Windows.这对我来说总是适用于 Windows。 Open Task Manager, go to Details tab, find and kill java.exe and run app again.
打开任务管理器,go 到详细信息选项卡,找到并杀死 java.exe 并再次运行应用程序。
For them, who tried everything对于他们,谁尝试了一切
I faced the same issue and there were a lot of stuffs as a solution, mostly flutter clean and stopping java.exe.我遇到了同样的问题,并且有很多东西可以作为解决方案,主要是 flutter 清理并停止 java.exe。 But what I found in the end is,
但我最后发现的是,
When I run my app my storage reaches it's max.当我运行我的应用程序时,我的存储空间达到了最大值。 And then the program ends up doing this.
然后程序最终会这样做。 So for me none of those solution worked.
所以对我来说,这些解决方案都没有奏效。 I just had to figure it out and clear my storage a bit.
我只需要弄清楚并清理一下我的存储空间。
Try this尝试这个
Android studio :安卓工作室:
File -> Invalidate Caches / Restart.. > Invalidate/ Restart
or terminal:或终端:
flutter clean
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.