gpt4 book ai didi

android - Kotlin-xmlns :app ="http://schemas.android.com/apk/res-auto" is unavailable

转载 作者:行者123 更新时间:2023-11-29 22:42:57 25 4
gpt4 key购买 nike

我正在关注 kotlin fundamentals code lab在它里面说 API 21 下的任何东西都会将矢量图像转换为 png 图像并防止我需要添加 xmlns:app="http://schemas.android.com/apk/res-auto"activity_main.xml 文件并按 Sync Now,并将 vectorDrawables.useSupportLibrary = true 添加到 defaultConfig { } .gradle(:app) 文件中。我遵循了一切,但我一直收到错误消息:

/Users/Home/IdeaProjects/DiceRoller/app/src/main/res/layout/activity_main.xml:12

error: attribute android:srcCompat not found.

error: failed linking file resources.

我意识到 xmlns:app="http://schemas.android.com/apk/res-auto" 行变灰了

enter image description here

这是我正在使用的 gradle 版本:

dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha18

是什么导致了这个问题?

activity_main.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_vertical"
tools:context=".MainActivity">

<android.support.v7.widget.AppCompatImageView
android:id="@+id/diceImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:srcCompat="@drawable/empty_dice"
tools:src="@drawable/dice_1">
</android.support.v7.widget.AppCompatImageView>

构建:等级(:应用程序)

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.diceroller"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.core:core-ktx:1.2.0-beta02'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}

build.gradle:

buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-alpha18'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()

}
}

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

最佳答案

这是因为srcCompat属性只存在于app中(http://schemas.android.com/apk/res-auto) AppCompatImageView 类的命名空间(参见 API documentation 了解更多信息),而不是默认的 android (http://schemas.android.com/apk/res/android) 命名空间。

要解决此问题,只需将 android:srcCompatandroid 部分重命名为 app:srcCompat:

<android.support.v7.widget.AppCompatImageView 
app:srcCompat="@drawable/empty_dice" />

(附注:考虑自动关闭 XML 标记,这样您就不必编写更多代码来关闭 XML 元素。有关详细信息,请参阅 this question)

关于android - Kotlin-xmlns :app ="http://schemas.android.com/apk/res-auto" is unavailable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58785929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com