Android 11(API 수준 30)에서 Android 12(API 수준 31)로 이전

2022. 11. 25. 01:36Develop/React-Native

평소처럼 안드로이드 빌드를 프로덕션으로 올리는 중이었는데, 번들을 올리니까 아래와 같은 오류가 나타났다

Android 11(API 수준 30)에서 Android 12(API 수준 31)로 이전해야합니다.

처음엔 굉장히 당황했는데 내가 아직 안드로이드를 30수준에서 사용하고있어서 그랬다.

 

일단 android/build.gradle에서 compileSdkVersiontargetSdkVersion을 31로 변경하자.

이후 android/app/src/main/AndroidManifest.xml로 들어간다음 activity를 사용하고있는곳에 아래와 같은 코드를 추가하자

android:exported="false"

단 activity안에 intent-filter를 사용하고있다면 true로 설정해야한다.

android:exported라는 속성은 앱에서 활동, 서비스 또는 수신기에 엑세스 할 수 있으며 외부 응용 프로그램에서 실행 될 수 있는지 정의하는데 사용되는 속성이다. 자세한 설명은 여기를 참조!

31이전엔 자동으로 적용되었으나, 31부터는 명시적으로 작성해 주어야한다.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.test">

<application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="true"
      android:usesCleartextTraffic="true"
      android:theme="@style/AppTheme">
      
	  <!--intent filter 가 있을시 android:exported="true"-->
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <!--filter 내용-->
        </intent-filter>        
      </activity>

       <!--intent filter 가 없을시 android:exported="false"-->
       <activity
        android:name=".SecondActivity"       
        android:exported="false" />     

    </application>
</manifest>

이런식으로 intent-filter가 들어갈 경우 true, 들어가지 않을 경우 false로 지정해주면된다!