aapt 获取'android:name'属性的错误:属性不是一个字符串值[英] aapt ERROR getting 'android:name' attribute: attribute is not a string value

本文是小编为大家收集整理的关于aapt 获取'android:name'属性的错误:属性不是一个字符串值的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

生成我的apk,我在它上执行命令aapt dump badging.我继续收到以下错误:

应用程序:label ='name'图标='res/drawable/icon_128x128.png'
应用程序调试可启动活动: name ='co.package.name.mainactivity'label ='name'icon =''错误 获取'Android:name'属性:属性不是字符串值

我试图为所有活动添加标签名称,并删除/res下的所有其他值-xxx文件夹,但vain.但是,如果我创建一个全新的项目并生成新的APK,则可以使用aapt dump badging命令成功执行APK.

我比较了两个APK的印刷消息,发现了主要区别:

成功的消息apk:

应用程序标签:'applabel'
application-icon-160:'res/drawable-xhdpi/icon_128x128.png'
application-icon-240:'res/drawable-xhdpi/icon_128x128.png'
application-icon-320:'res/drawable-xhdpi/icon_128x128.png'
应用程序:Label ='Applabel' icon ='res/drawable-xhdpi/icon_128x128.png'
Application-Debugaumable
可启动 - 活动: name ='com.demo.testapp.mainactivity'label ='''icon ='

失败的消息apk:

应用程序标签:'myapp'
应用程序 - 标签 - ja:'myapp'
application-label-de:'myapp'
应用程序 - 标签 - 他:'myapp'

application-label-zh:'myapp'
应用程序 - 标签 - fi:'myapp'
application-label-nl:'myapp'
..
..(所有语言都会附加,最后发生错误)

应用程序:Label ='MyApp'icon ='Res/Waplable/Icon_128x128.png'
应用程序 - 调试
可启动 - 活动: name ='com.name.myapp.mainactivity'label ='myapp'icon =''
错误 获取'Android:name'属性:属性不是字符串值


-----编辑------
我发现没有与"语言"问题有关.我修改了我的清单文件,确保没有打印出这样的"应用程序标签-XX",错误仍然是相同的.

下面是我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="co.package.name"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <supports-screens android:anyDensity="true" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- Location -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <!-- Camera -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.camera.front"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />

    <!-- GCM Necessary -->
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <permission
        android:name="co.package.name.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="co.package.name.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Calendar R/W -->
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon_128x128"
        android:label="@string/app_name"
        >
        <!-- GCM meta-data -->
        <meta-data
            android:name="com.arrownock.push.SERVICE_TYPE"
            android:value="GCM" />
        <meta-data
            android:name="com.arrownock.push.gcm.SENDER_ID"
            android:value="@string/gcm_project_id" />
        <meta-data
            android:name="com.arrownock.push.APP_KEY"
            android:value="@string/light_appkey" />

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/fb_id" />

        <activity
            android:name=".Main"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.package.name.SplashHP"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SettingsHP"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.package.name.LocationSelect"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.package.name.SettingOptionAlarm"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SettingOptionNotify"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SettingOptionShare"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="settingshare"
                    android:scheme="oauth" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.package.name.HpCalendar"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SMSList"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SMSEditor"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SMSChooseToSend"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.ShareToFB"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.ActPOI"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>

        <activity
            android:name="com.facebook.LoginActivity"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.LogInOutFB"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>

        <activity
            android:name="co.package.name.LoginTwitter"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="t4jsample"
                    android:scheme="oauth" />
            </intent-filter>
        </activity>

        <receiver
            android:name="co.package.name.AlarmReceiver"
            android:exported="true" >
            <intent-filter>
                <action android:name="@string/action_alarm" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

        <!-- GCM Service -->
        <receiver
            android:name="com.arrownock.push.AnPushGCMReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="co.package.name" />
            </intent-filter>
        </receiver>
        <service android:name="com.arrownock.push.GCMIntentService" />

        <receiver
            android:name="co.package.name.ExtendedReceiver"
            android:exported="true"
            android:icon="@drawable/icon_128x128"
            android:label="Receiver" >
            <intent-filter>
                <action android:name="com.arrownock.push.PushService.MSG_ARRIVAL" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

也许在我的清单文件中有错误的格式或错字?

------编辑----
我也认为也许这是解码问题.在我的环境中,我使用UTF-8.也许在将XML转换为二进制文件的构建过程中是错误的?

如果在上面有任何不合理的嫌疑人,我真诚地道歉.我已经陷入了这个问题三天,真的无法达到进步.尝试了很多事情,错误总是相同的.任何建议或评论都将非常感激.

推荐答案

你的意思是这也可能是由破碎的aapt工具引起的吗?

肯定. Android工具历史上有很多错误,并且没有理由假设 aapt dump badging 以某种方式完美.事实上,您的非常问题已被提交为错误.所以,除非你是,必然是你的应用程序.

如果您还没有更新到R22工具,则可能会这样做,以查看此错误是否已修复,并且它们只有未关闭此问题.如果您在R22工具上,您可能会向该问题添加评论,指向此问题,并将其包含在此问题上的链接,因此工具团队在问题方面具有另一个数据点.

其他推荐答案

在这里的同一个故事.当我将工作APK上载到Google Play时,我收到了这条消息.我能够使用AAPT命令(... \ android-sdk \ platform-tools)重现它.它原来是一个意图过滤器名称中的字符串资源,并通过硬编码来修复.

它会让我在没有这个答案的情况下调试这个loooooong时间:)

其他推荐答案

如果您使用Gradle,并且希望将替换基于您的构建口味,您可以使用自定义替换字符串而不是使用Android @String引用. ( http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-mergerge#oc-placeHolder-Support

在build.gradle文件中,为"纸张持卡人"部分定义每个构建风味的值:

productFlavors {
    pro {
        manifestPlaceholders = [
            proFreeString:"my.pro.string"
        ]
    }
    free {
        manifestPlaceholders = [
            proFreeString:"my.free.string"
        ]
    }
}

然后,您可以在清单文件中使用"prepreestring"作为替换:

        <intent-filter>
            <action android:name="com.foo.${proFreeString}.ACTION_1" />
        </intent-filter>

本文地址:https://www.itbaoku.cn/post/1937938.html

问题描述

As my apk is generated I execute the command aapt dump badging on it. I keep receiving the following error:

application: label='Name' icon='res/drawable/icon_128x128.png'
application-debuggable launchable-activity: name='co.package.name.MainActivity' label='Name' icon='' ERROR getting 'android:name' attribute: attribute is not a string value

I've tried to add a label name for all activities and remove all other values-xxx folders under /res but in vain. However, if I create a whole new project and generate a new APK, the APK can be executed with the aapt dump badging command successfully.

I compared the printed message of both APK and found a main difference:

Message of Success apk:

application-label:'AppLabel'
application-icon-160:'res/drawable-xhdpi/icon_128x128.png'
application-icon-240:'res/drawable-xhdpi/icon_128x128.png'
application-icon-320:'res/drawable-xhdpi/icon_128x128.png'
application: label='AppLabel' icon='res/drawable-xhdpi/icon_128x128.png'
application-debuggable
launchable-activity: name='com.demo.testApp.MainActivity' label='' icon='

Message of Failed apk:

application-label:'MyApp'
application-label-ja:'MyApp'
application-label-de:'MyApp'
application-label-he:'MyApp'
application-label-zh:'MyApp'
application-label-fi:'MyApp'
application-label-nl:'MyApp'
..
.. (all languages would be attached, and finally the error occurs)
..
application: label='MyApp' icon='res/drawable/icon_128x128.png'
application-debuggable
launchable-activity: name='com.name.myapp.MainActivity' label='MyApp' icon=''
ERROR getting 'android:name' attribute: attribute is not a string value


----- Edit ------
I found there's no relevance to "Language" issue. I modified my Manifest file and make sure there is no such "application-label-XX" printed out, and the error is still the same.

Below is my Manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="co.package.name"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <supports-screens android:anyDensity="true" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- Location -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <!-- Camera -->
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.camera.front"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />

    <!-- GCM Necessary -->
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />

    <permission
        android:name="co.package.name.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="co.package.name.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

    <!-- Calendar R/W -->
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon_128x128"
        android:label="@string/app_name"
        >
        <!-- GCM meta-data -->
        <meta-data
            android:name="com.arrownock.push.SERVICE_TYPE"
            android:value="GCM" />
        <meta-data
            android:name="com.arrownock.push.gcm.SENDER_ID"
            android:value="@string/gcm_project_id" />
        <meta-data
            android:name="com.arrownock.push.APP_KEY"
            android:value="@string/light_appkey" />

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/fb_id" />

        <activity
            android:name=".Main"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.package.name.SplashHP"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SettingsHP"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.package.name.LocationSelect"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.package.name.SettingOptionAlarm"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SettingOptionNotify"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SettingOptionShare"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="settingshare"
                    android:scheme="oauth" />
            </intent-filter>
        </activity>
        <activity
            android:name="co.package.name.HpCalendar"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SMSList"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SMSEditor"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.SMSChooseToSend"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.ShareToFB"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.ActPOI"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>

        <activity
            android:name="com.facebook.LoginActivity"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>
        <activity
            android:name="co.package.name.LogInOutFB"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        </activity>

        <activity
            android:name="co.package.name.LoginTwitter"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="t4jsample"
                    android:scheme="oauth" />
            </intent-filter>
        </activity>

        <receiver
            android:name="co.package.name.AlarmReceiver"
            android:exported="true" >
            <intent-filter>
                <action android:name="@string/action_alarm" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </receiver>

        <!-- GCM Service -->
        <receiver
            android:name="com.arrownock.push.AnPushGCMReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>

                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="co.package.name" />
            </intent-filter>
        </receiver>
        <service android:name="com.arrownock.push.GCMIntentService" />

        <receiver
            android:name="co.package.name.ExtendedReceiver"
            android:exported="true"
            android:icon="@drawable/icon_128x128"
            android:label="Receiver" >
            <intent-filter>
                <action android:name="com.arrownock.push.PushService.MSG_ARRIVAL" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

Maybe there's a wrong format or typo in my Manifest file?

------ Edit ----
I also consider maybe it's a issue of decoding. In my environment I use utf-8. Maybe something is wrong within the build process of transforming XML to binary file?

If there's anything unreasonable suspect on above I sincerely apologize. I've stuck on this issue three days and really can't reach a progress. Tried a lot of things and the error is always the same. Any suggestion or comment would be really appreciated.

推荐答案

Do you mean this may also be caused by a broken aapt tool?

Sure. The Android tools have had plenty of bugs, historically, and there's no reason to assume that aapt dump badging is somehow perfect. In fact, your very issue has already been filed as a bug. So, unless you are also seeing some problem in your app's execution that might be tied in here, I'd assume that aapt dump badging is the item with the issue, not necessarily your app.

If you have not yet updated to the R22 tools, you might do so, to see if this bug has been fixed and they simply have not closed the issue. If you are on the R22 tools, you might add a comment to that issue, pointing this out, and include a link to this SO question, so the tools team has another data point in terms of the problem.

其他推荐答案

Same story here. I got this message when I uploaded a working apk to google play. I was able to reproduce it with the aapt command (in ...\android-sdk\platform-tools). It turned out to be a String resource in the name for an intent filter, and was fixed by hard coding it.

It would have taken me a loooooong time to debug this without this answer :)

其他推荐答案

If you are using Gradle and you want your substitution to be based on one of your build flavors, you can use a custom substitution string instead of using Android @string references. (http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-Placeholder-support)

In your build.gradle file, define a value for each build flavor in a "manifestPlaceholders" section:

productFlavors {
    pro {
        manifestPlaceholders = [
            proFreeString:"my.pro.string"
        ]
    }
    free {
        manifestPlaceholders = [
            proFreeString:"my.free.string"
        ]
    }
}

Then you can use "proFreeString" as a substitution in your Manifest file:

        <intent-filter>
            <action android:name="com.foo.${proFreeString}.ACTION_1" />
        </intent-filter>