簡體   English   中英

僅將依賴項添加到特定的風味-Android Studio

[英]Adding dependency only to specific flavour - 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:play-services:7.5.0'。

要將不同的依賴項添加到不同的構建類型或風格,可以使用此

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'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM