Triple-T / gradle-play-publisher

GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
MIT License
4.13k stars 341 forks source link

Error using onVariantProperties #978

Closed elrony closed 3 years ago

elrony commented 3 years ago

Hello, I have recently upgraded Gradle and GGP and updated its configuration all fine except I had to change the old outputProcessor{versionNameOverride...} to the new android{onVariantProperties...} and the build now is breaking with the error below.

I spent quite some time going through the issues here and found help with picking version 3.4.0-agp4.2 but I can't figure how to solve the problem with onVariantProperties.

Error

What went wrong:
A problem occurred evaluating project ':app'.
No signature of method: build_cvc4d1ripugzvx42x6hgp7lyh.android() is applicable for argument types: (build_cvc4d1ripugzvx42x6hgp7lyh$_run_closure5) values: [build_cvc4d1ripugzvx42x6hgp7lyh$_run_closure5@10e055fe]

This was my old config (in android/app/build.gradle)

play {
    defaultToAppBundles = true
    track = "internal"
    serviceAccountCredentials = file("./play-store.json")
    resolutionStrategy = "auto"
    outputProcessor {
        versionNameOverride = "$versionNameOverride.$versionCode"
    }
}

This is my new config

import com.github.triplet.gradle.androidpublisher.ResolutionStrategy

play {
    defaultToAppBundles.set(true)
    track.set("internal")
    resolutionStrategy.set(ResolutionStrategy.AUTO)
    serviceAccountCredentials.set(file("./play-store.json"))
}

android {
  onVariantProperties {
    for (output in outputs) {
      val processedVersionCode = output.versionCode.map { playVersionCode ->
        "$versionNameOverride.$playVersionCode"
      }
      output.versionName.set(processedVersionCode)
    }
  }
}

Versions

Tasks executed

./gradlew bundleRelease
./gradlew clean
any really

stacktrace.txt

Am I doing something wrong?

Any help appreciated. Thanks!

SUPERCILEX commented 3 years ago

I think it should be androidComponents instead of android

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

elrony commented 3 years ago

Hello,

tried the following in android/app/build.gradle (bottom of the file)

androidComponents {
  onVariantProperties {
    for (output in outputs) {
      val processedVersionCode = output.versionCode.map { playVersionCode ->
        "$versionNameOverride.$playVersionCode"
      }
      output.versionName.set(processedVersionCode)
    }
  }
}

but I am still getting errors:

No signature of method: build_cvc4d1ripugzvx42x6hgp7lyh.androidComponents() is applicable for argument types: (build_cvc4d1ripugzvx42x6hgp7lyh$_run_closure5) values: [build_cvc4d1ripugzvx42x6hgp7lyh$_run_closure5@2a829418]
SUPERCILEX commented 3 years ago

Are you sure you've applied the Android Gradle Plugin? The error is saying that android and androidComponents don't exist which probably means you're not applying AGP or aren't in the right file.

elrony commented 3 years ago

Hello,

The project I am working on is a react-native project. It has an android/build.gradle and an android/app/build.gradle.

android/build.gradle has the following:

    ....
    dependencies {
        classpath "com.android.tools.build:gradle:4.2.0"
    ...

android/app/build.gradle I did the following:

replaced the very first line:

-  apply plugin: "com.android.application"
+ plugins {
+    id("com.android.application")
+    id("com.github.triplet.play") version "3.4.0-agp4.2"
+ }

And added at the bottom of the file just after the closure of play { ... } the following:

androidComponents {
  onVariantProperties {
    for (output in outputs) {
      val processedVersionCode = output.versionCode.map { playVersionCode ->
        "$versionNameOverride.$playVersionCode"
      }
      output.versionName.set(processedVersionCode)
    }
  }
}
github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

SUPERCILEX commented 3 years ago

Whoops, will try to check this tonight.

SUPERCILEX commented 3 years ago

I think you might actually have to use AGP 7.0.0 (or at least, I know it works there). That means you'll also need GPP 3.4.0-agp7.0 (instead of 3.4.0-agp4.2).

elrony commented 3 years ago

Thanks!

Unfortunately I am unable to upgrade to gradle 7, my project does not allow it for the time being. Will keep it in mind for when I can upgrade