3

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

在此处输入图像描述

AClean 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'
}

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

此版本中使用了已弃用的 Gradle 功能,使其与 Gradle 7.0 不兼容。使用“--warning-mode all”显示各个弃用警告。见https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings

4

1 回答 1

1

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

  • Make Project从构建菜单中选择。
  • 转到File菜单并选择Invalidate Cache/restart
  • 将 gradle-wrapper.properties 中的更改distributionUrl为其他一些版本(首选更高版本)。
    distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
  • 更新安卓工作室。
于 2020-05-11T15:02:34.193 回答