Home > Net >  Android Material Design values.xml errors
Android Material Design values.xml errors

Time:04-19

I am creating an app with AppCompatActivity.

I use implementation 'com.google.android.material:material:1.3.0' in my build.gradle to use Material Design but I always receiving these errors:

aapt: Attribute "android:alpha" has already been defined

aapt: Attribute "android:translationX" has already been defined

aapt: Attribute "android:translationY" has already been defined

aapt: Attribute "android:translationZ" has already been defined

build.gradle files:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21

    defaultConfig {
        applicationId "com.dlv.mydiary"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.material:material:1.3.0'
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

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

allprojects {
    repositories {
        jcenter()
        google()
    }
}

I removed 3 declare-styleable as it's caused an error but it's getting worst.

Image Errors

Do you know how to fix this problem? Thanks!

CodePudding user response:

check if you do not use the same attributes names. So check all youre libraries.

CodePudding user response:

update to compile version 29, you are on 210this might help you

CodePudding user response:

This can occur if multiple tags do the same thing.
Like how an src and icon tag can be the same thing. If you use both within the same tag, it would give an error.
example-

<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:fitsSystemWindows="true"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".ui.AboutFragment">

</LinearLayout>

here, as you can see, the android:fitsSystemWindows and android:layout_height both define how the layout fits to the screen. So, that is what causes the already defined errors.

Also, please explain why are the errors on a screenshot of an android device giving code errors. I'm sure many others have the same question.

  • Related