Android resource linking failed的解决方案

今天尝试国际化安卓应用,配置了中国和美国的字符串资源文件,在布局文件使用了它们,

位置:res/values-en-rUS/strings.xml

<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ExtraTranslation">
    <string name="ok">OK</string>
    <string name="cancel">Cancel</string>
    <string name="msg">Hello, Android!</string>
</resources>

位置:res/values-zh-rCN/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="ExtraTranslation">
    <string name="ok">确定</string>
    <string name="cancel">取消</string>
    <string name="msg">你好啊,安卓</string>
</resources>

位置:res/layout/nationalization.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/na_show"
        android:text="@string/msg"
        android:textSize="20sp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:text="@string/ok"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <Button
            android:text="@string/cancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>

</LinearLayout>

资源文件存在且在布局文件中使用了,在编译工程时出现以下错误:

Android resource linking failed
warn: removing resource com.example.studyandroidchapter6_002:string/cancel without required default value.
warn: removing resource com.example.studyandroidchapter6_002:string/msg without required default value.
warn: removing resource com.example.studyandroidchapter6_002:string/ok without required default value.
D:\Android\Project\StudyAndroidChapter6_002\app\src\main\res\layout\nationalization.xml:8: error: resource string/msg (aka com.example.studyandroidchapter6_002:string/msg) not found.
D:\Android\Project\StudyAndroidChapter6_002\app\src\main\res\layout\nationalization.xml:20: error: resource string/ok (aka com.example.studyandroidchapter6_002:string/ok) not found.
D:\Android\Project\StudyAndroidChapter6_002\app\src\main\res\layout\nationalization.xml:24: error: resource string/cancel (aka com.example.studyandroidchapter6_002:string/cancel) not found.
error: failed linking file resources.

解决办法

  右键res/values-en-rUS/strings.xml,点击open translations Editor,填写 默认值,就可以了

上述问题的原因是因为没有配置默认选项,可以直接在values/strings.xml(默认)中添加;添加图片资源也是一样,添加了中美两种资源后还要添加默认值,默认目录为drawable目录,资源名字要和两个资源一样:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值