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

相关问题