IT Share you

Android에서 res / values ​​/ public.xml 파일의 용도는 무엇입니까?

shareyou 2021. 1. 7. 19:56
반응형

Android에서 res / values ​​/ public.xml 파일의 용도는 무엇입니까?


Google에서 검색했지만 관련 결과를 찾을 수 없습니다.

또한 점검 공식 안드로이드 문서페이지 (사용 가능한 모든 자원을) 내가 찾을 수있는 모든했다. 관련 링크 (받는 res/values/디렉토리) 나는이 페이지에서 찾았습니다

이 페이지는 res/values/public.xml파일 에 대해 아무것도 알려주지 않습니다 .
다음은 이러한 유형의 파일에 대해 찾은 입니다.

작은 스 니펫

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <public type="attr" name="commentTextColor" id="0xAA010007" />
    <public type="drawable" name="add_icon_bl" id="0xAA020000" />
    <public type="layout" name="act_date_picker" id="0xAA030001" />
    <public type="anim" name="activity_slide_from_bottom" id="0xAA040000" />
    <public type="xml" name="pref_menu" id="0xAA050000" />
    <public type="raw" name="alert_bell_animation_bl" id="0xAA060000" />
    <public type="array" name="taskRepeat" id="0xAA070000" />
    <public type="color" name="theme_main_color_bl" id="0xAA080000" />
    <public type="string" name="no_internet" id="0xAA0a0001" />
    <public type="id" name="page1" id="0xAA0d0015" />
</resources>

type속성 에서 볼 수 있듯이 일반적으로 디렉토리 아래 별도의 디렉토리넣는 거의 모든 표준 리소스 유형 을 포함합니다 .res


Android가 제공하는 디렉토리를 오용하고 단일 파일을 사용하여 모든 값을 저장하는 이유는 무엇입니까? 누군가 이것에 대해 더 많은 정보를 줄 수 있습니까?


res / values ​​/ public.xml 파일 은 Android 리소스에 고정 리소스 ID를 할당하는 데 사용됩니다.

res / values ​​/ strings.xml 에서 다음 문자열 리소스 세트를 고려하십시오 .

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="string1">String 1</string>
    <string name="string3">String 3</string>
</resources>

Android Asset Packaging Tool (aapt)은 앱이 컴파일 될 때 이러한 리소스에 대해 다음 리소스 ID를 할당 할 수 있습니다.

public final class R {
    // ...
    public static final class string {
        public static final int string1=0x7f040000;
        public static final int string3=0x7f040001;
    }
}

이제 문자열 리소스 세트를

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="string1">String 1</string>
    <string name="string2">String 2</string>
    <string name="string3">String 3</string>
</resources>

and you'll notice that the resource ID for @string/string3 has changed:

public final class R {
    // ...
    public static final class string {
        public static final int string1=0x7f040000;
        public static final int string2=0x7f040001;
        public static final int string3=0x7f040002; // New ID! Was 0x7f040001
    }
}

To prevent this, you can use res/values/public.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <public type="string" name="string3" id="0x7f040001" />
</resources>

which will result in the resource IDs being assigned as follows:

public final class R {
    // ...
    public static final class string {
        public static final int string1=0x7f040000;
        public static final int string2=0x7f040002;
        public static final int string3=0x7f040001; // Resource ID from public.xml
    }
}

Applications rarely have any use for res/values/public.xml since the resource IDs assigned to resources does not matter. When they change, the entire application is rebuilt anyway so any references in Java code to resources by resource ID will be updated.

The most significant user of res/values/public.xml is the Android platform itself. Applications built against old versions of Android assumes that certain resource have a certain resource ID. For example, the Android resource @android:style/Theme must always have the resource ID 0x01030005 for the platform to be backwards compatible with apps built against old versions of the platform.

If you are curious about more details on how resource IDs are assigned, please refer to this answer: How does the mapping between android resources and resources ID work?


https://developer.android.com/studio/projects/android-library.html#PrivateResources

public.xml is useful for library projects in general. If you include a public.xml, it's assumed that the rest of your resources are meant to be private.

Although private resources will still be usable by other projects, the linter will warn about using them, and they won't be included in AndroidStudio's autocompletion.

Here's a gist for autogenerating public.xml https://gist.github.com/HannahMitt/99922d4183bdb03356fd339413ba6303


Is it not a file just for the use authors of the OS code to define a mapping between symbolic names and system resource ids?

You'll find it in your SDK at YOUR_SDK_LOCATION\platforms\android-??\data\res\values.

It's headed

This file defines the base public resources exported by the platform, which must always exist

and has the caveat:

IMPORTANT NOTE FOR ANYONE MODIFYING THIS FILE READ THIS BEFORE YOU MAKE ANY CHANGES

This file defines the binary compatibility for resources. As such, you must be very careful when making changes here, or you will completely break backwards compatibility with old applications

It has entries such as

<public type="attr" name="smallScreens" id="0x01010284" />
<public type="attr" name="normalScreens" id="0x01010285" />
<public type="attr" name="largeScreens" id="0x01010286" />

in it - all system resurce ids, so anyone changing entries will break their code, insomuch as it won't run on a standard device.

ReferenceURL : https://stackoverflow.com/questions/9348614/what-is-the-use-of-the-res-values-public-xml-file-on-android

반응형