每当尝试运行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.
我尝试添加:
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'
`
答案 0 :(得分: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”的目录
答案 1 :(得分:1)
对我有用的是关闭Android Studio,转到文件资源管理器中的工作区,然后删除{project} / app / build。然后重新打开Android Studio。
答案 2 :(得分:0)
试试这个
Android Studio:
File -> Invalidate Caches / Restart.. > Invalidate/ Restart
或终端:
flutter clean
答案 3 :(得分:0)
在 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'
}
答案 4 :(得分:0)
当我开始从 Windows 更新我的项目时,我遇到了同样的问题。同一个项目运行良好,能够在 mac os 中构建 apk。
就我而言,问题是由于堆分析造成的。如果您不想使用堆分析,请在 build.gradle 中禁用堆并删除相关依赖项。 或者,如果这是一项要求,请在下面查看我的解决方案。
当前系统操作系统:Windows 10
我的解决方案:
'com.heapanalytics.android'
更新 build.gradle
版本(**非常重要)。就我而言,我更新到版本“1.7.0”build.gradle
android.permission.WAKE_LOCK
权限。这是为了
Firebase 分析实例。使缓存无效并重新启动,然后重建您的项目。
Nb: It will be helpful if anyone struggling with same scenario. That's why i'm posting here. Thanks.
答案 5 :(得分:0)
可能的问题:问题是 Java 服务/进程被调试文件夹中的文件卡住了(这就是为什么错误消息指向您的 .jar 文件的原因),
可能的解决方案:您必须重新启动或终止 Java 服务/进程。
这样我就解决了这个问题,希望对你有帮助