-
[Android] Kotlin DSL, gradle.kts 사용시 Manifest에서 local.properties 사용하기안드로이드 2024. 3. 21. 10:49
*카카오 Native app key를 사용하는 것을 기준으로 작성되어있습니다.
모듈 build.gradle.kts
android { namespace = "~" compileSdk = 33 defaultConfig { // ... // 로컬 프로퍼티 사용 부분 val localProperties = Properties() val localPropertiesFile = rootProject.file("local.properties") if (localPropertiesFile.exists()) { localProperties.load(localPropertiesFile.inputStream()) } val nativeAppKey = localProperties.getProperty("kakao_app_key") ?: "" // 매니페스트 플레이스홀더 설정 manifestPlaceholders["NATIVE_APP_KEY"] = nativeAppKey // 코드 상에서 local.properties 변수 사용 buildConfigField("String", "KAKAO_NATIVE_APP_KEY", getProperty("kakao_app_key")) } buildTypes { //... } compileOptions { //... } kotlinOptions { //... } buildFeatures{ //... } }
해당 모듈의 AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application> <activity android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity" android:exported="true"> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <!-- Redirect URI: "kakao${NATIVE_APP_KEY}://oauth" --> <data android:host="oauth" android:scheme="kakao${NATIVE_APP_KEY}" /> </intent-filter> </activity> <!-- 그 외 엑티비티 선언 -- > </application> </manifest>