2

我的項目有一個免費和付費版本,僅對特定的味道添加依賴項 - Android Studio

免費版本使用Admob服務,但付費版本沒有任何廣告。 如何刪除的付費版本

依賴這是我的build.gradle文件

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 22 
    buildToolsVersion "22.0.1" 

    defaultConfig { 
     applicationId "com.udacity.gradle.builditbigger" 
     minSdkVersion 10 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 
     testApplicationId"com.udacity.gradle.builditbigger.tests" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    productFlavors{ 
     free{ 
      applicationId"com.udacity.gradle.builditbigger.flavours.free" 
     } 
     paid{ 

      applicationId"com.udacity.gradle.builditbigger.flavours.paid" 
     } 


    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    // Added for AdMob 

    compile project(':mylibrary') 
    compile project(path: ':endpoint-backend', configuration: 'android-endpoints') 
    compile 'com.android.support:appcompat-v7:22.2.0' 


     compile 'com.google.android.gms:play-services:7.5.0' 


} 

我想依賴編譯「com.google.android.gms:發揮服務:7.5.0」只適用於免費版本,但不適用於付費版本。

回答

6

爲了不同的依賴添加到不同的生成類型或香料,你可以使用這個

dependencies { 
    releaseCompile 
    debugCompile 
    flavor1Compile 
    flavor1DebugCompile 
} 

你的情況:

dependencies { 
    freeCompile 'com.google.android.gms:play-services:7.5.0' 
} 

另外,如果你需要olny AdMob後,你應該使用這種依賴關係,而不是充分發揮服務。

compile 'com.google.android.gms:play-services-ads:7.8.0' 
+0

'apply'怎麼樣? – Kehlan

相關問題