【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )
生活随笔
收集整理的這篇文章主要介紹了
【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
文章目錄
- 一、報錯信息
- 二、解決方案
一、報錯信息
報錯信息 :
D:\002_Project\002_Android_Learn\ClassLoader_Demo\app\build\generated\source\buildConfig\debug\com\example\classloader_demo\BuildConfig.java:15: 錯誤: 找不到符號public static final String market = GooglePlay;^符號: 變量 GooglePlay位置: 類 BuildConfig在 Android Studio 項目根目錄的 gradle.properties 配置文件中 , 配置
# 配置是否在 Google Play 上架 isGooglePlay=true # 配置當(dāng)前的應(yīng)用市場 market=GooglePlay在 build.gradle 中的對應(yīng)配置如下 :
android {defaultConfig {// 應(yīng)用是否在 Google Play 上架buildConfigField("boolean", "isGooglePlay", isGooglePlay)// 當(dāng)前的應(yīng)用市場buildConfigField("String", "market", market)} }生成的 BuildConfig.java 配置如下 :
/*** Automatically generated file. DO NOT MODIFY*/ package com.example.classloader_demo;public final class BuildConfig {public static final boolean DEBUG = Boolean.parseBoolean("true");public static final String APPLICATION_ID = "com.example.classloader_demo";public static final String BUILD_TYPE = "debug";public static final int VERSION_CODE = 1;public static final String VERSION_NAME = "1.0";// Field from default config.public static final boolean isGooglePlay = true;// Field from default config.public static final String market = GooglePlay; }最后的 GooglePlay 字符串沒有雙引號導(dǎo)致錯誤 ;
二、解決方案
使用
buildConfigField("String", "market", "\"${market}\"")Groovy 代碼 , 可以生成 BuildConfig.java 中的如下配置 :
public static final String market = "GooglePlay";字符串的雙引號需要自己使用轉(zhuǎn)義字符添加上去 , 否則無效 ;
"\"${market}\"" 的 第一層雙引號 , 是因為 buildConfigField 函數(shù)需要傳入三個字符串類型的變量 , 第三個參數(shù)必須是字符串 ;
第二層雙引號 \" \" 使用轉(zhuǎn)移字符 , 這才是在 BuildConfig 中顯示的雙引號 , 內(nèi)部的 ${market} 就是 GooglePlay 配置內(nèi)容 ;
總結(jié)
以上是生活随笔為你收集整理的【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【数字信号处理】傅里叶变换性质 ( 共轭
- 下一篇: 【Android Gradle 插件】g