项目报错-Some file crunching failed, see logs for details

参考:Android Studio 报错 Error:Some file crunching failed, see logs for details

项目报错问题:

Error:Some file crunching failed, see logs for details


Error:Execution failed for task ':app:mergeDebugResources'.
> Error: Some file crunching failed, see logs for details

原因:

这是9-patch图片资源文件的问题

解决方法:

1、修改9-patch图片:

点击右下角的Gradle Console,查看gradle详细日志,比如我的项目:

Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]

Configuration on demand is an incubating feature.
NDK is missing a "platforms" directory.
If you are using NDK, verify the ndk.dir is set to a valid NDK directory.  It is currently set to D:\Users\Android\sdk\ndk-bundle.
If you are not using NDK, unset the NDK variable from ANDROID_NDK_HOME or local.properties to remove this warning.

useNewCruncher has been deprecated. It will be removed in a future version of the gradle plugin. New cruncher is now always enabled.
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2531Library
:app:prepareComAndroidSupportAppcompatV72531Library
:app:prepareComAndroidSupportConstraintConstraintLayout102Library
:app:prepareComAndroidSupportSupportCompat2531Library
:app:prepareComAndroidSupportSupportCoreUi2531Library
:app:prepareComAndroidSupportSupportCoreUtils2531Library
:app:prepareComAndroidSupportSupportFragment2531Library
:app:prepareComAndroidSupportSupportMediaCompat2531Library
:app:prepareComAndroidSupportSupportV42531Library
:app:prepareComAndroidSupportSupportVectorDrawable2531Library
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources

AAPT err(Facade for 1520024021): 
ERROR: 9-patch image \\?\D:\Users\Administrator\AndroidStudioProjects\Njb\app\src\main\res\drawable-xhdpi\iv_log_et_bg.9.png malformed.
AAPT err(Facade for 147729603): 
ERROR: 9-patch image \\?\D:\Users\Administrator\AndroidStudioProjects\Njb\app\src\main\res\drawable-xhdpi\commentlist.9.png malformed.
AAPT err(Facade for 1423460849): 
ERROR: 9-patch image \\?\D:\Users\Administrator\AndroidStudioProjects\Njb\app\src\main\res\drawable-mdpi\navbar.9.png malformed.
AAPT err(Facade for 1520024021):        Frame pixels must be either solid or transparent (not intermediate alphas).
AAPT err(Facade for 1423460849):        Must have one-pixel frame that is either transparent or white.
AAPT err(Facade for 147729603):        Frame pixels must be either solid or transparent (not intermediate alphas).
AAPT err(Facade for 1520024021):        Found at pixel #1 along bottom edge.
AAPT err(Facade for 147729603):        Found at pixel #565 along top edge.
AAPT err(Facade for 147729603): 
ERROR: 9-patch image \\?\D:\Users\Administrator\AndroidStudioProjects\Njb\app\src\main\res\drawable-xhdpi\supply_demand_add.9.png malformed.
AAPT err(Facade for 147729603):        Frame pixels must be either solid or transparent (not intermediate alphas).
AAPT err(Facade for 147729603):        Found at pixel #70 along top edge.

Error: Some file crunching failed, see logs for details
:app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: Some file crunching failed, see logs for details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 23.603 secs

先看下英文意思:

malformed:畸形

facade:表面

Frame pixels must be either solid or transparent (not intermediate alphas).
边框像素必须实心或者透明(不能中间的透明度)

Must have one-pixel frame that is either transparent or white.
必须有一个透明或白色的像素边框。

在上面的错误日志中我们知道哪些9-patch图片是有问题的,然后一张张的找到,操作如下:

项目报错-Some file crunching failed, see logs for details_第1张图片

按住Ctrl或者shift,点击鼠标左键在边界像素上调节黑色部分,直到我们需要的区域且不报错即可。

项目报错-Some file crunching failed, see logs for details_第2张图片

完成后sync,clean一下即可。

2、添加9-patch忽略:

如果还有问题,在APP的build.gradle添加Android studio忽略对9-patch的检查

    aaptOptions {
        cruncherEnabled = false
        useNewCruncher = false
    }

如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.3'

    aaptOptions {
        cruncherEnabled = false
        useNewCruncher = false
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/ASL2.0'
    }

    defaultConfig {
        applicationId "com.example.administrator.njb"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

你可能感兴趣的:(异常)