java - Android Studio 给了我 BuildConfig 错误

标签 java android android-studio kotlin buildconfig

如果我点击调试图标,Android Studio 有时会自动创建新的 BuildConfig文件,然后提示它应该只有一个名为 Buildconfig.java 的文件。 ...

enter image description here

一个 Clean Project修复它,但它太烦人了,必须有一个可靠的解决方案。

提前致谢

编辑:

我的 build.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.72'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        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()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我的 build.gradle(Module: app) :

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "de.my.app.id"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

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

// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)


    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.2.2'
    implementation 'androidx.navigation:navigation-ui:2.2.2'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.2.2'
    implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation 'com.github.siyamed:android-shape-imageview:0.9.3@aar'
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.github.RobertApikyan:SegmentedControl:1.2.0'
    implementation 'androidx.viewpager2:viewpager2:1.0.0'
    implementation 'com.h6ah4i.android.materialshadowninepatch:materialshadowninepatch:1.0.0'
}

编辑:
构建和调试时,我在控制台中收到此错误警告:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

最佳答案

按列出顺序尝试以下方法:

  • 选择 Make Project从构建菜单。
  • 转至 File菜单并选择 Invalidate Cache/restart .
  • 更改distributionUrl在 gradle-wrapper.properties 到其他一些版本(更高的首选)。distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
  • 更新安卓工作室。
  • 关于java - Android Studio 给了我 BuildConfig 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61636699/

    相关文章:

    android - 如何对 Android 系统应用进行仪器测试

    Android Studio 在 Windows 8 中找不到 Java SDK

    java - 在 fragment 中实现时,Google map 控制按钮(例如 mylocation 等)会消失

    java - 如何在没有名称的情况下销毁java中的对象?

    java.lang.NoClassDefFoundError : com/google/api/client/json/JsonFactory issue

    java - 填充 JTable 的第一列

    java - 如何将 PerspectiveTransform 应用于图形对象或图像?

    android - 为什么要选择 HttpGet/HttpPost 方法而不是 kSoap?

    android - 图像不显示在 android studio 的 drawable 文件夹中

    android - 我无法在 Linux mint 17.1 上安装 Android Studio