【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )
2023-09-14 09:07:28 时间
一、报错信息
报错信息 :
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
# 配置当前的应用市场
market=GooglePlay
在 build.gradle 中的对应配置如下 :
android {
defaultConfig {
// 应用是否在 Google Play 上架
buildConfigField("boolean", "isGooglePlay", isGooglePlay)
// 当前的应用市场
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 字符串没有双引号导致错误 ;
二、解决方案
使用
buildConfigField("String", "market", "\"${market}\"")
Groovy 代码 , 可以生成 BuildConfig.java 中的如下配置 :
public static final String market = "GooglePlay";
字符串的双引号需要自己使用转义字符添加上去 , 否则无效 ;
"\"${market}\""
的 第一层双引号 , 是因为 buildConfigField 函数需要传入三个字符串类型的变量 , 第三个参数必须是字符串 ;
第二层双引号 \" \"
使用转移字符 , 这才是在 BuildConfig 中显示的双引号 , 内部的 ${market}
就是 GooglePlay
配置内容 ;
相关文章
- 代码加密 android,Android 开发怎样做代码加密或混淆「建议收藏」
- Android代码混淆及调试错误「建议收藏」
- android autosize原理,Android屏幕适配头条:autosize的原理
- strictmode android,(十三)Android 性能优化 StrictMode
- 测试android sdk是否安装成功,配置Android SDK
- android短信验证码方案,Android开发之属于你的短信验证码(一)
- android短信验证码代码,Android短信验证码自动填写实现代码
- android调用相册并显示图片_Android获取相册列表
- android横竖屏切换问题
- 【错误记录】Android Studio 中 DataBinding 布局报错 ( Resources$NotFoundException: String resource ID #0xd )
- 【Android RTMP】音频数据采集编码 ( FAAC 头文件与静态库拷贝到 AS | CMakeList.txt 配置 FAAC | AudioRecord 音频采样 PCM 格式 )
- 【Android 性能优化】应用启动优化 ( 安卓应用启动分析 | Launcher 应用启用普通安卓应用 | 应用进程分析 )
- 【错误记录】Flutter / Android 报错 ( AAPT: error: attribute android:requestLegacyExternalStorage not found )
- 【错误记录】Android 应用 release 打包报错处理 ( 关闭语法检查 | 日志处理 | release 配置 )
- 【错误记录】Android 应用打包错误 ( Entry name ‘assets/xxx.xml‘ collided )
- 【错误记录】Android 低版本使用分区存储错误 ( 低版本存储不得使用 MediaStore )
- 【错误记录】Android 应用运行报错 ( You need to use a Theme.AppCompat theme (or descendant) with this activity. )
- 【错误记录】Android Studio 创建报错 ( The length of the module location exceeds the limit of 100 characters. )
- 【错误记录】Android Studio 中查看 Gradle 配置的方法源码 ( 配置 gradle-wrapper.properties 中版本为 gradle-x.x.x-all.zip )
- 【Android Gradle 插件】Module 目录下 build.gradle 配置文件 ( android 闭包块配置 | AppExtension 扩展类型参考文档 )
- 【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )
- 【ijkplayer】编译 Android 版本的 ijkplayer ③ ( 执行 compile-ffmpeg.sh clean 命令 | 下载并配置 android-ndk-r10e )
- 【错误记录】Android Studio 编译报错 ( Error: Duplicate resources | 使用 sourceSets 配置多个 res 资源不能有重复名称的资源 )
- 【Android Gradle 插件】组件化中的 Gradle 构建脚本实现 ⑤ ( 优化 Gradle 构建脚本 | 构建脚本结构 | 闭包定义及用法 | 依赖配置 | android 块配置 )
- [android] 看博客学习Android常见的几种RuntimeException详解手机开发
- WPS Office for Android v12.5 高级特别版
- Android中button实现onclicklistener事件的两种方式
- android新建草稿删除后下次开机还会显示保存的草稿
- Android获得当前正在显示的activity类名的方法