且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ClassNotFoundException:找不到类"android.support.constraint.ConstraintLayout";在路上

更新时间:2022-03-09 06:37:51

您之前所做的更改破坏了Gradle File(模块1). 它应该看起来像这样:

Changes you have made earlier corrupted your Gradle File (the module one). It should look like this:

apply plugin: 'com.android.application'

android {

    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "***" /*Your package name*/
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 5
        versionName "1.4"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}

dependencies {
//Your Dependencies
//Don't forget to add dependency of constraint-layout
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
}

为约束布局添加依赖项. 查看代码

Add dependency for constraint-layout. See Code

注意:编译已过时并被实现"取代 关键字,因此将"compile"替换为"implementation"

NOTE : compile has become obsolete and replaced with 'implementation' keyword so replace 'compile' with 'implementation'

因此代码将是

dependencies {
//Your Dependencies
//Don't forget to add dependency of constraint-layout
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
}

更新:如果您现在已经升级到AndroidX.然后,您需要使用androidx.constraintlayout.widget.ConstraintLayout而不是android.support.constraint.ConstraintLayout

UPDATE: If you have upgraded to AndroidX now. Then you need to use androidx.constraintlayout.widget.ConstraintLayout instead of android.support.constraint.ConstraintLayout