0

when I place the

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

in library module in app level it show an error like

'Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension'

So I removed the plugin it build successfully. But the data is not store in FireStore. How can I store the data when I place the plugin in library module.

How to solve that problem ? Root level app module :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.example.vijayasrivudanti.pages"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        configurations.all {
            resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.0.2'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.stripe:stripe-android:4.1.5'
    compile 'com.google.firebase:firebase-database:11.4.2'
    compile 'com.google.android.gms:play-services:11.4.2'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.firebase:firebase-firestore:11.4.2'
    compile 'com.google.android.gms:play-services-auth:11.4.2'

    testCompile 'junit:junit:4.12'
    compile project(':pays')


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


Library app module :

   // enter code here
apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        configurations.all {
            resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.stripe:stripe-android:4.1.5'
    compile 'com.google.firebase:firebase-database:11.4.2'
    compile 'com.google.android.gms:play-services:11.4.2'
    compile 'com.android.support:multidex:1.0.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.firebase:firebase-firestore:11.4.2'

    //compile project(':ReactAndroid')
    //compile (project(':react-native-firestack')){exclude group: 'com.google.android.gms' }
}

apply plugin: 'com.google.gms.google-services'
Lahari Areti
  • 627
  • 2
  • 10
  • 30

1 Answers1

1

Add the below in your root build.gradle file

 classpath 'com.google.gms:google-services:3.1.0'

In a library module, you do not need to add the plugin; you can directly use the compile repo of Google services. Just make sure it is there in app level build.gradle file.

Below is a sample whole file:

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

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        jcenter()
        mavenCentral()
        google()
    }
}

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

here is a sample app level build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-crash'
android {

    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.ncommunity.agriculture"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 11
        versionName "1.10"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
        debug {
            signingConfig signingConfigs.config
            resValue("string", "PORT_NUMBER", "8081")
        }
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    debugCompile project(':debug-db')
    compile project(':tracker')
    compile 'com.android.support:appcompat-v7:26.1.0'
    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support:cardview-v7:26.1.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.google.android.gms:play-services-location:11.4.2'
    compile 'com.google.android.gms:play-services-places:11.4.2'
    compile 'com.google.android.gms:play-services-maps:11.4.2'
    compile 'com.github.dmytrodanylyk.shadow-layout:library:1.0.3'
   /* compile 'com.google.android.gms:play-services:11.4.0'*/
    compile 'com.google.firebase:firebase-core:11.4.2'
    compile 'com.google.firebase:firebase-crash:11.4.2'
    compile 'com.google.firebase:firebase-messaging:11.4.2'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.squareup.okhttp3:okhttp:3.4.2'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.github.Kunzisoft:Android-SwitchDateTimePicker:1.7'
    compile 'com.github.safetysystemtechnology:location-tracker-background:v1.2'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:recyclerview-v7:26.1.0'
    testCompile 'junit:junit:4.12'
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
halfer
  • 19,824
  • 17
  • 99
  • 186
Niraj Sanghani
  • 1,493
  • 15
  • 23