안녕하세요! 안드로이드 개발을 하다보면 앱 배포 이전에 테스트를 하기 위해 debug용으로 앱을 따로 추출하여 사용하는 경우가 많습니다. 저 같은 경우 debug용 빌드를 위해 패키지명이라던가 앱이름을 하나하나 수정한 뒤에 따로 apk를 추출했었습니다. 하지만 이는 추후 실제 release 앱을 배포할 때 소스코드를 원래대로 돌려놓아야하기 때문에 여간 귀찮은 일이 아닙니다..😢
그래서 오늘은 소스코드 수정없이 debug와 release용 앱을 분리하는 방법에 대해 알아보도록 하겠습니다.
패키지명 분리
Gradle에서 debug와 release용에 맞는 앱 이름을 각각 따로 설정하실 수 있으며,
applicationIdSuffix를 이용하면 패키지명을 직접 바꿀 필요없이 debug용으로 빌드할때 자동으로 기존 패키지명에 .dev를 추가한 새로운 패키지명으로 빌드됩니다!
buildTypes {
release {
...
manifestPlaceholders = [appName: "@string/app_name"]
...
}
debug {
applicationIdSuffix ".dev"
manifestPlaceholders = [appName: "@string/test_app_name"]
}
}
앱이름 설정
위 Gradle 설정을 통해 debug/release용 앱 이름을 각각 설정하셨다면 그 다음은 매니페스트 파일을 수정해주시면 됩니다.
제가 구글링 통해 찾아본 자료들에서는 메인되는 액티비티에도 설정을 해줘야한다고 되어있었는데,
일단은 따로 하지않아도 동작하는 것을 확인했습니다.
(저와 다르게 문제가 발생하신 분은 댓글로 적어주시면 감사하겠습니다🙇)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="${appName}"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.VemoPlus"
android:usesCleartextTraffic="false"
tools:replace="android:label">
<!-- Setting Activity -->
<activity
android:name=".activities.SplashActivity"
android:label="${appName}">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
소스코드 분리
만약 운영하는 서버에 테스트용이 따로 있으시다면, 아래와 같이 BuildConfig.DEBUG 를 이용하여
빌드된 앱이 debug용인지 release용인지 판단하여 그에 맞게 코드를 수정하시면 되겠습니다!
if(!BuildConfig.DEBUG) {
mBaseUrl = URL;
} else {
mBaseUrl = TEST_URL;
}
참고
https://lasselindh.tistory.com/1
[안드로이드/Android] 소스코드 수정없이 개발/운영 패키지, 앱이름, 옵션 분리하기
안드로이드 앱을 개발하다보면 운영(Real)앱과 개발(Test)앱을 분리하여 관리해야될 때가 있다.스튜디오의 경우 패키지명만 변경하면 다른 어플리케이션으로 인식하여 개발앱과 운영앱을 동시에
lasselindh.tistory.com
'Android' 카테고리의 다른 글
[안드로이드 / Kotlin] Moshi (2) | 2022.09.30 |
---|---|
[안드로이드 / Kotlin] Clean Architecture 개념 (0) | 2022.09.18 |
[안드로이드 / Kotlin] Status bar 투명하게 (with DrawerLayout) (0) | 2022.05.18 |
[안드로이드 / Kotlin] Dagger Hilt (0) | 2022.05.17 |
[안드로이드 / Kotlin] Room (0) | 2022.04.27 |