How to get the build variant at runtime in Android Studio?

前端 未结 5 1100
别那么骄傲
别那么骄傲 2020-12-02 22:00

I\'d like to get the build variant during runtime, is this possible without any extra config or code?

5条回答
  •  执念已碎
    2020-12-02 22:35

    You can try with

    getPackageName(); 
    

    it will return what you've defined in build.gradle

    productFlavours{
      flavour1{
         applicationId 'com.example.package.flavour1'
      }
      flavour2{
         applicationId 'com.example.package.flavour2'
      }
    }
    

提交回复
热议问题