Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not get unknown property 'processReleaseGoogleServices'

I updated to use Android Studio 2.2 and Gradle 2.2.0. And now I have a problem building.

I followed this post https://medium.com/google-cloud/automatic-per-variant-google-services-json-configurations-with-gradle-d3d3e40abc0e#.g1p7c1tx2 to configure two "google-services.json" files to be used for dev vs prod builds and use the following method in my app/build.gradle file to toggle between the copying the two "google-services.json" files.

afterEvaluate {
    processDebugGoogleServices.dependsOn switchToDebug
    processReleaseGoogleServices.dependsOn switchToRelease
}

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

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

Gradle complies fine but when I click on the "Run app" (triangle "play" icon) or "Debug app" (triangle "play" icon with a bug behind) buttons in Android Studio, I get the following:

* What went wrong:
A problem occurred configuring project ':app'.
> Could not get unknown property 'processReleaseGoogleServices' for object of type com.android.build.gradle.AppExtension.

Please help, much appreciated.

like image 273
user1465656 Avatar asked Sep 21 '16 00:09

user1465656


4 Answers

I had the same issue and problem was in enabled instant run.Try to disable it and run again.

like image 63
Artem Korolchuk Avatar answered Nov 12 '22 08:11

Artem Korolchuk


You should update Google Play Services gradle plugin as well, follow the documentation to set it up: https://developers.google.com/android/guides/google-services-plugin

The great thing is that you no longer need to write gradle tasks which create appropriate google-services.json files in your root directory. Build type specific google-services.json are now supported by the plugin:

"As of version 2.2.0 the plugin supports build type and product flavor specific JSON files. All of the following directory structures are valid"

like image 1
Singed Avatar answered Nov 12 '22 09:11

Singed


An alternative way to this is to refer to the task in the following way:

tasks.whenTaskAdded { task ->
    if (task.name == 'assembleDebug') {
        task.dependsOn 'switchToDebug'
    } else if (task.name == 'assembleRelease') {
        task.dependsOn 'switchToRelease'
    }
}

UPDATE

The problem you mentioned in comment is related to your google-services.json file. You need to place google-services.json into app/ dir. And for each build type there should be accordant director in app/src folder. If file already exists check if correct package name inside it

"client_info": {
"mobilesdk_app_id": "1:6596814400689:android:65d6f25f5006145",
"android_client_info": {
  "package_name": "com.my.app.package.name"
}
like image 1
Volodymyr Avatar answered Nov 12 '22 07:11

Volodymyr


As described by @Singed, add a directory pr build type/flavor under src-directory and the corresponding google-services.jsonand Google Play gradle plugin will take care of the rest, e.g.:

src/
    debug/google-services.json
    release/google-services.json

During build the correct file will be processed, ending up in build/generated/res/google-services/debug|release/values/values.xml

like image 1
Bjørn Egil Avatar answered Nov 12 '22 07:11

Bjørn Egil