inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

1:1채팅 만들기(Android + Kotlin + Firebase)

DB 입력

빨간색 글씨때문에 막혀요. 그리고 Cloud Firestore 초기화 코드가 달라요.

942

Tkhp Sch

작성한 질문수 35

0

val user =User(uid, username.text.toString())
에서 username부분이 빨간색이 떠요.
val db = FirebaseFirestore.getInstance.collection("users")
에서 FirebaseFirestore가 빨간색이 떠요.
addOnSuccessListener{
Log.d(TAG, "데이터베이스 성공")
}
addOnFailureListener{
Log.d(TAG, "데이터베이스 실패")
}
에서
addOnSuccessListener와 addOnFailureListener가 빨간색이 떠요.
multiDexEnabled true와 "com.android.support:multidex:1.0.3"은 어디서 나온건가요?
어디서 복사하기 붙여넣기 했나요? 파이어스토어 데이터베이스에서 검색해봐도 똑같은
코드가 없습니다. 어떻게 했는지 모르겠어요.
package com.example.chatting_video

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_main.*
import android.util.Log as Log
import kotlinx.android.synthetic.main.activity_main.login_button_main as login_button_main


class MainActivity : AppCompatActivity() {

private lateinit var auth: FirebaseAuth// ...

private val TAG: String = MainActivity::class.java.simpleName


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)"


auth = FirebaseAuth.getInstance()

join_button.setOnClickListener {

val email = email_area.text.toString()
val password = password_area.text.toString()
auth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information

Log.d(TAG, "성공")

val uid = FirebaseAuth.getInstance().uid



val user =User(uid, username.text.toString())

// 여기에서 데이터베이스에 넣음
val db = FirebaseFirestore.getInstance.collection("users")
db.document(uid)
.set(user)
addOnSuccessListener{
Log.d(TAG, "데이터베이스 성공")
}
addOnFailureListener{
Log.d(TAG, "데이터베이스 실패")
}



val intent = Intent(this, ChatListActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
startActivity(intent)


} else {

Log.d(TAG, "실패", task.exception)


}
}
}




login_button_main.setOnClickListener {

val intent = Intent(this, LoginActivity::class.java)
startActivity(intent)
}



}


}


plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.example.chatting_video"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-auth:19.3.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation platform('com.google.firebase:firebase-bom:27.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation platform('com.google.firebase:firebase-bom:26.8.0')


}

kotlin android firebase

답변 2

0

개복치개발자

multiDex 관련 설명입니다.

https://mixup.tistory.com/72

0

개복치개발자

아래 코드를 참고해보시겠어요??

// Create a new user with a first and last name
val user = hashMapOf(
       
"first" to "Ada",
       
"last" to "Lovelace",
       
"born" to 1815
)

// Add a new document with a generated ID
db
.collection("users")
   
.add(user)
   
.addOnSuccessListener { documentReference ->
       
Log.d(TAG, "DocumentSnapshot added with ID: ${documentReference.id}")
   
}
   
.addOnFailureListener { e ->
       
Log.w(TAG, "Error adding document", e)
   
}


https://firebase.google.com/docs/firestore/quickstart

Groupy 라이브러리 지원이 되지 않습니다.

0

171

1

Firebase가 아닌 my sql

0

360

0

4분 3초에서 그룹 어뎁터와 그룹뷰 홀더 빨간색 글씨

0

293

2

7강 RecyclerView 강의에서 질문있습니다.

0

613

3

개복님 말씀대루 다했는데 도중에 앱이 꺼져용

0

412

1

안녕하세요. 말씀하신 import 추가했는데 오류가 또 뜨네요 ㅠ

0

476

2

안녕하세욤 강의 잘보고 있습니다

0

292

2

파이어스토어,리얼타임데이터베이스 uid 관련 질문입니다.

0

310

2

recyclerview_list 이부분이 안뜹니다.

0

275

1

firebase 업데이트 된버전에 코드를 알 수 있을 까요?

0

226

1

Firebase 연동 질문입니다.

0

293

1

auth.createUserWithEmailAndPassword 유저생성이안돼요

0

416

1

개복치님 리사이클러뷰 질문입니다.

0

339

3

recycleview강의에서 4분 12초에 .adapter부분이 빨간색이 떠요.

0

449

3

.adapter부분이 빨간색이 떠요. 어떤게 빠진건가요?

0

217

1

RecyclerView 7분중 GroupieViewHolder 자동입력과 UserItem을 Implement Members하는법을 모르겠어요.

0

405

3

13강 리얼타임 수강중입니다. 말씀대로 LOG.D(TAG,MSG 결과입니다. )

0

526

6

GroupAdapter와 GroupieViewHolder 자동입력이 안떠요.

0

280

1

auth = FirebaseAuth.getInstance를 auth = Firebase.auth로 바꾸면 오류가 떠요.

0

264

0

빨간색 item을 Import하는 법과 GroupViewHolder 자동입력되는 법과 Try it out:2.9.0 다운받는 법좀 알려주세요!

0

259

0

13강 리얼타임 수강중입니다.

0

441

1

ChatListActivity에서 디자인 (or 텍스트) 메뉴가 없어서 리사이클뷰를 키지 못합니다.

0

342

0

이 코드를 어디에 넣는건가요? db.collection(

0

250

0

chatting_video 타이틀 제거가 안되요.

0

240

2