尝试使用ConstraintLayout时出现错误:没有枚举常量com.android.manifmerger.AttributeOperationType.CONTEXT.
enter image description here
下面是我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">
<EditText
android:id="@+id/inputFirstName"
android:layout_width="398dp"
android:layout_height="47dp"
android:layout_margin="10dp"
android:layout_marginEnd="188dp"
android:layout_marginBottom="21dp"
android:hint="Enter your first name"
android:minHeight="48dp"
app:layout_constraintBottom_toTopOf="@+id/inputLastName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.848" />
<EditText
android:id="@+id/inputLastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="135dp"
android:hint="Enter your last name"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btnUploadData"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="56dp"
android:layout_marginEnd="8dp"
android:text="@string/save_data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/inputLastName" />
<Button
android:id="@+id/btnReadData"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="8dp"
android:text="@string/retrieve_data"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnUploadData"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textViewResultTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="104dp"
android:layout_marginTop="43dp"
android:text="FireStore data :"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnReadData" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:text=""
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewResultTitle"
app:layout_constraintVertical_bias="0.081" />
</androidx.constraintlayout.widget.ConstraintLayout>
当我尝试使用ConstraintLayout时,我删除了一个并将其改为
这是我在论坛上找到的。它不起作用,所以我决定返回,并把它“androidx.constraintlayout.widget.constraintLayout”,但它也给了我一个错误。所以我不知道如何修复它。也许是因为我的xml文件在manifest文件夹:enter image description hereHere is my dependencies in build.gradle (:app):
构建.gradle(:应用程序)文件
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}
android {
namespace 'com.example.myapplication'
compileSdk 32
defaultConfig {
applicationId "com.example.myapplication"
minSdk 19
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-firestore-ktx:24.1.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// To use constraintlayout in compose
implementation("androidx.constraintlayout:constraintlayout-compose:1.0.1")
}
1条答案
按热度按时间xqk2d5yq1#
根据您的屏幕截图,您已经将
AndroidManifest.xml
的内容替换为layout XML。该文件非常重要,如果您尝试构建而没有有效的文件,将会出现各种错误!您需要将其还原,然后为尝试使用的布局XML创建一个布局文件(在
res/layout
文件夹中