Tag Archives: Android Gradle configure error

[Solved] Android Gradle configure error: Location: Class buildconfig

Error message:

D:\002_Project\002_Android_Learn\ClassLoader_Demo\app\build\generated\source\buildConfig\debug\com\example\classloader_demo\BuildConfig.java:15: Error: Symbol not found
  public static final String market = GooglePlay;
                                      ^
  Symbol: Variable GooglePlay
  Location: Class BuildConfig

In the gradle.properties configuration file in the root of the Android Studio project, configure as:

# Configure whether to be on Google Play
isGooglePlay=true
# Configure the current app marketplace
market=GooglePlay

The corresponding configuration in build.gradle is as follows :

android {

    defaultConfig {
        // Whether the app is available on Google Play
        buildConfigField("boolean", "isGooglePlay", isGooglePlay)
        // The current app marketplace
        buildConfigField("String", "market", market)
    }
}

The generated BuildConfig.java configuration is as follows :

/**
 * 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;
}

The last googleplay string has no double quotation marks, resulting in an error;

 

2. Solution

use

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

Groovy code , you can generate the following configuration in BuildConfig.java :

public static final String market = "GooglePlay";

The double quotes in the string need to be added with their own escape characters, otherwise they are invalid;

The first level of double quotes in “\”${market}\”” is because the buildConfigField function requires three string variables to be passed in, and the third parameter must be a string;

The second double-quote \” \”” uses the transfer character, which is the double-quote displayed in BuildConfig, and the internal ${market} is the GooglePlay configuration content ;