0

Like the following grade script setting:

productFlavors {
   A { description "A"}
   B { description "B" }
   C { description "C" }
    }

productFlavors.all { flavor ->
        println name
        println description
    }

logout is:

A 
C
B
C
C
C

What is wrong with me here?

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
Jenus Dong
  • 304
  • 2
  • 7
  • 2
    Maybe you should use `flavor.name`, `flavor.description`? – Opal Jan 08 '16 at 08:13
  • flavor.name can pass compile, but flavor.description cannot. So, description for what? [Build Type + Product Flavor = Build Variant] – Jenus Dong Jan 08 '16 at 09:42
  • Seems like `productFlavor` class doesn't have the field `description` – RaGe Jan 08 '16 at 19:28
  • 1
    See here: http://stackoverflow.com/questions/28232261/android-studio-gradle-product-flavors-define-custom-properties/28279105#28279105 – RaGe Jan 08 '16 at 19:30
  • Good point. And I know the reason of the problem. Always the puzzle is "description" is not my custom define property. My first impression is it is inline property, just like 'name' property. You can use smart tip to see it when click down 'd' the first letter in your productFlavors block. – Jenus Dong Jan 10 '16 at 13:54

1 Answers1

1

If your intention is to use description somewhere in your code it is better you add a BuildConfigField. You can do it as follows:

productFlavors {
   A { 
     buildConfigField 'String', 'DESCRIPTION', '"A"'
   }
   B { 
     buildConfigField 'String', 'DESCRIPTION', '"B"' 
   }
   C { 
     buildConfigField 'String', 'DESCRIPTION', '"C"'
   }
}

These can be accessed in your java code as follows:

String desc = BuildConfig.DESCRIPTION;
Viral Patel
  • 32,418
  • 18
  • 82
  • 110
  • thanks. Yes, your comment is good. To me, I wonder how to use "description" property in the build.gradle for different productFlavors? You know, 'name' field can be printed with right value, but 'description'. – Jenus Dong Jan 10 '16 at 13:41
  • Haven't tried it but can you try and print "BuildConfig.DESCRIPTION" and see of it works there? – Viral Patel Jan 10 '16 at 20:14
  • Yes, it works. "Description" is referred to Project define: /** * Returns the description of this project. * * @return the description. May return null. */ String getDescription(); – Jenus Dong Jan 11 '16 at 01:43