Gradle code broken after updating to gradle 6.x variant.getVariantData().getVariantConfiguration() not working

Viewed 1795

I defined manifest placeholders for different variants using following code.

android.applicationVariants.all { variant ->
//        def names = variant.getVariantData().getVariantConfiguration().getFlavorName()
    def mergedFlv = variant.getVariantData().getVariantConfiguration().getMergedFlavor()

    mergedFlv.manifestPlaceholders = [pl1: mergedFlv.getApplicationId() + mergedFlv.getApplicationIdSuffix()]

It was working well. But I updated to the latest version of Android Studio a week ago and also updated gradle version for this project when Android Studio prompted and the Android Studio throws following error.

No signature of method: com.android.build.gradle.internal.variant.ApplicationVariantData.getVariantConfiguration() is applicable for argument types: () values: []

How do I fix this?

Update

I found this class at https://android.googlesource.com/platform/tools/build/+/0d498ccf6f91a12c036b382b7ae2b1a809eb2b9d/gradle/src/main/groovy/com/android/build/gradle/internal/variant/ApplicationVariantData.java

It does not have getVariantConfiguration() method. But it is extending ApkVariantData class which in turn is extending BaseVariantData. BaseVariantData has this public method getVariantConfiguration()

Thus it should be accessible. I closed and reopened project as well as android studio and tried building project again too... Doesn't seem to work.

Any help please

2 Answers

As of now I downgraded my Android Gradle Plugin Version from 4.0.0 to 3.6.3 and Gradle Version from 6.5.1 to 5.6.4 following this answer (method to downgrade) and it worked.

There seems to be problem/bug with Gradle.

Refer this post.

I think this may no longer work. See Android 4.0 Known Issues - Variant Output

Try this instead:

android.applicationVariants.all { variant ->
//        def names = variant.getFlavorName()
    def mergedFlv = variant.getMergedFlavor()

    mergedFlv.manifestPlaceholders = [pl1: mergedFlv.getApplicationId() + mergedFlv.getApplicationIdSuffix()]

It worked for me.

Related