본문 바로가기

Android

안드로이드 개발/상용 버전에 따른 코드 분류(android debuggable)

로그인이 필요한 앱을 개발하다보면 앱을 삭제 후 다시 설치할 경우 아이디/비번을 계속 일일이 입력해줘야 하

는 불편함이 있었다

C의 경우는 define을 통해 개발자모드일때 로그인처리를 해주는 코드를 넣을수 있었는데 안드로이드도 찾아보

debuggable 이란 속성이 있었다.

기본이 true로 되어있는데 릴리즈 버전을 만들땐 반드시 false로 변경 후 배포를 해야한다.

위의 속성은 Androidmanifest.xml 파일에서 application 속성에 넣어주면 된다,


1
2
3
4
5
<application
    android:name="com.skt.tmap.TmapAppContext"
    android:debuggable="true"
    android:icon="@drawable/tmap_icon"
    android:label="@string/app_name" >

매니페스트에 설정된 debuggable  값이 true 이면 2 를 리턴하고 false 이면 0을 리턴하게 되는데 아래와 같은 

함수를 통해 현재 프로젝트 매니페스트 파일의 디버깅 정보를 가져올수 있다.

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
 * Debug Mode
 */
public static final int DEVELOPMENT_MODE = 2;
/**
 * Release Mode
 */
public static final int RELEASE_MODE = 0;

public static int getCompileMode(Context context)
{
  return (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE);
}

getCompileMode() 함수를 통해 디버깅 모드일경우 와 배포버전일 경우 코드를 분리해주면 된다.