【问题标题】:Android Studio cannot initiate the constraint layoutAndroid Studio 无法启动约束布局
【发布时间】:2019-02-19 10:12:19
【问题描述】:

[在此处输入图片描述]

在右上角,缩放按钮旁边会出现一个蓝色警告,基本上是:

未能启动一门或多门课程

以下类无法实例化:

  • android.support.constraint.ConstraintLayout

带有异常详情:

异常详情 java.lang.NoClassDefFoundError: android/support/constraint/R$styleable android.support.constraint.ConstraintLayout.init(ConstraintLayout.java:599) android.support.constraint.ConstraintLayout.(ConstraintLayout.java:576 ) java.lang.reflect.Constructor.newInstance(Constructor.java:423) android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) android.view.LayoutInflater.inflate(LayoutInflater.java:492) android.view.LayoutInflater.inflate(LayoutInflater.java:394)

还有activity_main.xml的文本格式

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

在 tools:context=".MainActivity" 行上,.MainActivity 以红色显示“Unresolved class MainActivity”

这是我的 AndroidManifest.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.kaan.asd">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

我是 Android Studio 的新手,我已经尝试解决这个问题很长一段时间了,我尝试过清除缓存、清理/重建项目,但都没有解决我的问题。 我在 Windows 上使用带有 4.10.1 gradle 版本的 Android Studio 3.3.1 版本。 如果有人能帮我解决它,我会很高兴的。

【问题讨论】:

  • 您使用的是新的 mdc 还是支持库?

标签: android android-studio android-layout android-constraintlayout


【解决方案1】:

你必须在android目录中添加约束布局的存储库:app/build.gradle如下:

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

然后同步您的项目并享受这个完美的布局。

【讨论】:

  • 感谢您的建议,我在依赖项标签下的 app/build.gradle 中添加了您给出的行,但我仍然遇到同样的问题并出现同样的错误。
  • 我不知道我是否应该将它添加到另一个标签下
  • @KaanAlgan 可以进入文件 -> 无效/缓存 --> 无效并重新启动
  • @Aadit33 我通过重新安装 Android Studio 修复了它,它工作正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-16
  • 2017-08-03
  • 1970-01-01
  • 2017-06-05
  • 2016-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多