BuildConfig类找不到,BuildConfig.java类不在编译加载路径问题解决

今天用buildConfigField设置编译时常量遇到了问题,访问不到BuildConfig类,import导包也找不到类,具体设置如下:

复制代码
    defaultConfig {
        applicationId 'com.sample.abc'
        minSdk 28
        targetSdk 33
        versionCode getVerInt()//1
        versionName getVerName()//"1.0"
        
        

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        buildConfigField "String", "Build_ENV", "\"abc\""
        buildConfigField "String", "Build_VEHICLE_TYPE", "\"type1\""
    }

原因是buildConfigField脚本写在了testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"脚本之后;

写在testInstrumentationRunner语句之前就可以解决了,代码如下:

复制代码
    defaultConfig {
        applicationId 'com.sample.abc'
        minSdk 28
        targetSdk 33
        versionCode getVerInt()//1
        versionName getVerName()//"1.0"

        buildConfigField "String", "Build_ENV", "\"abc\""
        buildConfigField "String", "Build_VEHICLE_TYPE", "\"type1\""
        

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        
    }
相关推荐
不好听61320 分钟前
JavaScript 到底是怎么运行的?从编译阶段到执行上下文全面解析
javascript
丷丩1 小时前
MapLibre GL JS第29课:添加Canvas源
javascript·gis·map·mapbox·maplibre gl js
utf8mb4安全女神1 小时前
【rsyslog服务】把所有服务的“临界点”以上的错误都保存在/var/log/alert.log⽇志中
java·前端·javascript
csdn_aspnet1 小时前
javascript 算法 LeetCode 编号 70 - 爬楼梯
开发语言·javascript·算法·leetcode·ecmascript
swipe1 小时前
DeepAgents 多 Agent 深度调研助手工程实战:从 createDeepAgent 到可控调研工作流
javascript·面试·langchain
moMo2 小时前
JavaScript 变量提升,执行上下文里的各种门道
javascript·面试
weixin_471383032 小时前
由浅入深递归练习
前端·javascript·vue.js
丷丩2 小时前
MapLibre GL JS第21课:绘制GeoJSON点图标、注记
前端·javascript·gis·mapbox·maplibre gl js
丷丩3 小时前
MapLibre GL JS第20课:更新GeoJSON多边形
前端·javascript·gis·mapbox·maplibre gl js
丷丩3 小时前
MapLibre GL JS第33课:渲染世界副本
javascript·gis·map·mapbox·maplibre gl js