본문 바로가기

IT/Kotiln

[Android][Kotiln] 파이어베이스 연결, 연결 오류 해결하기, token 받기 - 2

반응형

[Android][Kotiln] 파이어베이스 연결, 연결 오류 해결하기, token 받기 - 1 (tistory.com)

 

[Android][Kotiln] 파이어베이스 연결, 연결 오류 해결하기, token 받기 - 1

우선 안드로이드 IDE를 키고 파이어베이스 홈페이지에 접속해 줍니다 Firebase (google.com) Firebase Firebase는 고품질 앱을 빠르게 개발하고 비즈니스를 성장시키는 데 도움이 되는 Google의 모바일 플랫

evinfor.tistory.com

 

우선 gradle(project)로 가서 확인을 해줍니다

gradle(project) 원본

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}

기본적으로 다음과 같이 원본에선 plugins만 있고 해당하는 것이 없기 때문에

 

gradle(project) 추가한 후

buildscript {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository

    }
    dependencies {
        // Add the dependency for the Google services Gradle plugin
        classpath 'com.google.gms:google-services:4.3.15'

    }
}

allprojects {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository

    }
}

 

다음과 같이 복사/붙여넣기로 아래에 해당 buildscript항목을 추가해줍니다

 

다음은 Gradle(app) 작업을 해주어야 합니다.

 

체크는 Kotiln이나 자바 자신에게 맞는 것으로 선택해주시면 됩니다

 

Gradle(app)의 원본

Gradle(app)의 원본은 다음과 같이 되어 있을 것인데 여기서는 부분만 붙여넣기 해주면 됩니다

 

해당 부분만 복사 붙여넣기 버튼을 눌러 알맞은 칸에 붙여넣도록 합니다

 

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
}

android {
    namespace 'test.sdfasf'
    compileSdk 32

    defaultConfig {
        applicationId "test.sdfasf"
        minSdk 23
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    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 'com.google.firebase:firebase-analytics-ktx'
    implementation platform('com.google.firebase:firebase-bom:31.2.0')
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.6.0'
    implementation 'com.google.android.material:material:1.8.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

저는 위와 같은 Gradle(app) 코드가 완성되었습니다

 

작업을 다 완료하셨으면 우측 상단 Sync Now 버튼을 눌러 적용을 해주도록 합니다

 

그랬더니 다음과 같은 오류가 발생했습니다

 

8: all buildscript {} blocks must appear before any plugins {} blocks in the script

 

buildscript {} block은 plugins {} block 전에 나타나야한다고 하네요

 

다음과 같이 buildscript 블럭을 plugins 블럭 전으로 옮겨주었습니다 이제 다시 우측 상단 Try Again 버튼을 누릅시다

 

이번엔 다음과 같은 오류가 발생합니다

 

Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'

 

설정 repositories 가 더 선호된다고 하는데 이미 Google이 추가되었다고하네요

 

여기선 위의 buildscript안에 있는 google()과 mavenCentral()이 중복되기 때문에 생긴 문제입니다

 

allprojects {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository

    }
}

다음 allprojects {} 블럭을 통채로 지워줍시다

 

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        // Make sure that you have the following two repositories
        google()  // Google's Maven repository
        mavenCentral()  // Maven Central repository

    }
    dependencies {
        // Add the dependency for the Google services Gradle plugin
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}

그럼 다음과 같은 build.gradle(Project)가 완성되게 됩니다

 

이제 다시 Try Again  버튼을 눌러줍니다

 

그럼 다음과 같이 BUILD SUCCESSFUL로 빌드가 성공한 것을 알 수 있습니다

 

이제 Firebase와의 연결은 완료 되었습니다!

반응형