-
[FIREBASE] 파이어베이스 개발환경 구축하기2@챈챈/#Other 2020. 1. 17. 10:37
안드로이드 스튜디오에 파이어베이스를 연동해보겠습니다.
개발 환경
안드로이드 OS : API 16(젤리빈) 이상
Gradle 버전 : 4.1 이상
Android Studio : 2.2 이상
제가 사용하는 버전은 3.5.2입니다.
+Start a new Android Studio project를 클릭해서 새 프로젝트를 만들어봅시다.
꼭 확인해야 할 것 : Minimum API level.(API 16 이상)
안드로이드 프로젝트가 만들어진 화면입니다.
1. Firebase Assistant로 생성한 안드로이드 프로젝트를 추가하는 방법
[Tool]-[Firebase]를 클릭합니다.
그러면 화면 레이아웃에 다음과 같은 Window가 자리를 차지하게 됩니다.
여기서 우리는 'Analytics'를 클릭합니다.
그리고 나오는 'Log an Analytics event'를 클릭합니다.
'Connet to Firebase'를 클릭합니다. 그럼 새 창이 뜨면서 구글에 로그인 하도록 유도합니다.
로그인이 완료되었다면 다시 안드로이드 스튜디오로 돌아옵니다.
이전에는 보지 못했던 Connect to Firebase Window가 보일겁니다.
이 Window는 신규 프로젝트를 생성할 수도 있고 구글 계정에 등록되어 있는 파이어베이스 프로젝트 리스트를 가져와 기존 프로젝트에 안드로이드 프로젝트를 등록하도록 선택할 수 있습니다.
Connect to Firebase를 클릭하면 위와 같이 초록색 계열의 Connected라는 글자를 볼 수 있습니다.
그 후에 밑에 있는 Add Anlytics to your app 버튼을 누르면 다음과 같은 창이 나옵니다.
여기서 Accept Changes를 눌러줍니다.
그러면 우리는 몇가지 추가된 gradle을 확인할 수 있습니다.
1. Gradle Scripts/build.gradle(Project:Firebase)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2. Gradle Scripts/build.gradle(Module: app)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.firebase"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-core:17.2.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.1'
}
수정해야 할 부분이 있는데, firebase-core에서 버전을 최신으로 바꿔줘야 합니다.
저는 16.0.4에서 최신인 17.2.1로 바꿨습니다. 이건 마우스를 올려보면 나옵니다.
그리고 다른 버전 관련된 숫자도 최신 숫자가 있다면 바꿔주세요.
빌드해봅시다.
오류 없이 동작되는 것을 확인할 수 있습니다.
-다른 소스는 전혀 건들지 않았습니다-
1. MainActivity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.example.firebase;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
2. activity_main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
웹에서 확인해보면 안드로이드 스튜디오에서 만든 프로젝트가 Firebase와 연동되었음을 볼 수 있습니다.
'@챈챈 > #Other' 카테고리의 다른 글
[JAVA] 구구단 (0) 2020.02.20 [JAVA] 별찍기 (1) 2020.02.20 [JAVA] 은행 프로그램 (1) 2020.02.20 [FIREBASE] 파이어베이스 개발환경 구축하기3 (0) 2020.01.17 [FIREBASE] 파이어베이스 개발환경 구축하기1 (0) 2020.01.17