libpng错误:不是PNG文件

时间:2015-11-21 18:17:13

标签: android compiler-errors android-gradle libpng aapt

我已多次尝试升级1.3.1之前的Android Studio构建工具,但我总是遇到这个libpng错误。我通过完全删除maven依赖项解决了其中一个错误(因为gradle控制台指向问题文件的确切位置),但现在我遇到了相同的错误,并且没有指向问题文件所在的指针。我错过了什么吗?这是gradle控制台日志:

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

Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidDatabindingAdapters10Rc3Library UP-TO-DATE
:app:prepareComAndroidDatabindingLibrary10Rc3Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72310Library UP-TO-DATE
:app:prepareComAndroidSupportCardviewV72310Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2310Library UP-TO-DATE
:app:prepareComAndroidSupportMediarouterV72220Library UP-TO-DATE
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:app:prepareComAndroidSupportPercent2310Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72310Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42310Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidAnswers132Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidBeta113Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlytics252Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlyticsCore235Library UP-TO-DATE
:app:prepareComFacebookAndroidFacebookAndroidSdk410Library UP-TO-DATE
:app:prepareComFacebookFrescoDrawee061Library UP-TO-DATE
:app:prepareComFacebookFrescoFbcore061Library UP-TO-DATE
:app:prepareComFacebookFrescoFresco061Library UP-TO-DATE
:app:prepareComFacebookFrescoImagepipeline061Library UP-TO-DATE
:app:prepareComGithubRahatarmanahmedCircularprogressview232Library UP-TO-DATE
:app:prepareComGoogleAndroidExoplayerExoplayerR142Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAds810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppstate810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesCast810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesDrive810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesFitness810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGames810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGcm810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesIdentity810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesLocation810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMeasurement810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesNearby810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPanorama810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPlus810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesVision810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWallet810Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWearable810Library UP-TO-DATE
:app:prepareIoFabricSdkAndroidFabric136Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources
AAPT err(Facade for 961886319): libpng error: Not a PNG file

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> 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: 4.398 secs

以下是我的build.gradle(模块:app)

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "us.revibe.revibe"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
    }
    buildTypes {
        debug{
            debuggable true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

repositories {
//    maven { url 'http://maven.livotovlabs.pro/content/groups/public' }
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.android.support:percent:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile files('libs/core-3.2.1.jar')
    compile files('libs/retrofit-1.9.0.jar')
    compile files('libs/connectionclass-1.0.1.jar')
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
    compile 'com.squareup.okhttp:okhttp:2.3.0'
    compile 'com.joanzapata.android:android-iconify:1.0.8'
    compile 'com.github.rahatarmanahmed:circularprogressview:2.3.2'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.facebook.fresco:fresco:0.6.1+'
    compile 'com.google.android.gms:play-services:8.1.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.amazonaws:aws-android-sdk-core:2.+'
    compile 'com.amazonaws:aws-android-sdk-cognito:2.+'
    compile 'com.amazonaws:aws-android-sdk-s3:2.+'
//    compile ('eu.livotov.labs:zxscanlib:2.0.1@aar') {transitive=true}

    compile 'com.google.android.exoplayer:exoplayer:r1.4.2'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
        transitive = true;
    }
}

以下是我的顶级build.gradle

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:1.5.0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

恢复到classpath" com.android.tools.build:gradle:1.3.1"似乎解决了这个问题,但我想开始使用所有新功能

3 个答案:

答案 0 :(得分:22)

问题出在您的png文件中。可能你的图像是通过一些png优化工具优化的。 Android工作室使用 AAPT 工具在构建项目期间优化图像。出现此问题的原因是 AAPT 工具不知道您预处理了图片。

要在您的应用程序中解决此问题,您需要在gradle中指定选项

  aaptOptions{
    cruncherEnabled = false
}

这是对所有png文件禁用 AAPT 优化。

类似问题被问到here

答案 1 :(得分:0)

我采取了简短的方法,只是删除了我在drawables文件夹中的任何未使用的文件。这似乎解决了这个问题。将来,我会确保粉碎任何PNG,然后将它们放入drawables文件夹中,如Tauqir建议的那样。

答案 2 :(得分:0)

实际上,原因是你的一些所谓的.png文件实际上不是 PNG ,而是其他一些类型(大多数我怀疑它们 JPEG s,但是其他人或可能是你用.png文件扩展名重命名它们只是为了欺骗Eclipse。但是请记住 Android Studio :D )

为了确保检查,打开一个PNG图像文件,可能会在Photoshop中提供此错误,如工具( Photoshop 更好,因为如果文件扩展名不同比它的实际格式还会出错。如果是这样,要找出你的图像文件的实际格式是使用webapp like this)。

<强>解决方案:
在Photoshop中打开文件后,将其另存为PNG。并尝试构建这个,大多数情况下这个问题可能已经消失。

希望这个答案对那里的人有所帮助 干杯!