1

If anyone can explain how to use Firebase in Intellij Idea, it would be very useful as I am unable to find any resource to refer to.

I found that following is the process for Android Studio but I need to do it in Intellij Idea.

First make sure you have installed Google Repository version 26 or higher, using the following steps:

Click Tools > SDK Manager.
Click the SDK Tools tab.
Check the Google Repository checkbox, and click OK.
Click OK to install.
Click Background to complete the installation in the background, or wait for the installation to complete and click Finish.
You can now open and use the Assistant window in Android Studio by following these steps:

Click Tools > Firebase to open the Assistant window.
Click to expand one of the listed features (for example, Analytics), then click the Get Started tutorial to connect to Firebase and add the necessary code to your app.

1 Answers1

1

It's not as difficult as it may seem.

This explains all the proccess.

Your choose is the Option 1. After step 4 your project-level build.gradle should look like (of course sdk, java, libreries versions can be different)

all sub-projects/modules.
buildscript {
    repositories {
        google()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.12'
    }
}

plugins {
    id 'com.android.application' version '7.2.1' apply false
    id 'com.android.library' version '7.2.1' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

allprojects {
    repositories {
        google()
    }
}

and app-level build.gradle(app/build.gradle) like

plugins {
    id 'com.android.application'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "io.devmartynov.bulletinboard"
        minSdk 30
        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_11
        targetCompatibility JavaVersion.VERSION_11
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation platform('com.google.firebase:firebase-bom:30.2.0')
    implementation 'com.google.firebase:firebase-database'
}

apply plugin: 'com.google.gms.google-services'

Don't foget to add implementation 'com.google.firebase:firebase-database' in you app-level build.gradle(app/build.gradle), because steps 1-4 don't mention it.

After that sync gradle files changes. While syncing you may face with error Build was configured to prefer settings repositories over project repositories but repository 'Google' was added by build file 'build.gradle'. This explains and solves the problem.

Next you should create Realtime Database. It's pretty simple!

You also must place google-services.json file to your app directory. You can download this file in settings->project settings->your apps->google-services.json

After that you can try to write to you DB.

Add this test code to onCreate method and start app.

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("messages");
myRef.setValue("Hello, World!");
domartynov
  • 58
  • 5