简体   繁体   English

Kotlin- xmlns:app="http://schemas.android.com/apk/res-auto" 不可用

[英]Kotlin- xmlns:app=“http://schemas.android.com/apk/res-auto” is unavailable

I'm following the kotlin fundamentals code lab and in it it says that anything under API 21 will convert vector images to png images and to prevent that I need to add xmlns:app="http://schemas.android.com/apk/res-auto" to the activity_main.xml file and press Sync Now , and add vectorDrawables.useSupportLibrary = true to the defaultConfig { } in the .gradle(:app ) file.我正在关注kotlin 基础代码实验室,其中说 API 21 下的任何内容都会将矢量图像转换为 png 图像并防止我需要添加xmlns:app="http://schemas.android.com/apk/res-auto"activity_main.xml文件并按下Sync Now ,然后将vectorDrawables.useSupportLibrary = true添加到.gradle(:app ) 文件中的defaultConfig { }中。 I followed everything but I kept getting an error:我跟着一切,但我一直得到一个错误:

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

error: attribute android:srcCompat not found.错误:属性 android:srcCompat 未找到。

error: failed linking file resources.错误:链接文件资源失败。

I realized that the xmlns:app="http://schemas.android.com/apk/res-auto" line is grayed out我意识到xmlns:app="http://schemas.android.com/apk/res-auto"行是灰色的

在此处输入图像描述

This is the gradle version I'm using:这是我正在使用的 gradle 版本:

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

What is causing this problem?是什么导致了这个问题?

activity_main.xml file: 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>

build:grade(:app)构建:等级(:应用程序)

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

This is because the srcCompat attribute only exists in the app ( http://schemas.android.com/apk/res-auto ) namespace for the AppCompatImageView class (see the API documentation for more info), not the default android ( http://schemas.android.com/apk/res/android ) namespace. This is because the srcCompat attribute only exists in the app ( http://schemas.android.com/apk/res-auto ) namespace for the AppCompatImageView class (see the API documentation for more info), not the default android ( http://schemas.android.com/apk/res/android )命名空间。

To fix this, simply rename the android portion of android:srcCompat to app:srcCompat :要解决此问题,只需将android:srcCompatandroid部分重命名为app:srcCompat

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

(PS Consider self-closing the XML tag such that you don't have to write more code to close the XML element. See this question for more info) (PS 考虑自动关闭 XML 标签,这样您就不必编写更多代码来关闭 XML 元素。有关更多信息,请参阅此问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 什么是xmlns:app =“ http://schemas.android.com/apk/res-auto中的app:overlayImage? - What is app:overlayImage in xmlns:app="http://schemas.android.com/apk/res-auto? android xml 文件中像 xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot; 这样的行的含义是什么? - What is the meaning of such lines like xmlns:app="http://schemas.android.com/apk/res-auto" in android xml file? “即使在使用命名空间http://schemas.android.com/apk/res-auto后,也找不到属性&#39;错误的资源标识符 - 'No resource identifier found for attribute' error even after using namespace http://schemas.android.com/apk/res-auto 在库项目中使用自定义名称空间属性时,请使用名称空间“ http://schemas.android.com/apk/res-auto”代替 - when using a custom namespace attribute in a library project, use the namespace “http://schemas.android.com/apk/res-auto” instead <menu xmlns:android=“http://schemas.android.com/apk/res/android”></menu>出现在main.xml中 - <menu xmlns:android=“http://schemas.android.com/apk/res/android”></menu> appears in main.xml xmlns:android =“ http://schemas.android.com/apk/res/android”,此行在线性布局中被标记为错误 - xmlns:android=“http://schemas.android.com/apk/res/android” this line is marked as error in Linear Layout 如何访问 http://schemas.android.com/apk/res/android? - how to access http://schemas.android.com/apk/res/android? 该位置没有XML:http://schemas.android.com/apk/res/android - No XML at the location: http://schemas.android.com/apk/res/android uri 未注册 http://schemas.android.com/apk/res/android - uri is not registered http://schemas.android.com/apk/res/android xmlns:android =“http://schemas.android.com/apk/res/android”被添加到我的所有布局对象中导致错误 - xmlns:android=“http://schemas.android.com/apk/res/android” gets added to all my layout objects causing errors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM