日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Android >内容正文

Android

【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )

發(fā)布時(shí)間:2025/6/17 Android 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig ) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

  • 一、報(bào)錯(cuò)信息
  • 二、解決方案





一、報(bào)錯(cuò)信息



報(bào)錯(cuò)信息 :

D:\002_Project\002_Android_Learn\ClassLoader_Demo\app\build\generated\source\buildConfig\debug\com\example\classloader_demo\BuildConfig.java:15: 錯(cuò)誤: 找不到符號(hào)public static final String market = GooglePlay;^符號(hào): 變量 GooglePlay位置: 類 BuildConfig

在 Android Studio 項(xiàng)目根目錄的 gradle.properties 配置文件中 , 配置

# 配置是否在 Google Play 上架 isGooglePlay=true # 配置當(dāng)前的應(yīng)用市場(chǎng) market=GooglePlay

在 build.gradle 中的對(duì)應(yīng)配置如下 :

android {defaultConfig {// 應(yīng)用是否在 Google Play 上架buildConfigField("boolean", "isGooglePlay", isGooglePlay)// 當(dāng)前的應(yīng)用市場(chǎ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 字符串沒(méi)有雙引號(hào)導(dǎo)致錯(cuò)誤 ;





二、解決方案



使用

buildConfigField("String", "market", "\"${market}\"")

Groovy 代碼 , 可以生成 BuildConfig.java 中的如下配置 :

public static final String market = "GooglePlay";

字符串的雙引號(hào)需要自己使用轉(zhuǎn)義字符添加上去 , 否則無(wú)效 ;

"\"${market}\"" 的 第一層雙引號(hào) , 是因?yàn)?buildConfigField 函數(shù)需要傳入三個(gè)字符串類型的變量 , 第三個(gè)參數(shù)必須是字符串 ;

第二層雙引號(hào) \" \" 使用轉(zhuǎn)移字符 , 這才是在 BuildConfig 中顯示的雙引號(hào) , 內(nèi)部的 ${market} 就是 GooglePlay 配置內(nèi)容 ;

總結(jié)

以上是生活随笔為你收集整理的【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。