【问题标题】:Gradle can't see product flavors. How can I add them?Gradle 看不到产品风味。我怎样才能添加它们?
【发布时间】:2018-04-15 23:23:27
【问题描述】:

当我尝试向我的项目添加风格时,Gradle 根本不想同步,即使我同步它,我也无法在 Build Variats 中看到风格。什么会导致这个问题?该项目有几个模块,我需要为应用程序添加风味。我的档案:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.24.4'
    }
}

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


def keystorePropertiesFile = "${rootDir}${File.separator}keystore.properties" as File

keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {

    dexOptions {
           javaMaxHeapSize "4g"
    }

    compileSdkVersion 25
    buildToolsVersion "25.0.3"

    defaultConfig {
        applicationId ""
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 9999
        versionName "17.2 (9999)"
    }

    productFlavors {
        testFlavor {
            applicationId "com.volodymyr.mobiletest"
        }
    }

    def keystoreFilePath = "${System.properties['user.home']}${File.separator}${keystoreProperties['storeFile']}"
    signingConfigs {
        config {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreFilePath)
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {

        }
        debug {

        }
    }
    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a', 'arm64-v8a'//, 'x86', 'x86_64'
            universalApk true
        }
    }

    lintOptions {
        lintConfig file("lint.xml")

        check "WrongConstant"
        abortOnError true
    }
}

tasks.whenTaskAdded { task ->
    if(task.name.equals("assembleDebug")){
        task.dependsOn(lint)
    }
}
dependencies {
}

我从这里删除了一些信息,例如依赖项、id 等,只是为了显示一个结构。

【问题讨论】:

    标签: android gradle android-gradle-plugin android-productflavors


    【解决方案1】:

    错误:(15, 0) ProductFlavor 名称不能以 'test' 开头

    你应该使用另一个风味名称

    【讨论】:

    • ^^ 不能以 'test' 开头并不意味着等于 test。你现在的风味名称是testFlavor(它以测试开头)。您应该将其更改为 demoFlavor 或 abcFlavor,...不是测试...
    • 如果我添加一些资源,我仍然看不到“Sourse set”。 Gradle 仍然不想同步,而且我在 Build Types 上看不到风味
    • 你的安卓工作室版本是多少? gradle 是否显示任何错误?尝试重启android studio。
    • 3.0.没有报错,可能是gradle版本导致的?
    • 你的构建 gradle 是哪个?
    【解决方案2】:

    问题在于这个 gradle 文件仅用于 CI。要更改 gradle 配置,我需要改进 settings.gradle 中的构建文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      相关资源
      最近更新 更多