Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

java - Unable to reference BuildConfig after doing productFlavors

So I wanted to add productFlavors in my project so I added below code Then I got an error Unresolved reference: BuildConfig in all of file that contains import com.example.packingstation.BuildConfig

    productFlavors{
        station1{
            applicationId "com.example.packingstation"
            dimension "version"
            applicationIdSuffix ".station1"
            versionNameSuffix "-station1"
        }
        station2{
            applicationId "com.example.packingstation"
            dimension "version"
            applicationIdSuffix ".station2"
            versionNameSuffix "-station2"
        }
    }

this is all of my build.gradle

android {
    compileSdkVersion rootProject.compileSdkVersion

    buildFeatures {
        viewBinding = true
    }

    defaultConfig {
        applicationId "com.srichand.packingstation"
        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 1
        versionName "1.0"

        vectorDrawables.useSupportLibrary = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        staging {
            keyAlias stagingKeystoreProperties['key.alias']
            keyPassword stagingKeystoreProperties['key.alias.password']
            storeFile file(stagingKeystoreProperties['key.store'])
            storePassword stagingKeystoreProperties['key.store.password']
        }

        release {
            keyAlias keystoreProperties['key.alias']
            keyPassword keystoreProperties['key.alias.password']
            storeFile file(keystoreProperties['key.store'])
            storePassword keystoreProperties['key.store.password']
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix '.debug'
            buildConfigField("String", "API_URL", '"https://example.com/"')
        }

        staging {
            initWith release
            applicationIdSuffix '.staging'

            buildConfigField("String", "API_URL", '"https://example.com/"')
            signingConfig signingConfigs.staging
            matchingFallbacks = ['release']
        }

        release {
            buildConfigField("String", "API_URL", '"https://example.com/"')
            signingConfig signingConfigs.release

            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }


    }

    flavorDimensions "version"
    productFlavors{
        station1{
            applicationId "com.example.packingstation"
            dimension "version"
            applicationIdSuffix ".station1"
            versionNameSuffix "-station1"
        }
        station2{
            applicationId "com.example.packingstation"
            dimension "version"
            applicationIdSuffix ".station2"
            versionNameSuffix "-station2"
        }
    }

Buildconfig.java


public final class BuildConfig {
  public static final boolean DEBUG = Boolean.parseBoolean("true");
  public static final String APPLICATION_ID = "com.example.packingstation.debug";
  public static final String BUILD_TYPE = "debug";
  public static final int VERSION_CODE = 1;
  public static final String VERSION_NAME = "1.0";
  // Fields from build type: debug
  public static final String API_URL = "https://example.com/";
}

I am not sure what the wrong. I checked the BuildConfig.java file in the project repository and they exist and look fine

question from:https://stackoverflow.com/questions/65884035/unable-to-reference-buildconfig-after-doing-productflavors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...