本文介绍了已存在的程序类型:android.support.constraint.BuildConfig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

build.gradle(模块:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-P'
    buildToolsVersion '27.0.3'
    defaultConfig {
        multiDexEnabled true
        applicationId "tk.megh.myapplication"
        minSdkVersion 'P'
        targetSdkVersion 'P'
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dexOptions {
        preDexLibraries = false
    }
}



dependencies {
    implementation 'com.android.support:multidex:1.0.1'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.0'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:+'
    testImplementation 'junit:junit:4.12'

}

好吧,我想我知道是什么导致了错误,如果您查看依赖项,则会有两个名称不同的冗余包

Well i think i know what's causing the error, if you look at the dependencies there are two redundant packages with different names

com.android.support.constraint:constraint-layout:1.1.0androidx.constraintlayout:constraintlayout:1.1.0

但我无法删除它们中的任何一个,因为它们被某些软件包使用.我是 android 开发的新手,所以我对任何解决方法都不太了解.

But i can't remove either of them because they are used by some packages. I'm a novice in android development, so i don't have much idea about any workarounds.

如果我删除

implementation 'com.android.support.constraint:constraint-layout:1.1.0'

我在调试时遇到这个错误:

i get this error while debugging:

    java.lang.RuntimeException: Unable to start activity 
ComponentInfo{tk.megh.myapplication/tk.megh.myapplication.MainActivity}: 
android.view.InflateException: Binary XML file line #2: Binary XML file 
line #2: Error inflating class android.support.constraint.ConstraintLayout

如果我删除

implementation 'androidx.constraintlayout:constraintlayout:1.1.0'

调试时出现以下错误:

 java.lang.RuntimeException: Unable to start activity 
ComponentInfo{tk.megh.myapplication/tk.megh.myapplication.DisplayMessageActivity}: 
android.view.InflateException: Binary XML file line #2: Binary XML file line #2: 
Error inflating class androidx.constraintlayout.widget.ConstraintLayout

其他详细信息:

导入MainActivity.java:

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;

导入DisplayMessageActivity.java:

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;   

提前致谢.

推荐答案

错误表明您在布局 xml 文件中使用了 ConstraintLayout.

The errors indicate that you're using the ConstraintLayout in your layout xml files.

只保留一个版本的库,并确保您在 xmls 中使用该版本的 ConstraintLayout.

Keep only one version of the library and make sure, that you are using that version's ConstraintLayout in your xmls.

因此,如果您保留 androidx,请检查您的布局文件并确保您在那里使用 androidx.constraintlayout.ConstraintLayout,并且没有 android.support.constraint.ConstraintLayout.

So, if you keep androidx, check your layout files and make sure, you are using androidx.constraintlayout.ConstraintLayout there, and not android.support.constraint.ConstraintLayout.

这篇关于已存在的程序类型:android.support.constraint.BuildConfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 04:23