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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…