【Android】【配置文件】gradle和manifest的使用(三):gradle引用properties变量

在gradle.properties里面定义变量

APP_NAME="HelloWorld"
DB_VERSION=101

在build.gradle里面引用变量

    buildTypes {
        release {
            buildConfigField "String", "APP_NAME", "${APP_NAME}"
            buildConfigField "Integer", "DB_VERSION", "${DB_VERSION}"
        }
        debug {
            buildConfigField "String", "APP_NAME", "${APP_NAME}"
            buildConfigField "Integer", "DB_VERSION", "${DB_VERSION}"
        }
    }

gradle.properties里面定义的变量是存放在project对象中的,还可以通过另一种方法调用

appName = appName
    defaultConfig {
        manifestPlaceholders = [
                appName  : project.property("appName").toString(),
                dbVersion: 101
        ]
    }

猜你喜欢

转载自blog.csdn.net/u013718730/article/details/88179711