0

this is my build.gradle

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

buildscript {

  }

 repositories {

   android {
        signingConfigs {
     release_config {

     }
   }

compileSdkVersion 22
buildToolsVersion '22'

defaultConfig {
    applicationId "in.workindia.xxxxxxxxxxandroid"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 35
    versionName "3.3.0"
    signingConfig signingConfigs.release_config
}
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    /*While app is in debug mode disable crashlytics*/
    debug {
        versionNameSuffix "-DEBUG"
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

buildTypes.debug {
    it.buildConfigField 'String', 'BASE_URLS', DEBUG_URLS
    it.buildConfigField 'String', 'CLIENT_ID', SERVER_DEBUG_CLIENT_ID
}

buildTypes.release {
    it.buildConfigField 'String', 'BASE_URLS', BASE_URLS
    it.buildConfigField 'String', 'CLIENT_ID', SERVER_RELEASE_CLIENT_ID
}
}

afterEvaluate {
   processDebugGoogleServices.dependsOn switchToDebug
   processReleaseGoogleServices.dependsOn switchToRelease
 }

     task switchToDebug(type: Copy) {
          description = 'Switches to DEBUG google-services.json'
          from "src/debug_work"
          include "google-services.json"
          into "."
       }

  task switchToRelease(type: Copy) {
      description = 'Switches to RELEASE google-services.json'
      from "src/release_work"
      include "google-services.json"
      into "."
     }

   dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
       dependencies {
     debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
     releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
   }
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
    compile 'com.google.android.gms:play-services-analytics:8.3.0'
    compile 'com.google.android.gms:play-services-location:8.3.0'
}

these three are not getting executed why ?
afterEvaluate
switchToDebug
switchToRelease
enter image description here What I am doing wrong ?

Lokesh Tiwari
  • 10,496
  • 3
  • 36
  • 45
  • Your .gradle file is malformed. See http://developer.android.com/tools/building/configuring-gradle.html#buildFileBasics for more details. – Waqar Khan May 10 '16 at 09:48

1 Answers1

0

put this in your dependency

    compile 'com.google.android.gms:play-services-gcm:8.3.0'
    compile 'com.google.android.gms:play-services-analytics:8.3.0'
    compile 'com.google.android.gms:play-services-location:8.3.0'

Make sure that the following line is at the end of the app build.gradle file:

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

Full Gradle File :

apply plugin: 'com.android.application'

buildscript {

  }

 repositories {

   android {
        signingConfigs {
     release_config {

     }
   }

compileSdkVersion 22
buildToolsVersion '22'

defaultConfig {
    applicationId "in.workindia.xxxxxxxxxxandroid"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 35
    versionName "3.3.0"
    signingConfig signingConfigs.release_config
}
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }

    /*While app is in debug mode disable crashlytics*/
    debug {
        versionNameSuffix "-DEBUG"
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

buildTypes.debug {
    it.buildConfigField 'String', 'BASE_URLS', DEBUG_URLS

    it.buildConfigField 'String', 'GOOGLE_ANALYTIC_KEY', GoogleTracker_KEY_DEBUG
    it.buildConfigField 'Boolean', 'BRANCH_IO_MODE_IS_LIVE', BRANCH_IO_MODE_DEBUG


    it.buildConfigField 'String', 'CLIENT_ID', SERVER_DEBUG_CLIENT_ID
    it.buildConfigField 'String', 'SECRET_KEYS', SERVER_DEBUG_CLIENT_SECRET

}

buildTypes.release {
    it.buildConfigField 'String', 'BASE_URLS', BASE_URLS

    it.buildConfigField 'String', 'GOOGLE_ANALYTIC_KEY', GoogleTracker_KEY_RELEASE
    it.buildConfigField 'Boolean', 'BRANCH_IO_MODE_IS_LIVE', BRANCH_IO_MODE_LIVE


    it.buildConfigField 'String', 'CLIENT_ID', SERVER_RELEASE_CLIENT_ID
    it.buildConfigField 'String', 'SECRET_KEYS', SERVER_RELEASE_CLIENT_SECRET
}
}

afterEvaluate {
   processDebugGoogleServices.dependsOn switchToDebug
   processReleaseGoogleServices.dependsOn switchToRelease
 }

     task switchToDebug(type: Copy) {
          description = 'Switches to DEBUG google-services.json'
          from "src/debug_work"
          include "google-services.json"
          into "."
       }

  task switchToRelease(type: Copy) {
      description = 'Switches to RELEASE google-services.json'
      from "src/release_work"
      include "google-services.json"
      into "."
     }

   dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
       dependencies {
     debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
     releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
     compile 'com.google.android.gms:play-services-gcm:8.3.0'
    compile 'com.google.android.gms:play-services-analytics:8.3.0'
    compile 'com.google.android.gms:play-services-location:8.3.0'
   }

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

}
  • you are saying /**apply plugin: 'com.google.gms.google-services'**/ should be last line ?? – Lokesh Tiwari May 10 '16 at 09:49
  • @LokeshTiwari yes and also put this three inside your `dependencies`. –  May 10 '16 at 09:50
  • they are already in dependencies. Any documentation why apply plugin: 'com.google.gms.google-services' line should be at last ?? – Lokesh Tiwari May 10 '16 at 09:52
  • still same problem. I think putting apply plugin line at last do not do anything – Lokesh Tiwari May 10 '16 at 10:02
  • @LokeshTiwari in your project build you define `dependencies { classpath 'com.android.tools.build:gradle:2.1.0-alpha4' classpath 'com.google.gms:google-services:2.1.0-alpha4' }` –  May 10 '16 at 10:04
  • I using classpath 'com.google.gms:google-services:1.5.0-beta2' and gradle copy task doesn't depends upon google services – Lokesh Tiwari May 10 '16 at 10:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/111512/discussion-between-harshad-and-lokesh-tiwari). –  May 10 '16 at 10:09