简体   繁体   English

如何在 android 中的应用程序 build.gradle 中使用 productFlavors 定义不同的 compileSdkVersion

[英]How to define different compileSdkVersion using productFlavors in app build.gradle in android

I want to add define different compile sdk version for each if my product flavour A and B as mentioned below.如果我的产品风味 A 和 B 如下所述,我想为每个添加定义不同的编译 sdk 版本。

 productFlavors {
        a{
            compileSdkVersion 29
        }
        b{
           compileSdkVersion 30
        }
    }

But its not detecting.但它没有检测到。 Please help me if anyone knows.如果有人知道,请帮助我。

As I know you can't have different build.gradle for product flavors.据我所知,您不能为产品口味提供不同的build.gradle However you should be able to condition the buildscript and the compileSdkVersion .但是,您应该能够调节buildscriptcompileSdkVersion

It is not so clean but you can use something like:它不是那么干净,但你可以使用类似的东西:

    buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    if (condition) {
        dependencies {
            classpath 'com.android.tools.build:gradle:1.3.0+'
        }
    } else if (condition) {
        dependencies {
            classpath 'com.amazon.device.tools.build:gradle:1.1.3'
        }
    }
}

android {
  def type="Google"

    if (type=="Google") {
        compileSdkVersion 29
    } else if (type=="Amazon") {
        compileSdkVersion 30            
    }
  //...
}

暂无
暂无

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

相关问题 在Android Studio中创建新项目之前,如何在build.gradle中设置compileSdkVersion? - How to Setting compileSdkVersion in build.gradle before create a new project in Android Studio? 如何在android的build.gradle文件中定义flutter应用程序的基本URL? - How to define base URL for flutter app in build.gradle file of android? Gradle构建在不同产品上失败 - Gradle build failing on different productFlavors Android Studio:如何在build.gradle中定义自定义宏(针对不同的构建变体),并让本机C / C ++代码检测到它们? - Android Studio: How to define custom macros in build.gradle (for different build variants) and let native C/C++ code detect them? 如何在Eclipse的现有Android应用上添加build.gradle - How to add build.gradle on existing Android app on Eclipse 如何在离子项目中找到( <android> / <app> /build.gradle) - how to find in ionic project (<android>/<app>/build.gradle) 如何在build.gradle中为Android应用程序指定支持的体系结构? - How to specify supported architectures for android app in build.gradle? 如何使用Eclipse在build.gradle中包含android.support - How to include android.support in build.gradle using Eclipse 如何使用android studio将TIKA添加到build.gradle中? - How to add TIKA into build.gradle using android studio? 如何从build.gradle中提取compileSdkVersion以在.travis.yml中使用? - How to extract compileSdkVersion from build.gradle to be used in .travis.yml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM