Sunday, January 28, 2018

How to Setup Google firebase SDK while using the logic in module?

Just thought to try out firebase messaging SDK to implement a chat feature. The setup is like this

App1(com.example.testapp)
Messaging Module (com.example.messaginglib)

Messaging module has core logic around implementing the chat logic and UI related to the Chat. The intention was to share this across multiple apps if needed. 

Below can be done to achieve this:

- Create a Google project in firebase with the package name com.example.testapp  (If we try to create a project with package name com.example.messaginglib, this wont work because then it will not be portable to other apps)

- Now download and copy the google-services.json file on to the app1's root folder. 

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26


    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'

    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.google.android.gms:play-services-auth:11.8.0'
    compile 'com.google.firebase:firebase-analytics:11.8.0'
    compile 'com.google.firebase:firebase-database:11.8.0'
    compile 'com.google.firebase:firebase-storage:11.8.0'
    compile 'com.google.firebase:firebase-auth:11.8.0'
    compile 'com.google.firebase:firebase-config:11.8.0'
    compile 'com.google.android.gms:play-services-appinvite:11.8.0'
    compile 'com.google.firebase:firebase-messaging:11.8.0'
    compile 'com.google.android.gms:play-services-ads:11.8.0'
    compile 'com.google.firebase:firebase-appindexing:11.8.0'
    compile 'com.google.firebase:firebase-crash:11.8.0'
    compile 'com.google.firebase:firebase-analytics:11.8.0'
    // Firebase UI
    compile 'com.firebaseui:firebase-ui-database:3.0.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Top level build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
 
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com" // Google's Maven repository
        }
    }
}

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

app level build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.examplelib"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:26.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    implementation project(':modulemessaging')
}

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

1 comment:

  1. Hey there, You’ve done an incredible job.I recommend you to check http://involvedot.com/ as well. InvolveDot is an instant messaging software for business that connects all the members within an organization. The platform provides features such as messaging, employee tracking, audio and video calls, file sharing to real-time alerts.

    ReplyDelete