每次我进行任何更改并运行应用程序时,都会在我的项目中创建 3 个构建文件夹,这会出现“我的项目中有 3 个 BuildConfig 文件”之类的错误
当我清理项目并重建它时,该应用程序成功运行但再次创建。
这是我的项目结构:
项目构建.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext{
kotlin_version = "1.3.72"
ext.archLifecycleVersion = '2.2.0'
ext.room_version = '2.1.0-alpha01'
ext.navigation_version = '1.0.0-alpha06'
ext.kodein_version = '5.2.0'
}
repositories {
google()
jcenter()
maven {
url 'https://dl.bintray.com/pegasuscontrol/RippleCircleButton/'
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://maven.google.com"
}
maven {
url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用程序构建.gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}
project.ext {
appcompat = "26.1.0"
arch = "1.1.1"
retrofit = "2.0.2"
constraintLayout = "1.0.2"
multidexVersion = "2.0.1"
}
def NEWS_API_KEY = '"' + NewsApiKey + '"'
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.poojasingh.tutorialkotlin"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "NewsApiKey", NEWS_API_KEY
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
dataBinding = true
viewBinding = true
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
// Kotlin Android Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0-RC1'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0-RC1"
}
更新:
我尝试了这个->“文件->使用 Gradle 文件同步项目”并手动删除了“build 2”和“build 3”文件夹,它没有再次生成,但一段时间后仍然面临同样的问题。一天后我运行了我的应用程序,并且显示了此错误。我将清理项目并重建,然后它将运行。但是每次都有一个“被多次定义”的新文件,正如它在错误中所说的那样。我仍然无法找到发生这种情况的确切原因。