hem hem - 4 months ago 18
Android Question

when I generated signed apk got error Error:(57) Error parsing XML: duplicate attribute in cardview?

I don't how to solve this Its showed in many activity same error.
How to Resolve this Error.

Like this error for many activity first line in cardview. Duplicate in the sense for same cardview used in mamy activity, so that's why don't know.

Thanks in Advance.

xml:



<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:descendantFocusability="blocksDescendants"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardBackgroundColor="@color/myTextPrimaryColor"
card_view:cardCornerRadius="10dp"
app:cardUseCompatPadding="true"
card_view:cardElevation="1dp"
card_view:cardUseCompatPadding="true"
android:id="@+id/cv"
>



<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">

<ImageView
android:layout_width="130dp"
android:layout_height="120dp"
android:layout_weight="0"
android:id="@+id/pimage"
android:src="@drawable/sliper"
android:focusable = "false"
android:focusableInTouchMode = "false"
android:layout_marginTop="15dp"
android:layout_marginRight="10dp" />

<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/itemname"
android:textColor="@color/myNavigationColor"
android:id="@+id/itemname"
android:layout_marginTop="20dp"
android:textStyle="bold"
android:paddingRight="10dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="balck, 16gb"
android:textColor="@color/myNavigationColor"
android:id="@+id/aliasname"
android:layout_marginTop="10dp"
android:textStyle="bold" />

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="@string/itemamount"
android:textColor="@color/myNavigationColor"
android:id="@+id/wishselling"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:text="@string/eixstingamt"
android:textColor="@color/darkhash"
android:id="@+id/wishmrp"
android:layout_marginLeft="5dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"


android:id="@+id/wishoffer"
android:layout_marginLeft="5dp"
android:textColor="@color/WishTextColor"
android:textStyle="bold" />
</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">

<RatingBar
android:id="@+id/rtbProductRating"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:numStars="5"
android:rating="3"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:isIndicator="true"
android:theme="@style/RatingBar"
style="?android:attr/ratingBarStyleSmall" />
<!-- <RatingBar android:id="@+id/ratingBar1"
style="@style/foodRatingBar"

android:layout_width="wrap_content"
android:layout_height="wrap_content">

</RatingBar> -->

<!-- style="@style/foodRatingBar" style="@style/foodRatingBar"-->



<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/rating"
android:textColor="@color/darkhash"
android:id="@+id/ratingtxt"

android:layout_marginLeft="15dp" />
</LinearLayout>

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="15dp">

<ImageButton
android:layout_width="25dp"
android:layout_height="25dp"
android:id="@+id/likes"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:background="@drawable/ic_delete_sweep_black_24dp"
android:layout_gravity="right"
android:layout_marginRight="15dp" />


</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>

</LinearLayout>


Manifest:

C: \Users\ admin\ AndroidStudioProjects\ shoppingdrawer\ app\ src\ main\ res\ layout\ activity_address__edit.xml
Error: (57) Error parsing XML: duplicate attribute
C: \Users\ admin\ AndroidStudioProjects\ shoppingdrawer\ app\ src\ main\ res\ layout\ activity_address_edit_.xml
Error: (56) Error parsing XML: duplicate attribute
C: \Users\ admin\ AndroidStudioProjects\ shoppingdrawer\ app\ src\ main\ res\ layout\ activity_delivery_.xml
Error: (52) Error parsing XML: duplicate attribute
C: \Users\ admin\ AndroidStudioProjects\ shoppingdrawer\ app\ src\ main\ res\ layout\ activity_delivery_2.xml
Error: (52) Error parsing XML: duplicate attribute
C: \Users\ admin\ AndroidStudioProjects\ shoppingdrawer\ app\ src\ main\ res\ layout\ addressdiplayrow.xml
Error: (9) Error parsing XML: duplicate attribute
C: \Users\ admin\ AndroidStudioProjects\ shoppingdrawer\ app\ src\ main\ res\ layout\ wishitemsrow.xml
Error: (12) Error parsing XML: duplicate attribute
Error: Execution failed
for task ':app:processReleaseResources'. >
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '
C: \Users\ admin\ AppData\ Local\ Android\ sdk\ build - tools\ 23.0 .3\ aapt.exe ''
finished with non - zero exit value 1
Information: BUILD FAILED

Answer

The problem is these two lines:

    app:cardUseCompatPadding="true"
    card_view:cardUseCompatPadding="true"

Remove either one of those and it'll be fixed.

Explanation: Even though these two lines seem to be different, they're actually the same, because if you look at this:

xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"

These two namespaces are declared as the same one, which effectively means that these two refer to the same thing, and thus declaring the same attribute twice makes it a duplicate, which is not allowed.