自动解决Android编译错误:帧像素必须是固体或透明的(不是中间阿尔法)。 - 发现了在像素#4沿顶边 [英] automatically solve Android build Error:Frame pixels must be either solid or transparent (not intermediate alphas). - Found at pixel #4 along top edge

查看:1785
本文介绍了自动解决Android编译错误:帧像素必须是固体或透明的(不是中间阿尔法)。 - 发现了在像素#4沿顶边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android的工作室(使用SDK 19,21或22)显示错误的Eclipse ADT(使用SDK 19)不:

  

错误:9片图像D:\工作区.... \水库\绘制,华电国际\ btn_bg_common_ press.9.png畸形。   错误:帧像素必须是固体或透明的(不是中间阿尔法)。 - 发现了在像素#4沿顶边

或<一href="http://stackoverflow.com/questions/28940476/android-gradle-build-errorticks-in-transparent-frame-must-be-black-or-red">other错误:

  

错误:蜱在透明的框架必须是黑色或红色

无论在 AAPT

  

错误:错误:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:处理'命令'E:\ Android的\ SDK-机器人工作室\集结工具\ 19.1。 0 \ aapt.exe''非零退出值完成42

文件的实施例的正上方,但也有行之有效20+此类文件。

如何让Android Studio或摇篮跳过此错误,而无需修改这些文件没有失败一个接一个?

如果这是不可能与摇篮,我什么命令行工具可以用它来代替所有透明象素与非透明?

更新:build.gradle的应用模块(如资源)低于

我跟 SDK 19和SDK 21 都试过,的build工具19.1,21.1.2,22

在AOSP类似问题 问题159464:Android的工作室:mergeDebugResources失败时导入Eclipse项目

  buildscript {
    库{
        jcenter()
    }
    依赖{
        类路径com.android.tools.build:gradle:1.1.+
    }
}

allprojects {
    库{
        jcenter()
    }
}

// ---
任务包装(类型:包装){
    gradleVersion =2.2.1
}

应用插件:com.android.application

依赖{
    编译文件树(导演:库,包括:的* .jar)
    编制项目(:afinal)
    编译com.android.support:appcompat-v7:19.0.+
    //编译com.android.support:appcompat-v7:21.0.+
}

// ---
安卓{
    sourceSets {
        主要 {
            manifest.srcFile的Andr​​oidManifest.xml
            res.srcDirs = ['水库']
            assets.srcDirs = ['资产']
        }
    }

    compileSdkVersion 19
    buildToolsVersion19.1.0
    // compileSdkVersion 21
    // buildToolsVersion21.1.2
    // compileSdkVersion的Integer.parseInt(project.COMPILE_SDK_VERSION)
    // buildToolsVersion project.BUILD_TOOLS_VERSION

    buildTypes {
        推出 {
            minifyEnabled假
            proguardFiles getDefaultProguardFile('ProGuard的-android.txt'),'ProGuard的-rules.txt
            zipAlignEnabled真
            // signingConfig signingConfigs.release
        }
        调试{
            zipAlignEnabled真
        }
    }

    lintOptions {
        // checkReleaseBuilds假
        //或者,如果你preFER,您可以继续检查错误的发布版本,
        //但即使继续建立发现错误的时候:
        abortOnError假// false还需要https://wiki.jenkins-ci.org/display/JENKINS/Android+Lint+Plugin
    }
} //机器人
 

Android的摇篮插件来源是在
<一href="https://android.googlesource.com/platform/tools/build/+/master">https://android.googlesource.com/platform/tools/build/+/master

解决方案
  

如何自动解决这个问题(但不检查在不同分辨率下的所有图片)

不可能的。既然你想要的巴纽表现得像一个九补丁(沿边缘扩展,不会延长整个位图),你将不得不将其格式化为这样的ERGO的你要修改的文件

建议的替代

由于形状是如此简单,你会更好删除该文件的所有变体(节省空间,在这个过程中的时间和头痛),并创建 / RES /绘制/ btn_bg_common_ preSS的.xml 绘制有以下内容:

 &LT; XML版本=1.0编码=UTF-8&GT?;
&LT;形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
       机器人:形状=矩形&GT;
    &LT;边角机器人:半径=16DP/&GT;
    [固体机器人:颜色=#CCC/&GT;
    &LT;中风
        机器人:颜色=#0C0
        机器人:宽=2DP/&GT;
&LT; /形状&GT;
 

您可以使用颜色的资源,而不是硬codeD值。此外,您可能要添加在填充元素形状

 &LT;形状...&GT;
    &LT;填充
        机器人:顶部=8DP
        机器人:左=8DP
        机器人:底部=8DP
        机器人:右=8DP/&GT;
&LT; /形状&GT;
 

和/或包裹形状插入元素中的元素。

 &LT;插图
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:insetTop =8DP
    机器人:insetLeft =8DP
    机器人:insetBottom =8DP
    机器人:insetRight =8DP&GT;
    &LT;形状...&GT;
&LT; /插图&GT;
 

如果你这样做,可绘制会有隐含填充,你会不会有造型的小部件时,将其设置。既然你有多个状态可绘制的按钮,我建议你转换所有的人都为xml,以确保线条的粗细和角落的比赛。

尽管根元素的名称&LT;形状&GT; 竟膨胀到 GradientDrawable (这意味着你可以往里面渐变而不是纯色)。回顾<一href="http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html"><$c$c>GradientDrawable文档其所有选项。不要的永远的使用 ShapeDrawable 编程,这是行不通的。

分析9补丁

考虑以下三个放大的影像。

候选人#1是一个九补丁。它在每一侧为拉伸和填充的规格而保留1px的。这人会表现为一个普通的位图拉伸时。如果宽度大于高度,所以将在两侧的边框厚度。边框会按比例缩放。

候选人#2也是九补丁,实际上说这是怎么回事伸展除了1px的边框一切,将隐含在每边的3px的填充。拉伸时就会有一个不错的挺括1px的边界。

候选人#3是不会九补丁。它缩放方式相同#1

现在,让我们来看看在图像的放大版,你包括在OP:

正如你可以看到它不是一个九补丁,所以它不会得到跨preTED为一体,并构建工具是一种足以提醒你。即使旧的构建工具更宽容,并添加每边为你透明1px的,结果会表现得就像一个普通的位图,这意味着当把手一伸,看起来就像一个标本,而不是样品B.预期的结果。

下面的在九补丁更多的阅读。这解释了在每一侧的额外1px的用于

Android Studio (using SDK 19, 21 or 22) shows error that Eclipse ADT (using SDK 19) does not:

Error:9-patch image D:\Workspaces....\res\drawable-hdpi\btn_bg_common_press.9.png malformed. Error:Frame pixels must be either solid or transparent (not intermediate alphas). - Found at pixel #4 along top edge.

or other error:

Error:Ticks in transparent frame must be black or red.

both within aapt

Error:Error: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\Android\sdk-Android-Studio\build-tools\19.1.0\aapt.exe'' finished with non-zero exit value 42

Example of file is above, but there are 20+ such files that worked well.

How to make Android Studio or gradle to skip this error and not to fail without having to modify those files one-by-one?

If it is not possible with gradle, what command-line tool could I use to replace all transparent pixel with non-transparent?

UPDATE: build.gradle for application module (where resources are) is below.

I have tried both with SDK 19 and SDK 21, build tools 19.1, 21.1.2, 22

Similar issue on AOSP Issue 159464: Android studio :mergeDebugResources FAILED when import eclipse project.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.+'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

//---
task wrapper(type: Wrapper) {
    gradleVersion = '2.2.1'
}

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':afinal')
    compile 'com.android.support:appcompat-v7:19.0.+'
    //compile 'com.android.support:appcompat-v7:21.0.+'
}

//---
android {
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }

    compileSdkVersion 19
    buildToolsVersion "19.1.0"
    //compileSdkVersion 21
    //buildToolsVersion "21.1.2"
    //compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VERSION)
    //buildToolsVersion project.BUILD_TOOLS_VERSION

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            zipAlignEnabled true
            //signingConfig signingConfigs.release
        }
        debug {
            zipAlignEnabled true
        }
    }

    lintOptions {
        //checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false // false also required by https://wiki.jenkins-ci.org/display/JENKINS/Android+Lint+Plugin
    }
}//android

Android gradle plugins sources are at
https://android.googlesource.com/platform/tools/build/+/master

解决方案

How automatically solve the issue (without checking all images in different resolutions)

Not possible. Since you want the .png to behave like a nine-patch (expand along the edges, not stretch the whole bitmap), you're going to have to format them as such ergo you have to modify the files.

Proposed alternative

Since the shape is so simple you'd be better off deleting all variants of this file (saving space, time and headache in the process) and create /res/drawable/btn_bg_common_press.xml drawable with following contents:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <corners android:radius="16dp"/>
    <solid android:color="#ccc"/>
    <stroke
        android:color="#0c0"
        android:width="2dp"/>
</shape>

You can use dimen and color resources instead of hardcoded values. Additionally you might want to add the padding element inside shape

<shape...>
    <padding
        android:top="8dp"
        android:left="8dp"
        android:bottom="8dp"
        android:right="8dp"/>
</shape>

and/or wrap the shape element inside an inset element.

<inset
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetTop="8dp"
    android:insetLeft="8dp"
    android:insetBottom="8dp"
    android:insetRight="8dp">
    <shape...>
</inset>

If you do that, the drawable will have implied padding and you won't have to set it when styling widgets. Since you have multiple state drawables for the button I suggest you convert all of them to XML to make sure the line thickness and corners match.

Despite the root element's name the <shape> actually inflates to GradientDrawable (meaning you can fill it with gradient instead of solid color). Review GradientDrawable docs for all its options. Do not ever use ShapeDrawable programmatically, it just doesn't work.

Analyzing 9-patches

Consider the three following enlarged images.

Candidate #1 is a nine-patch. It has reserved 1px on each side for stretch and padding specification. This one will behave as an ordinary bitmap when stretched. If the width will be greater than height, so will the border thickness on sides. The border will scale proportionally.

Candidate #2 is also a nine-patch and is actually saying it's going to stretch everything besides 1px border and will have implied padding of 3px on each side. It will have a nice crisp 1px border when stretched.

Candidate #3 is NOT a nine-patch. It scales the same way as #1.

Now let's take a look at enlarged version of the image you included in OP:

As you can see it's not a nine-patch, so it won't get interpreted as one and the build tools are kind enough to warn you of that. Even if older build tools were more forgiving and added transparent 1px on each side for you, the result would have behaved like an ordinary bitmap, meaning when stretched it would look like specimen A instead of expected result specimen B.

Here's more reading on nine-patches. This explains what the extra 1px on each side is used for.

这篇关于自动解决Android编译错误:帧像素必须是固体或透明的(不是中间阿尔法)。 - 发现了在像素#4沿顶边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆