홍드방 입문자님을 위한 파이어베이스 그레들리 셋팅 방법(gradle 7.x 이상)
이글은 홍드로이드 단톡방에 계신 입문자 분들을 위해 작성합니다.
https://open.kakao.com/o/gWIiEKWc
파베 프로젝트 셋팅할때 이렇게 하라고 나옵니다.
(1)build.gradle(Project:플젝명)
buildscript {
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
}
dependencies {
...
// Add this line
classpath 'com.google.gms:google-services:4.3.10'
}
}
allprojects {
...
repositories {
// Check that you have the following line (if not, add it):
google() // Google's Maven repository
...
}
}
(2)build.gradle(Module:플젝명.app)
apply plugin: 'com.android.application'
// Add this line
apply plugin: 'com.google.gms.google-services'
dependencies {
// Import the Firebase BoM
implementation platform('com.google.firebase:firebase-bom:29.1.0')
// Add the dependency for the Firebase SDK for Google Analytics
// When using the BoM, don't specify versions in Firebase dependencies
implementation 'com.google.firebase:firebase-analytics'
// Add the dependencies for any other desired Firebase products
// https://firebase.google.com/docs/android/setup#available-libraries
}
하지만 최신 안드로이드 스튜디오 사용하시는분들은 그레들리 버전도 자동으로 올라가있어서 위 방식이 되지 않을것입니다. 아쉽게도 문서 최신화가 이루어지지 않아서 생기는 문제이기도 합니다.
해결법
기존 classPath는 사라졌으며 그렇다고 비슷해보이는 plugin에 적기만해도 안될겁니다.
그래서 입문자분들은 어렵겠지만,, 공식문서를 보는 습관을 만드셔야합니다.
참고링크는 아래입니다.
https://developer.android.com/studio/releases/gradle-plugin?hl=ko#updating-plugin
어쨋든 결론인 코드를 보여드리겠습니다.
기존 classPath는 없어졌고, build.gradle(Project:플젝명)과 build.gradle(Project:플젝명.app)에 plugins 두곳다 존재하는 것이 보일겁니다.
즉, classPath에 적힌 'com.google.gms:google-services:4.3.10' (예시) 를
build.gradle(Project:플젝명) plugins 에 다음과 같이 포함하면 됩니다.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
// 이게 핵심!!!
id 'com.google.gms.google-services' version '4.3.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
주의할점은 om.google.gms:google-services:4.3.10에서 com.google.gms.google-services + 버전명 으로 바뀌었다는것인데 자세히 보면 gms:google 를 gms.google 로 바꾼것을 볼 수 있습니다. 즉
build.gradle(Module:플젝명.app)에 plugins에 명시된 내용을 적고 version을 따로 적어주는 형식입니다.
현재 예시의 해결 코드.
(1) build.gradle(Module:플젝명) (바로 위에 사용한것과 같은 코드)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.1' apply false
id 'com.android.library' version '7.1.1' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.google.gms.google-services' version '4.3.10' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
(2) build.gradle(Module:플젝명.app)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}
android {
....
}
dependencies {
...
//파이어 베이스
implementation 'com.google.firebase:firebase-analytics'
implementation platform('com.google.firebase:firebase-bom:29.1.0')
}