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'
}
我认为我知道造成这个错误的原因了。如果你看看依赖关系,会发现有两个重复的包名不同的冗余包。
com.android.support.constraint:constraint-layout:1.1.0 androidx.constraintlayout:constraintlayout:1.1.0
但是我不能删除它们中的任何一个,因为一些包使用了它们。我是Android开发的新手,所以对任何解决方法都没有太多想法。
如果我删除
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
我在调试过程中遇到了这个错误:
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;
提前致谢。