【问题标题】:ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on pathClassNotFoundException:在路径上找不到类“android.support.constraint.ConstraintLayout”
【发布时间】:2017-05-04 21:32:14
【问题描述】:

我正在使用一些库,所以我不得不编辑 Gradle 设置。由于我的应用程序无法运行,我在 Android Studio 中使用本地历史记录恢复了它,但它仍然无法运行。返回的错误在这里报告

05-04 23:26:34.953 28017-28017/? I/art: Late-enabling -Xcheck:jni
05-04 23:26:35.217 28017-28017/com.quintabi.facchini.myshop W/System: ClassLoader referenced unknown path: /data/app/com.quintabi.facchini.myshop-2/lib/arm
05-04 23:26:35.233 28017-28017/com.quintabi.facchini.myshop I/InstantRun: starting instant run server: is main process
05-04 23:26:35.333 28017-28017/com.quintabi.facchini.myshop W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-04 23:26:35.465 28017-28017/com.quintabi.facchini.myshop D/AndroidRuntime: Shutting down VM


                                                                              --------- beginning of crash
05-04 23:26:35.466 28017-28017/com.quintabi.facchini.myshop E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              Process: com.quintabi.facchini.myshop, PID: 28017
                                                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.quintabi.facchini.myshop/com.quintabi.facchini.myshop.index}: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
                                                                                  at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:154)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
                                                                               Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
                                                                               Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
                                                                               Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.quintabi.facchini.myshop-2/base.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.quintabi.facchini.myshop-2/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.quintabi.facchini.myshop-2/lib/arm, /system/lib, /vendor/lib]]
                                                                                  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                                  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                  at android.view.LayoutInflater.createView(LayoutInflater.java:609)
                                                                                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:964)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
                                                                                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                                  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:994)
                                                                                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:854)
                                                                                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                  at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                                  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                                  at com.quintabi.facchini.myshop.index.onCreate(index.java:25)
                                                                                  at android.app.Activity.performCreate(Activity.java:6672)
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
05-04 23:26:35.467 28017-28017/com.quintabi.facchini.myshop E/AndroidRuntime:     at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                  at android.os.Looper.loop(Looper.java:154)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:6123)
                                                                                  at java.lang.reflect.Method.invoke(Native Method)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)

Build.gradle(项目):

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

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.1'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }

    allprojects {
        repositories {
            jcenter()
        }
    }

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

Build.gradle(模块):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.quintabi.facchini.myshop"
        minSdkVersion 23
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    testCompile 'junit:junit:4.12'
}

Settings.gradle 只是

include ':app'

【问题讨论】:

  • 第二行:表示找不到某个文件。我会先检查一下。
  • 说你没有编译 ConstraintLayout
  • 如果您认为这是导致问题的原因,需要查看您所做的更改并上传您的 gradle 文件
  • @IshaanKumar 我导入然后删除了下载的 .jar 包。您需要哪个 gradle 文件?如您所知,我对 android 完全陌生 .-.
  • build.gradle 和 settings.gradle。您可以通过 Gradle 脚本左侧的 Android 选项卡轻松访问它们

标签: android android-constraintlayout


【解决方案1】:

您可能已更新到 AndroidX 支持库,并且布局引用了旧的 ConstraintLayout 版本。因此,您必须在布局 XML 中将 android.support.constraint.ConstraintLayout 标记更新为 androidx.constraintlayout.widget.ConstraintLayout。

【讨论】:

  • 也解决了我的问题。因为在我的 gradle.properties 文件中 android.useAndroidX=true android.enableJetifier=true 被设置为 true 所以它期待 androidx。组件。
  • 是的!这发生在迁移到 AndroidX 之后。问题解决了。谢谢
  • 是的,这就是解决方案。 Android Studio 没有正确迁移 smh
【解决方案2】:

您之前所做的更改损坏了您的 Gradle 文件(模块一)。 它应该是这样的:

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

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

注意:compile 已过时并替换为“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

【讨论】:

  • 如果它不能解决您的问题。请让我知道,如果不能随意接受这个作为答案:)
【解决方案3】:

使用 androidx.constraintlayout.widget.ConstraintLayout 替换 android.support.constraint.ConstraintLayout,然后就可以了

【讨论】:

    【解决方案4】:

    如果您将项目更新到 Androidx

    然后改变这个依赖。

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

    到

    implementation 'androidx.constraintlayout.widget.ConstraintLayout:1.0.0'
    

    这会起作用。

    【讨论】:

      猜你喜欢
      • 2015-07-01
      • 2014-01-22
      • 1970-01-01
      • 2017-10-21
      • 2018-11-20
      • 1970-01-01
      相关资源
      最近更新 更多