1. 프로젝트 생성
Android Studio를 열어서 기본 프로젝트를 만든다.
2. GCM에 프로젝트를 등록한다.
1) https://developers.google.com/cloud-messaging/ 접속
2) TRY IT ON ANDROID 클릭
3) add Cloud Messaging to your existing app 를 클릭
4) 화면을 아래로 내려서 중간 정도에 있는 GET A CONFIGURATION FILE 클릭
5) App Name, Android Package name 입력한 다음 Choose and configure services 를 클릭
('Your country/region' 선택상황이 나오면 '대한민국'으로 선택한다)
6) 조금기다리면 설정한 앱이 등록된것을 확인할수 있다.
앱이 등록하면 Google Sigin-in, Cloud Messaging, Analytics 서비스를 사용할 수 있다.
Google Cloud Messaging 탭에서 ENABLE GOOGLE CLOUD MESSAGING 버튼을 클릭.
이 버튼을 눌러줘야 GCM 서비스가 활성화 된다.
7) Server API Key 와 Sender ID 를 따로 저장해 놓고 아래 Generate configuration files 를 클릭한다.
8) Download google-services.json 을 클릭하여 설정파일을 다운로드 받는다.
9) Android 프로젝트 디렉토리 안에 app/ 디렉토리안에 google-services.json 파일을 복사한다.(CTRL+C, CTRL+V)
이 파일이 /app 디렉토리안에 들어있지 않으면 GCM 프로젝트를 빌드할때
R.string.gcm_defaultSenderId 리소스를 찾을 수 없다는 에러가 발생한다.
10) google-services.json 을 열어보면
Project ID와 Project Number가 자동으로 만들어진 것을 확인할 수 있다.
11) build.gradle(Module: app) 파일을 열어서 apply plugin, classpath 추가
apply plugin: 'com.google.gms.google-services'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.android.support:design:23.2.1'
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.rock.opregcheck"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile 'com.android.support:design:23.2.1'
}
댓글 없음 :
댓글 쓰기