Gradle buildConfigField BuildConfig无法解析符号 [英] Gradle buildConfigField BuildConfig cannot resolve symbol

查看:1546
本文介绍了Gradle buildConfigField BuildConfig无法解析符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Gradle构建我的Android应用程序。我试图使用一些基于构建类型(释放或调试)的标志。

I am using Gradle to build my Android application. I am trying to use some flags based on the build type (release or debug).

我的Gradle文件如下所示:

My Gradle file looks like this:

android {
    buildTypes {
        debug {
            buildConfigField 'boolean', 'PREPROD', 'true'
            buildConfigField 'boolean', 'STAGING', 'false'
        }

        release {
            buildConfigField 'boolean', 'PREPROD', 'false'
            buildConfigField 'boolean', 'STAGING', 'false'
        }
    }
}

如果我尝试调用 BuildConfig.PREPROD BuildConfig.STAGING ,则会出现无法解析符号错误。
Gradle同步成功,所以我不知道我是否忘记了一些步骤才能使用此功能?

And if I try to call BuildConfig.PREPROD or BuildConfig.STAGING I get a "Cannot resolve symbol" error. The Gradle sync was successful, so I don't know if I forgot some steps in order to be able to use this feature?

生成的 BuildConfig.java 文件如下(在 build / source / buildConfig / debug / com.example.myapp 中) p>

The generated BuildConfig.java file is the following (in build/source/buildConfig/debug/com.example.myapp):

package com.example.myapp;

public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String PACKAGE_NAME = "com.example.myapp";
  public static final String BUILD_TYPE = "debug";
  public static final String FLAVOR = "";
  public static final int VERSION_CODE = 400;
  public static final String VERSION_NAME = "";
}


推荐答案

确保您的文件正在导入正确的 BuildConfig 类。有时如果你有其他的项目库或模块,它可能会导入错误的buildConfig。
确保导入它就像 com.project.app.BuildConfig 。我有同样的问题,问题是这个,希望它可以帮助别人。

Make sure your file is importing the right BuildConfig class. Sometimes if you have other project libraries or modules, it may import the wrong buildConfig. Make sure your import it's like this com.project.app.BuildConfig. I was Having the same issue and the problem was this, Hope it can help somebody.

这篇关于Gradle buildConfigField BuildConfig无法解析符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆