简体   繁体   English

如何在build.gradle中使用不同的依赖关系?

[英]How to use different dependencies in build.gradle?

(related to my question here ) (有关我的问题在这里

I want to publish a one time update for my app for minSdk < 14 (compared to the current minSdk = 15. I am considering creating two flavors of my app - one that supports API levels lower than 14 with android support library 25.4.0 , and for API level 14 and newer that uses the latest support library 27.1.1, which only support API 14 and above. 我想为我的应用发布一次minSdk <14的更新(与当前的minSdk = 15比较)。我正在考虑创建我的应用的两种样式-一种使用Android支持库25.4.0支持低于14的API级别,对于使用最新支持库27.1.1(仅支持API 14及更高版本)的API级别14和更高版本。

Can the dependencies section of the build.gradle support different packages imports for different flavors? build.gradle的dependencies部分可以支持不同口味的不同包导入吗?

My first try looks like this: 我的第一次尝试如下所示:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    flavorDimensions "standard", "oldApi"

    defaultConfig {
        versionCode 37
        versionName "2.1.3"
        applicationId "org.app"
    }

    productFlavors {
        standard {
            dimension "standard"
            targetSdkVersion 27
            minSdkVersion 15
        }

        oldApi {
            dimension "oldApi"
            versionNameSuffix "X" //for old devices
            targetSdkVersion 14
            minSdkVersion 8
            maxSdkVersion 14
        }
    }

    signingConfigs {...}
    }

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

dependencies {
    standardImplementation project(path: ':MyappLibrary', configuration: 'standard')
    oldApiImplementation project(path: ':MyappLibrary', configuration: 'oldApi')
}

and: 和:

apply plugin: 'com.android.library'
android {
    compileSdkVersion 27
    flavorDimensions "standard", "oldApi"

    productFlavors {
        standard {
            dimension "standard"
        }

        oldApi {
            dimension "oldApi"
        }
    }
}

dependencies {
    api 'com.dropbox.core:dropbox-core-sdk:3.0.6'
    standardApi "com.android.support:appcompat-v7:$package_version"
    standardApi "com.android.support:support-v4:$package_version"
    oldApiApi 'com.android.support:appcompat-v7:25.4.0'
}

Errors (note the bolded parts): 错误(请注意粗体部分):

Unable to resolve dependency for ':app@ standardOldApiDebug /compileClasspath': Could not resolve project :MyappLibrary. 无法解析':app @ standardOldApiDebug / compileClasspath'的依赖项:无法解析项目:MyappLibrary。

Unable to resolve dependency for ':app@ standardOldApiDebugAndroidTest /compileClasspath': Could not resolve project :MyappLibrary. 无法解析':app @ standardOldApiDebugAndroidTest / compileClasspath'的依赖项:无法解析项目:MyappLibrary。 Open File Show Details 打开文件显示详细信息

Can the dependencies section of the build.gradle support different packages imports for different flavors? build.gradle的dependencies部分可以支持不同口味的不同包导入吗?

You can specify: 您可以指定:

productFlavors {
        f1 {
           //..
        }
        f2 {
           //..
        }
   }

dependencies{         
    f1Implementation 'com.android.support:appcompat-v7:XX.2.1'
    f2Implementation 'com.android.support:appcompat-v7:27..1'
}

More info here . 更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM