2017-03-06 56 views
5

在我将Android Studio从2.2更新到2.3并将应用程序运行到我的手机后,今天发生此错误。上周五一切都很好。这个星期一的礼物毁了我整天。
Gradle设置为“使用本地gradle分发”,版本3.3。某些文件运算失败,mergeDebugResources失败

日志信息如下,因为它太长,所有的人都是相似的,我只是复制了一些片段:

Error: Some file crunching failed, see logs for details 
:app:mergeDebugResources FAILED 
AAPT: \\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-mdpi-v4\abc_btn_switch_to_on_mtrl_00012.9.png ERROR: Unable to open PNG file 
AAPT: \\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-xxhdpi-v4\abc_ic_star_half_black_48dp.png ERROR: Unable to open PNG file 
AAPT: \\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-hdpi-v4\abc_ic_menu_share_mtrl_alpha.png ERROR: Unable to open PNG file 
AAPT: \\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-xxhdpi-v4\abc_text_select_handle_middle_mtrl_light.png ERROR: Unable to open PNG file 

AAPT err(Facade for 925134644) : No Delegate set : lost message:\\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-hdpi-v4\abc_ic_star_half_black_48dp.png ERROR: Unable to open PNG file 
AAPT err(Facade for 925134644) : No Delegate set : lost message:\\?\C:\Users\任\.android\build-cache\41cfce3bb6e2ca4b269727fe91725c24a067ec68\output\res\drawable-mdpi-v4\abc_switch_track_mtrl_alpha.9.png ERROR: Unable to open PNG file 

的build.gradle如下:

apply plugin: 'com.android.application' 
android { 
    compileSdkVersion 25 
    buildToolsVersion '25.0.2' 

    aaptOptions { 
     cruncherEnabled = false 
    } 

    defaultConfig { 
     minSdkVersion 18 
     targetSdkVersion 18 
    } 

    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 
     } 
    } 
    sourceSets { 
     main { 
      assets.srcDirs = ['src/main/assets', 'src/main/assets/'] 
     } 
    } 

    useLibrary 'org.apache.http.legacy' 

    dependencies { 
     compile fileTree(include: ['*.jar'], dir: 'libs') 
     testCompile 'junit:junit:4.12' 
     compile 'com.android.support:appcompat-v7:25.2.0' 
     compile 'com.android.support:support-v4:25.2.0' 
     compile 'com.jakewharton:butterknife:7.0.1' 
     compile 'org.jetbrains:annotations-java5:15.0' 
    } 
} 

据咨询其他问题,虽然有些答案太过时了,但我仍然尝试了以下方法,但不幸的是,它们中没有一个能够救我:
1.从我的项目中删除所有.9.png文件。
2.检查所有PNG文件是真实的PNG。
3.将下列设置的build.gradle:

aaptOptions { 
    cruncherEnabled = false 
} 

4.检查项目文件的路径,未达到255个字符(窗10)。
5.清除gradle缓存。
6.使缓存失效并重新启动。
7.清理项目。

我认为日志信息导致我由Android Studio自动生成的文件。试图搜索错误.png文件,它们都不存在于我的项目中。

任何意见表示赞赏。

+0

当我使用格式不正确的绘图工具时,我总是遇到这个问题。因此,如果您要复制drawables,请确保可以使用计算机上安装的媒体软件打开它。 –

+0

@FarazAhmed谢谢你的回复,但我在第二项中提到说我已经检查过了。 – Longer

回答

8

问题解决。解决方案是here

相关数据如下:
1.根据Android Studio 2.3版本的发布说明,默认情况下会启用构建缓存。
2.所以我们应该禁用此设置。这里是官方指南,Android Studio /用户指南/ build-cache(链接https://developer.android.com/studio/build/build-cache.html)。
3.转到gradle.properties文件,并禁用构建缓存。

// To re-enable the build cache, either delete the following 
// line or set the property to 'true'. 
android.enableBuildCache=false 

的另一种方式是通过增加

# first line can be skipped because true is the default value by 2.3 
android.enableBuildCache=true 
android.buildCacheDir =c:\\temp\\ 
+1

Awsome!更改缓存目录对我有效!我认为这是最好的解决方案。 –

+0

对于像我这样的新手用户:你在gradle.properties文件中加入了这个。 – green0range

+1

@ green0range是的,正如第3步所述。我不确定这个问题是否仍然存在,只要尝试一下,如果你坚持使用相同的日志信息。 – Longer

0

这是造成这个错误,因为在你的绘制,你必须更改扩展名从其他format.I到.png格式将建议修改构建的缓存目录更改扩展名使用MS Paint或其他图像编辑应用程序,如Gimp。

+0

我已通过选择所有可绘制文件并右键单击来查看它们的属性,它说Types是png文件。 – Longer