2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
네이티브 라이브러리의 네임스페이스
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Android 7.0에는 앱에서 실수로 자체 라이브러리 대신 플랫폼 라이브러리를 사용하게 되었을 때 네이티브 라이브러리에서 내부 API 가시성을 제한하고 상황을 해결할 수 있도록 하기 위한 네임스페이스가 도입되었습니다. 애플리케이션 관련 변경사항은 Android 개발자 블로그 게시물, Android 7.0의 비공개 C/C++ 기호 제한을 통한 안정성 개선을 참조하세요.
아키텍처
Android 7.0 이상에서는 시스템 라이브러리가 앱 라이브러리와 구분됩니다.
그림 1. 네이티브 라이브러리의 네임스페이스
네이티브 라이브러리의 네임스페이스는 OpenSSL의 경우처럼 앱이 비공개 플랫폼 네이티브 API를 사용하지 못하게 합니다. 또한 libpng
에서 볼 수 있는 것처럼 앱이 실수로 자체 라이브러리 대신 플랫폼 라이브러리를 사용하게 되는 상황을 없앱니다. 즉, 앱 라이브러리가 실수로 시스템 라이브러리를 사용하는 경우나 그 반대의 경우가 발생하기 어려워집니다.
부가적인 네이티브 라이브러리 추가
표준 공개 네이티브 라이브러리 외에도 실리콘 공급업체(Android 7.0부터) 및 기기 제조업체(Android 9부터)는 원하는 경우 앱에서 액세스 가능한 추가적인 네이티브 라이브러리를 제공할 수 있으며, 이를 위해 네이티브 라이브러리를 각각의 라이브러리 폴더 아래에 배치하고 이를 .txt 파일에 명시적으로 나열합니다.
라이브러리 폴더는 다음과 같습니다.
- 실리콘 공급업체의 라이브러리를 위한
/vendor/lib
(32비트용)과 /vendor/lib64
(64비트용)
- 기기 제조업체의 라이브러리를 위한
/system/lib
(32비트용)과 /system/lib64
(64비트용)
.txt 파일은 다음과 같습니다.
- 실리콘 공급업체의 라이브러리를 위한
/vendor/etc/public.libraries.txt
- 기기 제조업체의 라이브러리를 위한
/system/etc/public.libraries-COMPANYNAME.txt
. 여기서 COMPANYNAME
은 제조업체 이름을 나타냅니다(예: awesome.company
). COMPANYNAME
은 [A-Za-z0-9_.-]+
, 즉 영숫자 문자, _, .(점), -와 일치해야 합니다. 일부 라이브러리가 외부 솔루션 제공업체의 라이브러리라면 기기에 이러한 .txt 파일이 여러 개 있을 수 있습니다.
기기 제조업체에서 공개한 system
파티션의 네이티브 라이브러리 이름은 lib*COMPANYNAME.so
로 지정해야 합니다(예: libFoo.awesome.company.so
).
즉, 회사 이름 접미사가 없는 libFoo.so
는 공개하면 안 됩니다.
라이브러리 파일 이름의 COMPANYNAME
은 라이브러리 이름이 나열되는 txt 파일 이름의 COMPANYNAME
과 일치해야 합니다.
AOSP의 일부인 네이티브 라이브러리는 공개해서는 안 됩니다(기본적으로 공개인 표준 공개 네이티브 라이브러리는 예외). 실리콘 공급업체 또는 기기 제조업체에서 추가한 라이브러리만 앱에서 액세스할 수 있습니다.
Android 8.0부터는 공급업체 공개 라이브러리에 다음과 같은 추가적인 제한사항 및 필수 설정이 적용됩니다.
- 앱에서 액세스할 수 있도록 공급업체의 네이티브 라이브러리 라벨을 제대로 지정해야 합니다. 서드 파티 앱을 비롯하여 앱에서 액세스가 필요하면 라이브러리는 다음과 같이 공급업체별
file_contexts
파일에서 same_process_hal_file
로 라벨이 지정되어야 합니다. /vendor/lib(64)?/libnative.so u:object_r:same_process_hal_file:s0
여기서 libnative.so
는 네이티브 라이브러리의 이름입니다.
- 라이브러리는 VNDK-SP 및 LLNDK 라이브러리 이외의 시스템 라이브러리에 종속 항목을 통해 직접적으로 또는 간접적으로 종속되면 안 됩니다. VNDK-SP 및 LLNDK 라이브러리 목록은
development/vndk/tools/definition/tool/datasets/eligible-list-<version>-release.csv
에서 확인할 수 있습니다.
비공개 네이티브 라이브러리를 사용하지 않도록 앱을 업데이트
이 기능은 SDK 버전 24 이상을 타겟팅하는 애플리케이션에만 이전 버전과의 호환성을 위해 사용 설정됩니다. 표 1. 앱이 비공개 네이티브 라이브러리에 링크된 경우 예상 결과를 참조하세요.
앱에서 액세스 가능한 Android 네이티브 라이브러리(공개 네이티브 라이브러리라고도 알려짐) 목록은 CDD 섹션 3.1.1에 나열되어 있습니다. 24 이상을 타겟팅하고 비공개 라이브러리를 사용하는 앱을 업데이트해야 합니다. 자세한 내용은 플랫폼 라이브러리에 연결되는 NDK 앱을 참조하세요.
네이티브 라이브러리 종속 항목을 지정하도록 앱을 업데이트
SDK 버전 31(Android 12) 이상을 타겟팅하는 애플리케이션은 앱 매니페스트에서 <uses-native-library>
태그를 사용하여 네이티브 공유 라이브러리 종속 항목을 명시적으로 지정해야 합니다. 요청된 라이브러리의 일부라도 기기에 존재하지 않으면 앱이 설치되지 않습니다. 앱이 설치되면 앱에서 요청한 네이티브 공유 라이브러리만 제공됩니다. 즉, 앱 매니페스트에 나타나지 않는 네이티브 공유 라이브러리에는 액세스할 수 없습니다.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2024-04-26(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-04-26(UTC)"],[],[],null,["# Namespaces for native libraries\n\nAndroid 7.0 introduced namespaces for native libraries to limit internal API\nvisibility and resolve situations where apps accidentally use platform\nlibraries instead of their own. See the [Improving\nStability with Private C/C++ Symbol Restrictions in Android 7.0](http://android-developers.blogspot.com/2016/06/improving-stability-with-private-cc.html) Android\nDevelopers blog post for app-specific changes.\n\nArchitecture\n------------\n\n\nIn Android 7.0 and higher, system libraries are separated from app libraries.\n\n\n**Figure 1.** Namespaces for native libraries.\n\n\nNamespaces for native libraries prevent apps from using private-platform native\nAPIs (as was done with OpenSSL). It also removes situations where apps\naccidentally use platform libraries instead of their own (as witnessed\nwith `libpng`). It's difficult for app libraries to use internal\nsystem libraries by accident (and vice versa).\n\nAdd additional native libraries\n-------------------------------\n\n\nIn addition to standard public native libraries, silicon vendors (starting from Android 7.0) and\ndevice manufacturers (starting from Android 9) may choose to provide additional native libraries\naccessible to apps by putting them under the respective library folders and explicitly listing them\nin .txt files.\n\nThe library folders are:\n\n- `/vendor/lib` (for 32-bit) and `/vendor/lib64` (for 64-bit) for libraries from silicon vendors\n- `/system/lib` (for 32-bit) and `/system/lib64` (for 64-bit) for libraries from device manufacturers\n\nThe .txt files are:\n\n- `/vendor/etc/public.libraries.txt` for libraries from silicon vendors\n- `/system/etc/public.libraries-COMPANYNAME.txt` for libraries from device manufacturers, where `COMPANYNAME` refers to a name of the manufacturer (such as `awesome.company`). `COMPANYNAME` must match with `[A-Za-z0-9_.-]+`; alphanumeric characters, _, . (dot) and -. It is possible to have multiple such .txt files in a device if some libraries are from external solution providers.\n\n\nNative libraries in the `system` partition that are made public by device manufacturers\n**MUST** be named `lib*COMPANYNAME.so`, for example, `libFoo.awesome.company.so`.\nIn other words, `libFoo.so` without the company name suffix MUST NOT be made public.\nThe `COMPANYNAME` in the library file name MUST match with the `COMPANYNAME` in the\ntxt file name in which the library name is listed.\n\n\nNative libraries that are part of AOSP MUST NOT be made public (except the standard\npublic native libraries which are public by default). Only the additional libraries added by\nsilicon vendors or device manufacturers can be made accessible to apps.\n\n\nStarting from Android 8.0, vendor public libraries have the following additional\nrestrictions and required setups:\n\n1. The native library in vendor must be properly labeled so it can be accessible to apps. If access is required by any apps (including third party apps), the library must be labeled as `same_process_hal_file` in a vendor-specific `file_contexts` file as follows: \n\n ```\n /vendor/lib(64)?/libnative.so u:object_r:same_process_hal_file:s0\n ```\n where `libnative.so` is the name of the native library.\n2. The library, either directly or transitively through its dependencies, must not depend on system libraries other than VNDK-SP and LLNDK libraries. Locate the list of VNDK-SP and LLNDK libraries at `development/vndk/tools/definition/tool/datasets/eligible-list-\u003cversion\u003e-release.csv`.\n\n\nStarting from Android 15, vendor public libraries can be put in a\n[vendor APEX](/docs/core/ota/vendor-apex). When packaged in a vendor APEX, list the libraries\nin a `provideNativeLibs` property in the APEX manifest.\n\nUpdate apps to not use nonpublic native libraries\n-------------------------------------------------\n\n\nThis feature is enabled only for apps targeting SDK version 24 or later;\nfor backward compatibility, see [Table\n1. What to expect if your app is linking against private native libraries](http://android-developers.blogspot.com/2016/06/improving-stability-with-private-cc.html).\nThe list of Android native libraries accessible to apps (also know as\npublic native libraries) is listed in CDD section 3.1.1. Apps targeting 24 or\nlater and using any non-public libraries should be updated. See [NDK\nApps Linking to Platform Libraries](https://developer.android.com/about/versions/nougat/android-7.0-changes.html#ndk) for more details.\n\nUpdate apps for their native library dependencies\n-------------------------------------------------\n\nApps that target SDK version 31 (Android 12) or higher must\n*explicitly specify* their native shared library dependencies by using the\n`\u003cuses-native-library\u003e` tag in the app manifest. If any part of the requested\nlibrary doesn't exist on the device, the app isn't installed. When the apps are installed, they're\nprovided with *only* the native shared libraries that they've requested. This means that\napps can't access native shared libraries that don't appear in the app manifest."]]