공식문서 탐독하기 : The Manifest File

Skele·2025년 2월 9일
0

안드로이드의 컴포넌트들이 앱의 진입 지점이 될 수 있다는 것을 알았다. 그렇다면 시스템은 어떻게 이런 컴포넌트들을 파악할 수 있는 것일까?

The Manifest File


Before the Android system can start an app component, the system must know that the component exists by reading the app's manifest file, AndroidManifest.xml. Your app declares all its components in this file.

시스템은 앱의 컴포넌트들이 정의된 AndroidManifest.xml를 통해 어떤 컴포넌트들이 존재하는지 알 수 있다.

Declare Components


The primary task of the manifest is to inform the system about the app's components.
You must declare all app components using the following elements:

  • <activity> : elements for activities
  • <service> : elements for services
  • <receiver> : elements for broadcast receivers
  • <provider> : elements for content providers

<application> 안에 앱의 각 컴포넌트들에 대한 정보를 명시해야한다.

Activities, services, and content providers that you include in your source but don't declare in the manifest aren't visible to the system and, consequently, can never run. However, broadcast receivers can either be declared in the manifest or created dynamically in code as BroadcastReceiver objects and registered with the system by calling registerReceiver().

명시하지 않을 경우, 시스템에서 컴포넌트의 존재를 알 수 없고, 따라서 절대 실행 될 수 없다.
하지만 예외적으로 브로드캐스트 리시버의 경우, 런타임에 동적으로 생성하고 시스템에 등록을 할 수 있다.

  • 각 컴포넌트 선언하기
  • 동적으로 브로드캐스트 리시버 생성하기

IntentFilter


You can use an Intent to start activities, services, and broadcast receivers.

Explicit Intent

You do this by explicitly naming the target component, using the component class name, in the intent.

Implicit Intent

You can also use an implicit intent, which describes the type of action to perform and, optionally, the data you want to perform the action on. An implicit intent lets the system find a component on the device that can perform the action and start it. If there are multiple components that can perform the action described by the intent, the user selects which one to use.

Intent 를 통해 컴포넌트를 실행시킬 수 있다는 것을 알고 있을 것이다.

The system identifies the components that can respond to an intent by comparing the intent received to the intent filters provided in the manifest file of other apps on the device.
When you declare an activity in your app's manifest, you can optionally include intent filters that declare the capabilities of the activity so it can respond to intents from other apps. You do this by adding an <intent-filter> element as a child of the component's declaration element.

그리고 각 컴포넌트가 매니페스트 파일에서 어떤 Intent를 받아 실행될 것인지 Intent Filter를 통해 명시할 수 있다.

<manifest ... >
    ...
    <application ... >
        <activity android:name="com.example.project.ComposeEmailActivity">
            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <data android:type="*/*" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Don't declare intent filters for your services.
If you use an intent to start a Service, make sure that your app is secure by using an explicit intent. Using an implicit intent to start a service is a security hazard, because you can't be certain what service responds to the intent and the user can't see which service starts.

다만 서비스의 경우, 백그라운드에서 동작한다는 점 때문에 인텐트 필터를 통한 암시적 인텐트 사용이 제한된다.

  • IntentFilter에는 무엇이 있을까?

Declare App Requirements


The manifest does a number of things in addition to declaring the app's components, such as the following:

  • Identifies any user permissions the app requires, such as internet access or read-access to the user's contacts.
  • Declares the minimum API level required by the app, based on which APIs the app uses.
  • Declares hardware and software features used or required by the app, such as a camera, Bluetooth services, or a multitouch screen.
  • Declares API libraries the app needs to be linked against (other than the Android framework APIs), such as the Google Maps library.

매니페스트 파일은 이외에도 사용자 권한과 앱의 시스템 요구사항 같은 다양한 내용들이 포함되어 있다.

There are a variety of devices powered by Android, and not all of them provide the same features and capabilities. To prevent your app from being installed on devices that lack features needed by your app, it's important that you clearly define a profile for the types of devices your app supports by declaring device and software requirements in your manifest file.
Most of these declarations are informational only. The system doesn't read them, but external services such as Google Play do read them to provide filtering for users when they search for apps from their device.

이러한 내용들은 시스템에서 사용되기 보다는, 설치되는 환경이 적절한지 구글 플레이와 같은 외부 서비스가 확인하는 용도이다.

Don't set minSdkVersion and targetSdkVersion directly in the manifest file, since they are overwritten by Gradle during the build process.

다만 위 문서에서는 최소 API 레벨등의 정보도 들어간다고하지만 이는 개발자가 매니페스트에 직접 작성하는 것이 아닌데, 빌드 시에 Gradle 파일로부터 덮어씌워지기 때문이다. 따라서 Gradle 파일에 작성되어야한다.

android {
  ...
  defaultConfig {
    ...
    minSdkVersion 26
    targetSdkVersion 29
  }
}

App Requirement


<manifest ... >
    <uses-feature android:name="android.hardware.camera.any"
                  android:required="true" />
    ...
</manifest>

With the declarations shown in these examples, devices that do not have a camera or have an Android version lower than 8.0 can't install your app from Google Play. However, you can also declare that your app uses the camera, but does not require it. To do so, you set the required attribute to false, check at runtime whether the device has a camera, and disable any camera features as needed.

앱의 요구사항이 필수적인지 아닌지에 따라 이를 명시하고, 런타임에 확인하는 방법도 존재한다.

profile
Tireless And Restless Debugging In Source : TARDIS

0개의 댓글