투케이2K

125. (TWOK/ERROR) [Android] 빌드 에러 - [target 31/타겟 31] Manifest merger failed android:exported needs 본문

투케이2K 에러관리

125. (TWOK/ERROR) [Android] 빌드 에러 - [target 31/타겟 31] Manifest merger failed android:exported needs

투케이2K 2022. 11. 24. 13:28
반응형

[환경 설정 및 설명]

프로그램 : AndroidStudio

설 명 : 빌드 에러 - [target 31/타겟 31] Manifest merger failed android:exported needs to be explicitly specified for <receiver>. Apps targeting Android 12 ...

 

[에러 원인]

1. 안드로이드 정책 사항으로 target 타겟 버전 31 이상 android:exported 속성 명시적 선언 필요 이슈

Manifest merger failed : android:exported needs to be explicitly specified for <receiver>. 
Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. 
See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

 

// TODO [애플리케이션 빌드 설정 지정 실시]
android {
    // TODO [컴파일 버전]
    compileSdk 31

    // [Config 셋팅]
    defaultConfig {
        // ----------------------------
        applicationId "com.app.manager" // 앱 아이디
        // ----------------------------
        minSdk 21 // 최소 빌드 버전
        // ----------------------------
        targetSdk 31 // TODO 타겟 빌드 버전
        // ----------------------------
        versionCode 1 // TODO 앱 버전 코드 [마켓 관리]
        // ----------------------------
        versionName "1.0.0" // TODO 앱 버전 이름 [마켓 관리]
        // ----------------------------
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        // ----------------------------
    }

    // [빌드 설정]
    buildTypes {
        /*
        debug {
            minifyEnabled false // [true 프로가드 사용 / false 프로가드 사용안함]
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' // [프로가드 설정 파일 지정]
        }
        // */
        release {
            minifyEnabled false // [true 프로가드 사용 / false 프로가드 사용안함]
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' // [프로가드 설정 파일 지정]
        }
    }

    // [컴파일 자바 버전 지정]
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    // [아파치 http 사용 설정]
    useLibrary ('org.apache.http.legacy')
}
 

[해결 방법]

1. AndroidManifest.xml 파일에서 모든 Activity , receiver , service 에 android:exported 명시 수행

<!-- [배터리 잔량 및 충전 이벤트 확인 액티비티] -->
<activity
	android:name=".A_Battery"
	android:screenOrientation="portrait"
	android:windowSoftInputMode="adjustPan"/>



<!-- [배터리 잔량 및 충전 이벤트 확인 리시버] -->
<receiver
	android:name=".A_BatteryReceiver"
	android:enabled="true"
	android:exported="true">
	<intent-filter>
		<action android:name="android.intent.action.ACTION_POWER_CONNECTED"/>
		<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED"/>
	</intent-filter>
</receiver>



<!-- 파이어베이스 푸시 서비스 -->
<service
	android:name=".C_FirebaseMessagingService"
	android:enabled="true"
	android:exported="true">
	<intent-filter>
		<action android:name="com.google.firebase.MESSAGING_EVENT"/>
	</intent-filter>
</service>

2. build.gradle 빌드 그래들 파일에서 dependencies 의존성 부여 확인 (androidx)

// TODO [라이브러리 의존성 부여 실시]
dependencies {

    // -----------------------------------------------------------

    // [안드로이드 X 관련 의존성 부여 실시]

    //implementation 'androidx.appcompat:appcompat:1.3.0' // TODO [컴파일, 빌드 타켓 30 인 경우]
    //implementation 'com.google.android.material:material:1.4.0' // TODO [컴파일, 빌드 타겟 30 인 경우]
    //implementation 'androidx.constraintlayout:constraintlayout:2.1.2' // TODO [컴파일, 빌드 타겟 30 인 경우]


    implementation 'androidx.appcompat:appcompat:1.4.1' // TODO [컴파일, 빌드 타겟 31 인 경우]
    implementation 'com.google.android.material:material:1.5.0' // TODO [컴파일, 빌드 타겟 31 인 경우]
    implementation 'androidx.constraintlayout:constraintlayout:2.1.3' // TODO [컴파일, 빌드 타겟 31 인 경우]


    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    // -----------------------------------------------------------

    // [코틀린 호환성 추가]
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    // -----------------------------------------------------------

}

3. build.gradle 빌드 그래들 파일에서 라이브러리 버전 확인

- 라이브러리 버전이 target 31 버전과 호환되지 않는 경우 [Manifest merger failed android:exported needs to be explicitly] 에러가 발생

    // -----------------------------------------------------------

    // [altbeacon : 비콘 스캔 및 신호 활성 라이브러리]

    //implementation 'org.altbeacon:android-beacon-library:2.9.2' // [target 31 미만 하위 버전]
    implementation 'org.altbeacon:android-beacon-library:2.+' // [target 31 이상 상위 버전]
    //noinspection GradleCompatible
    implementation 'com.android.support:localbroadcastmanager:28.0.0'

    // -----------------------------------------------------------
 

 
반응형
Comments