brunch

You can make anything
by writing

C.S.Lewis

by 이승현 Jul 06. 2016

Firebase #01

Remote Config

Firebase 프로젝트란?  

Firebase 프로젝트를 통해 플랫폼 간에 사용자, 데이터 및 분석 자료를 공유하여 사용자의 기기와 관계없이 동일한 경험을 제공하고 모든 실적을 한 곳에서 관리할 수 있습니다.


Firebase를 사용하는 모든 앱은 Firebase 프로젝트 하나에 연결됩니다. 프로젝트에서 Firebase 콘솔을 통해 앱의 모든 버전(Android, iOS, 웹)을 관리할 수 있습니다.

https://support.google.com/firebase/answer/6399760?hl=ko&ref_topic=6399725


소규모 회사나 조직이 백앤드까지 개발하기가 쉽진 않습니다.

구글에서는 간단한 백앤드 기능 구현을 Firebase를 통해 제공하고 있습니다.

일부 기능은 유료이지만 백앤드 개발자를 구해서 개발하는 것보다 어찌 보면 더 저렴하네요.




Remote Config

Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to download an app update.

(Firebase Remote Config는 app을 업데이트하기 위한 별도의 다운로드 없이 동작이나 모양을 바꿀 수 있는 클라우드 서비스입니다.)


When using Remote Config, you create in-app default values that control the behavior and appearance of your app. 

(Remote Config를 이용하는 경우, 앱의 동작과 모양을 제어할 수 있는 in-app 기본 값을 생성합니다.)


Then, you can later use the Firebase console to override in-app default values for all app users or for segments of your userbase.

(그런 다음, 나중에 모든 앱 사용자나 사용자 기반의 세그먼트에 대한 in-app 기본값들을 대체하기 위해 Firebase console을 이용할 수 있습니다. )


Your app controls when updates are applied, and it can frequently check for updates and apply them with a negligible impact on performance.

(업데이트들이 적용될 때 앱은 제어하고, 자주 업데이트들을 확인하고 앱 성능에 끼치는 영향이 거의 없이 적용할 수 있습니다.)


https://firebase.google.com/docs/remote-config/

https://www.youtube.com/watch?v=_CXXVFPO6f0&feature=youtu.be&list=PLl-K7zZEsYLmOF_07IayrTntevxtbUxDL




Key functions

Quickly roll out changes to your app's userbase
server-side의 매개변수 값들을 변경해 앱의 기본 동작이나 모양을 바꿀 수 있다.

Customize your app for segments of your userbase
앱 버전, Firebase Analytics 대상, 언어 기반의 다른 세그먼트에 UX 변화를 줄 수 있다.

Run A/B tests to improve your app
전체 사용자를 대상으로 출시하기 전에 개선사항의 유효성을 확인할 수 있도록 임의의 Firebase Analytics 타깃을 대상으로 서로 다른 세그먼트 간 A/B 테스트를 한다.


Policies and limits

Don't use Remote Config to make app updates that should require a user's authorization. This could cause your app to be perceived as untrustworthy.
(사용자의 권한을 요구하도록 업데이트 하는데 이용하지 마라. 신뢰감을 잃게할 수 도 있다.)

Don't store confidential data in Remote Config parameter keys or parameter values. It is possible to decode any parameter keys or values stored in the Remote Config settings for your project.
(기밀 데이터를 Remote Config의 파라미터 키나 값에 저장하지 마라. 프로젝트를 설정하기 위한 Remote Config에 저장된 키와 값을 디코딩할 수도 있기 때문이다.)

Don't attempt to circumvent the requirements of your app's target platform using Remote Config.
(Remote Config를 이용하여 앱의 타깃 플랫폼의 요구사항을 회피하도록 시도하지 마라.)




Firebase 시작


아래 firebase console 사이트에 가입 후, 프로젝트를 생성합니다.

https://console.firebase.google.com/


#01 새 프로젝트 만들기
#02 프로젝트 만들기 - 이름, 국가/지역
#03 Android 앱에 Firebase 추가
#04 앱 세부정보(패키지 이름, SHA-1) 입력


SHA-1은 아래 stackoverflow 방식대로 얻어서 입력합니다.

http://stackoverflow.com/questions/27609442/how-to-get-the-sha1-fingerprint-certificate-in-android-studio-for-debug-mode



#05 구성 파일(google-services.jason) 복사
#06 build.gradle에 추가
#07 Done


"#05 구성 파일(google-services.jason) 복사"에서 "google-service.jason" 파일을 받지만 별도로 다시 받을 수 있습니다.


프로젝트 설정 - google-services.json 다운




Remote Config 시작



https://support.google.com/firebase/answer/6386651

#01 첫 번째 매개변수 추가


매개변수는 key-value 쌍으로 이루어진 변수입니다.

key는 고윳값으로 String으로 구성되고, value는 boolean, byte array, double, long, String을 이용할 수 있습니다.


Limits on parameters and conditions

Within a Firebase project, you can have up to 2000 parameters, and up to 100 conditions. Parameter keys can be up to 256 characters long. The total length of parameter value strings within a project cannot exceed 500,000 characters.
(Firebase 프로젝트에서 2000개의 매개변수와 최대 100개의 조건까지 가질 수 있습니다. 매개변수의 키는 256자까지 입력이 가능합니다. 매개변수 값은 500,000 자를 넘지 못합니다.)


#02 변경사항 게시

https://firebase.google.com/docs/remote-config/use-config-android


1. google-service.json 추가

#01 구성 파일 복사

Android studio에서 프로젝트 보기로 전환하여 프로젝트 루트 디렉터리를 표시하세요.

다운로드한 google-service.json 파일을 Android 앱 모듈 루트 디렉터리로 이동하세요.


2. plugin 추가

#02 Project build.gradle에 추가
buildscript {
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:3.0.0'
    }
}
#03 app build.gradle에 추가
apply plugin: 'com.android.application'

...

dependencies {
    ...
    compile 'com.google.firebase:firebase-core:9.2.0'
    compile 'com.google.firebase:firebase-config:9.2.0'
}

apply plugin: 'com.google.gms.google-services'

"firebase-core:9.2.0" 이 컴파일되지 않을 때는 아래와 같이 Google Play service 31 버전으로 업데이트해주세요.


#04 Google Play service v31


3. Remote Config Object 생성, Default parameter value 설정

#05 Remote Config Object, Default parameter value

Remote Config Object 생성

mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();

Remote Config Setting 설정

FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
      .setDeveloperModeEnabled(true)
      .build();
mFirebaseRemoteConfig.setConfigSettings(configSettings);

Default parameter value 설정 (Map이 아닌 XML resource file도 지원합니다.)

Map<String, Object> map = new HashMap<>();
map.put(FB_REMOTE_CONFIG_STRING, "default");
map.put(FB_REMOTE_CONFIG_BOOLEAN, false);
map.put(FB_REMOTE_CONFIG_BYTE_ARRAY, new byte[0]);
map.put(FB_REMOTE_CONFIG_DOUBLE, 0.0);
map.put(FB_REMOTE_CONFIG_LONG, 555);
map.put(FB_REMOTE_CONFIG_COLOR, "#000000");
mFirebaseRemoteConfig.setDefaults(map);


3. Fetch

#06 Fetch

fetch() 함수를 통해 Remote Config 서버로부터 매개변수들 가져옵니다.

private final long CACHE_EXPIRATION = 0;

mFirebaseRemoteConfig.fetch(CACHE_EXPIRATION);

addOnCompleteListener, addOnFailureListener 리스너 추가

mFirebaseRemoteConfig.fetch(CACHE_EXPIRATION).addOnCompleteListener(new OnCompleteListener<Void>() {
   @Override
   public void onComplete(@NonNull Task<Void> task) {

   }
}).addOnFailureListener(new OnFailureListener() {
   @Override
   public void onFailure(@NonNull Exception e) {

   }
});

가져온 키 - 값이 적용되도록 fetched config를 활성화

if (task.isSuccessful()) {
   mFirebaseRemoteConfig.activateFetched();
}

Remote Config 매개변수 호출

String str = mFirebaseRemoteConfig.getString(FB_REMOTE_CONFIG_STRING);
boolean b = mFirebaseRemoteConfig.getBoolean(FB_REMOTE_CONFIG_BOOLEAN);
byte [] arrBytes = mFirebaseRemoteConfig.getByteArray(FB_REMOTE_CONFIG_BYTE_ARRAY);
double d = mFirebaseRemoteConfig.getDouble(FB_REMOTE_CONFIG_DOUBLE);
long l = mFirebaseRemoteConfig.getLong(FB_REMOTE_CONFIG_LONG);
int color = Color.parseColor(mFirebaseRemoteConfig.getString(FB_REMOTE_CONFIG_COLOR));




조건 추가


매개변수를 추가한 후 또는 매개변수를 추가하거나 수정할 때 조건을 추가하거나 수정할 수 있습니다.

https://support.google.com/firebase/answer/6386651

#01 매개변수 클릭
#02 조건 값 추가
#03 새 조건 정의
#04 이름, 적용 조건, 색상 정의
#05 조건의 값 정의
#06 조건 추가
#07 CONDITION




Sample


https://firebase.google.com/docs/remote-config/android#how_it_works


https://github.com/oemilk/firebase






작가의 이전글 안드로이드 개발자 이직
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari