'targetSdkVersion 31'에 해당되는 글 1건

728x90

세부사항은 https://developer.android.com/about/versions/12/behavior-changes-12?hl=ko

 

동작 변경사항: Android 12를 타겟팅하는 앱  |  Android Developers

모든 앱에 영향을 주는 Android 12의 변경사항을 알아봅니다.

developer.android.com

를 읽어보면 된다.

 

앱이 Android 12 이상을 타겟팅하고 인텐트 필터를 사용하는 활동이나 서비스, broadcast receiver를 포함하면 이러한 앱 구성요소의 android:exported 속성을 명시적으로 선언해야 한다.

<service android:name="com.example.app.backgroundService"
         android:exported="false">
    <intent-filter>
        <action android:name="com.example.app.START_BACKGROUND" />
    </intent-filter>
</service>

 

android:exported
- 앱의 활동에 인텐트 필터가 포함되면 다른 앱에서 Activity를 시작할 수 있도록 이 요소를 'true'로 설정해야 한다.
- 모든 앱에서 Activity에 액세스할 수 있으며 정확한 클래스 이름으로 활동을 시작할 수 있다.
- 인텐트 필터가 없는 경우의 기본값은 false 이다.
- 같은 애플리케이션의 구성요소나 사용자 ID가 같은 애플리케이션, 권한있는 시스템 구성요소에서만 시작될 수 있다.

 

앱 build.gradle

apply plugin: 'com.android.application'
 
android {
    compileSdkVersion 31
    defaultConfig {
        applicationId "com.spectrum.android.ping"
        minSdkVersion 23
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
 
dependencies {
    implementation project(':lib')
}

 

오래된 앱을 targetSdkVersion 31 로 업데이트하면 아래와 같은 에러가 발생한다.

 

아래와 같이 수정되면 OK

Android 10 이라도 targetSdkVersion 31로 하면 android:exported="true" 설정해야 동작된다.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.spectrum.android.ping">
 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        >
        <activity android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>
 

 

블로그 이미지

Link2Me

,