2017-01-10 50 views
0

沒有人知道如何獨立簽署多個風格和尺寸的應用程序? 我試圖檢索提供簽名配置的任務的名稱,但它不起作用。Gradle與風味和尺寸簽署

這裏是我的gradle這個文件:

signingConfigs { 
    vanillaPaid { 
     ... 
    } 
    vanillaFree { 
     ... 
    } 
    chocolatePaid { 
     ... 
    } 
    chocolateFree { 
     ... 
    } 
} 

flavorDimensions "taste", "type" 

productFlavors { 
    vanilla { 
     dimension "taste" 
     applicationIdSuffix ".vanilla" 
    } 
    chocolate { 
     dimension "taste" 
     applicationIdSuffix ".chocolate" 
    } 
    free { 
     dimension "type" 
     ... 
    } 
    paid { 
     dimension "type" 
     ... 
    } 
} 

buildTypes { 
    release { 
     def taskNames = project.gradle.startParameter.taskNames 
     if (taskNames.size() > 0) { 
      if (taskNames.get(0).contains('VanillaPaid')) { 
       signingConfig signingConfigs.vanillaPaid 
      } else if (taskNames.get(0).contains('VanillaFree')) { 
       signingConfig signingConfigs.vanillaFree 
      } else if(...) { 
       ... 
      } 
     } 
     ... 
    } 
    debug { 
     ... 
    } 
} 
+1

什麼是'維'這裏 –

+0

這裏的維度是什麼?太? – Sodino

回答

1

解決的辦法是:

signingConfigs { 
    vanillaPaid { 
     ... 
    } 
    vanillaFree { 
     ... 
    } 
    chocolatePaid { 
     ... 
    } 
    chocolateFree { 
     ... 
    } 
} 

flavorDimensions "taste", "type" 

productFlavors { 
    vanilla { 
     dimension "taste" 
     applicationIdSuffix ".vanilla" 
    } 
    chocolate { 
     dimension "taste" 
     applicationIdSuffix ".chocolate" 
    } 
    free { 
     dimension "type" 
     ... 
    } 
    paid { 
     dimension "type" 
     ... 
    } 
} 

applicationVariants.all { variant -> 
    if (variant.name.equals("vanillaPaidRelease")) { 
     variant.mergedFlavor.setSigningConfig(signingConfigs.vanillaPaid) 
    } else if (variant.name.equals("vanillaFreeRelease")) { 
     variant.mergedFlavor.setSigningConfig(signingConfigs.vanillaFree) 
    } else if (variant.name.equals("chocolatePaidRelease")) { 
     variant.mergedFlavor.setSigningConfig(signingConfigs.chocolatePaid) 
    } else if (variant.name.equals("chocolateFreeRelease")) { 
     variant.mergedFlavor.setSigningConfig(signingConfigs.chocolateFree) 
    } 
} 

buildTypes { 
    release { 
     ... 
    } 
    debug { 
     ... 
    } 
} 

也可以設置應用程序標識如果需要的話:

applicationVariants.all { variant -> 
    if (variant.name.equals("vanillaFreeRelease")) { 
     variant.mergedFlavor.setSigningConfig(signingConfigs.vanillaFree) 
     variant.mergedFlavor.setApplicationId("com.domain.custom.id") 
    } else if (...) { 
     ... 
    } 
}