2015-08-30 66 views
2

假設我有這樣的build.gradle:不同依賴於不同的口味和在建的gradle類型

android { 
    productFlavors { 
     flavor1 { 
     } 
     flavor2 { 
     } 
    } 
} 

如何指定不同的相關性,如:

dependencies { 
    flavor1DebugCompile ... 
    flavor1ReleaseCompile ... 
    flavor2DebugCompile ... 
    flavor2ReleaseCompile ... 
} 

搖籃會產生錯誤,如:Could not find method flavor1DebugCompile() for arguments ...

+0

這是正確的。問題在哪裏? –

+0

gradle說'找不到方法flavor1DebugCompile()的參數...' – jayatubi

回答

0

這是一個錯誤。 試試這個:

def customDeps = [ 
    flavor1DebugCompile : dependencies.project(path: ':yourproject', configuration: 'flavor1Debug'), 
    flavor2DebugCompile : dependencies.project(path: ':yourproject', configuration: 'flavor2Debug'), 
    flavor1ReleaseCompile : dependencies.project(path: ':yourproject', configuration: 'flavor1Release'), 
    flavor2ReleaseCompile : dependencies.project(path: ':yourproject', configuration: 'flavor2Release'), 
] 

configurations.all() { config -> 
    Dependency d = customDeps.get(config.name) 
    if (d != null) { 
     config.dependencies.add(d) 
    } 
} 
+0

試圖打印出所有的配置,但沒有任何像'flavor1DebugCompile'命名的配置。我只能看到這樣的配置:'flavor1Compile','flavor2Compile','debugCompile','releaseCompile'等 – jayatubi

相關問題