Categories
discuss

Build android error at stage app:mergeDebugResources, ParseError AttributeNSNotUnique

I’ve been trying to build my Android Application on Android Studio 4.2 with Gradle 4.2.1, but I am faced with the following error of which I was only able to find one question one month ago, and another one from today which was not solved neither.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
   > Resource compilation failed. Check logs for details.

* Try:
Run with --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeDebugResources'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:200)
    at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:198)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:179)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:109)
    at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
    at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:62)
    ... 12 more
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.res.ResourceCompilerRunnable
    at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:336)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:142)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:94)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForAll(DefaultAsyncWorkTracker.java:80)
    at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:68)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.run(ExecuteActionsTaskExecuter.java:563)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
    at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
    ... 93 more
Caused by: com.android.aaptcompiler.ResourceCompilationException: Resource compilation failed. Check logs for details.
    at com.android.aaptcompiler.ResourceCompiler.compileResource(ResourceCompiler.kt:121)
    at com.android.build.gradle.internal.res.ResourceCompilerRunnable$Companion.compileSingleResource(ResourceCompilerRunnable.kt:31)
    at com.android.build.gradle.internal.res.ResourceCompilerRunnable.run(ResourceCompilerRunnable.kt:15)
    at com.android.build.gradle.internal.profile.ProfileAwareWorkAction.execute(ProfileAwareWorkAction.kt:74)
    at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
    ... 10 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[22,347]
Message: http://www.w3.org/TR/1999/REC-xml-names-19990114#AttributeNSNotUnique?androidx.constraintlayout.widget.ConstraintLayout&layout_width&http://schemas.android.com/apk/res/android
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652)
    at java.xml/com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(XMLEventReaderImpl.java:83)
    at com.android.aaptcompiler.XmlProcessor.process(XmlProcessor.kt:116)
    at com.android.aaptcompiler.ResourceCompiler.compileXml(ResourceCompiler.kt:267)
    at com.android.aaptcompiler.ResourceCompiler.access$compileXml(ResourceCompiler.kt:1)
    at com.android.aaptcompiler.ResourceCompiler$getCompileMethod$2.invoke(ResourceCompiler.kt:143)
    at com.android.aaptcompiler.ResourceCompiler$getCompileMethod$2.invoke(ResourceCompiler.kt)
    at com.android.aaptcompiler.ResourceCompiler.compileResource(ResourceCompiler.kt:118)
    ... 29 more

BUILD FAILED in 2s
17 actionable tasks: 1 executed, 16 up-to-date

Edited: This is my merged AndroidManifest.xml file, it looks like this without dependencies, still the message error remains the same and in the same line [22,347]:

Android Manifest Without Dependencies

I have also taken a look at all my *.xml files, from layouts to values, and android studio has validated them, so I don’t understand the exception.

The part related to the Parse Error:

Message: http://www.w3.org/TR/1999/REC-xml-names-19990114#AttributeNSNotUnique?androidx.constraintlayout.widget.ConstraintLayout&layout_width&http://schemas.android.com/apk/res/android

Makes me think there is something wrong with my layouts, but the IDE says they are fine and render normally.

Dependencies on the build.gradle (previous image shows the manifest after they were commented out):

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])

    // Core
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'androidx.annotation:annotation:1.2.0'

    // Singleton
    implementation group: 'javax.inject', name: 'javax.inject', version: '1'

    // Lifecycle
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

    // UI
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-ui:2.3.5'

    // Room
    implementation 'androidx.room:room-runtime:2.3.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    testImplementation 'junit:junit:4.12'
    annotationProcessor 'androidx.room:room-compiler:2.3.0'

    // Navigation
    implementation 'androidx.navigation:navigation-fragment:2.3.5'

    // Lombok
    compileOnly "org.projectlombok:lombok:1.18.12"
    annotationProcessor "org.projectlombok:lombok:1.18.12"

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'

    // JSON
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

    // Logging
    implementation 'com.jakewharton.timber:timber:4.7.1'
}

Answer

The answer to this question is that the error and the stacktrace are actually two different problems.

There was a problem with one of my xml layouts, yes, but the biggest issue was that the version of gradle 4.2.1 has obfuscated how to find the problem.

So if you want to actually know what is failing, downgrade your gradle to 4.1.3 and gradle will now tell you where your xml is wrong. I recommend this whatever error you have, be it a parse error, a resource error or a prolog error.

Now, for the actual exception, Android Studio does not detect when an attribute is duplicated between the <layout> tag and another different layout, like constraintLayout, frameLayout, etc… so if you are using databinding, check that any extra layouts you are using don’t have the same attribute. In fact I just recommend moving any attributes to your second, implementation specific layout and leave the databinding tag alone.

Categories
discuss

Why does JS desctructuring assignment work with numbers

As the title says, why does this code not throw a SyntaxError? I thought you could only destructure Objects

const {
  a,
  b
} = 0;

console.log(a, b); // undefined, undefined

Answer

When you access a property of a primitive, the primitive’s object wrapper is used to see if such a property exists on the prototype. For example, Number.prototype.toFixed exists. So you could theoretically do something like

const {
  toFixed
} = 0;

console.log(toFixed);

or

Number.prototype.a = 'foo'; // just for example, please never do this
Number.prototype.b = 'bar';

const {
  a,
  b
} = 0;

console.log(a, b);

It’s not invalid syntax, it’s just really weird.

Categories
discuss

use getStaticProps in component

i started a project with nextjs and typescript.i have a main component that i call it in index.js page i use getStaticProps function in main componet getStaticProps return a props and when i log props in my main component i recieved undifined in my console. i want to know if using the getStaticProps is wrong and I have to just use that function in pages or not. i am newbie in next js and I would be very grateful if anyone could help me.

this is my main component

import React from 'react';
import {IMain} from "../../../../interfaces/components/IMenu/IMain";

const Main:React.FC<IMain> = (props) => {
    console.log(props);
    return (
        <div>
        </div>
    );
};


export async function getServerSideProps() {
    return {
        props: {
            data: 'gg'
        }
    };
}

export default Main;

and this is my index.js page

import Text from "./../components/ui/Text/Text";
import Button from "../components/ui/Button/Button";
import Main from "../components/Menu/Desktop/Main/Main";

const Home = () => {
  return <Main/>;
};




export default Home;

Answer

getStaticProps can only be exported from a page. You can’t export it from non-page files.It will not work if you add getStaticProps as a property of the page component.

https://nextjs.org/docs/basic-features/data-fetching#only-allowed-in-a-page

Categories
discuss

How can I create a table in Jetpack Compose?

I want to create table views, like the one below, to show the data I have.

A header Another header
First row
Second row

I tried using LazyVerticalGrid to achieve it but Jetpack Compose doesn’t allow me to put LazyVerticalGrid inside a vertically scrollable Column.

It’s been two days and I’m really out of idea. Please help.

Answer

As far as I know, there’s no built-in component to that. But it’s actually easy to do it with LazyColumn and using the same weight for all lines of the same column.
See this example:

First, you can define a cell for your table:

@Composable
fun RowScope.TableCell(
    text: String,
    weight: Float
) {
    Text(
        text = text,
        Modifier
            .border(1.dp, Color.Black)
            .weight(weight)
            .padding(8.dp)
    )
}

Then you can use it to build your table:

@Composable
fun TableScreen() {
    // Just a fake data... a Pair of Int and String
    val tableData = (1..100).mapIndexed { index, item ->
        index to "Item $index" 
    }
    // Each cell of a column must have the same weight. 
    val column1Weight = .3f // 30%
    val column2Weight = .7f // 70%
    // The LazyColumn will be our table. Notice the use of the weights below
    LazyColumn(Modifier.fillMaxSize().padding(16.dp)) {
        // Here is the header
        item {
            Row(Modifier.background(Color.Gray)) {
                TableCell(text = "Column 1", weight = column1Weight)
                TableCell(text = "Column 2", weight = column2Weight)
            }
        }
        // Here are all the lines of your table.
        items(tableData) {
            val (id, text) = it
            Row(Modifier.fillMaxWidth()) {
                TableCell(text = id.toString(), weight = column1Weight)
                TableCell(text = text, weight = column2Weight)
            }
        }
    }
}

Here is the result:

enter image description here

Categories
discuss

App update constantly rejected by PlayStore for MANAGE_EXTERNAL_STORAGE permission and app description is also not updating

My app helps users to manage whatsapp stickers link to app and it supports SDK30 in first release but after that release now when I am trying to update new version of app playstore sent me app status rejected, I tried multiple times, I’ve mentioned the cause for the permission in app description and even in app while asking for the permission, but neither my app is updating nor my app’s short and long description are updating.
I have filled the Sensitive permission form too, whenever I try to release new version google send me

Publishing Status App Status: Rejected

Your app has been rejected and wasn’t published due to a policy
violation. If you submitted an update, the previous version of your
app is still available on Google Play.

Issue: Access to device storage not required

The feature you identified does not require unrestricted access to
device storage. There are other privacy friendly options for accessing
files in shared storage, such as using the system file picker, or,
depending on the use case, you can follow the recommendations for
receiving data from other apps listed here.

Please update your app so that the feature uses a privacy friendly
alternative and remove All Files Access (MANAGE_EXTERNAL_STORAGE)
permission.

Policy: All Files Access Permission

Files and directory attributes on a user’s device are regarded as
personal and sensitive user data subject to the Personal and Sensitive
Information policy and the following requirements:

Apps should only request access to device storage which is critical
for the app to function, and may not request access to device storage
on behalf of any third-party for any purpose that is unrelated to
critical user-facing app functionality. Android devices running
Android “R” (Android 11) or later, will require the
MANAGE_EXTERNAL_STORAGE permission in order to manage access in shared
storage. All apps that target R or later and request broad access to
shared storage (“All files access”) must successfully pass an
appropriate access review prior to publishing. Apps allowed to use
this permission must clearly prompt users to enable “All files access”
for their app under “Special app access” settings. For more
information on the R requirements, please see this help article.

Read more about Use of All Files Access Permission See Android storage
use cases and best practices and how to open files using storage
access framework Address this issue in the Play Console. Issue: Not
a core feature

The feature you identified that is dependent on this permission does
not appear to be critical to the core functionality of your app.

Core functionality is defined as the main purpose of the app. Without
this core functionality, the app is “broken” or rendered unusable. The
core functionality, as well as any core features that comprise this
core functionality, must all be prominently documented and promoted in
the app’s description.

Please update your app so that the feature does not use this
permission or ensure that the core functionality is prominently
documented and promoted in the app’s description and resubmit your app
on Play Developer console.

Policy: All Files Access Permission

Files and directory attributes on a user’s device are regarded as
personal and sensitive user data subject to the Personal and Sensitive
Information policy and the following requirements:

Apps should only request access to device storage which is critical
for the app to function, and may not request access to device storage
on behalf of any third-party for any purpose that is unrelated to
critical user-facing app functionality. Android devices running
Android “R” (Android 11) or later, will require the
MANAGE_EXTERNAL_STORAGE permission in order to manage access in shared
storage. All apps that target R or later and request broad access to
shared storage (“All files access”) must successfully pass an
appropriate access review prior to publishing. Apps allowed to use
this permission must clearly prompt users to enable “All files access”
for their app under “Special app access” settings. For more
information on the R requirements, please see this help article.

Read more about Use of All Files Access Permission See Android storage
use cases and best practices Address this issue in the Play Console.
Issue: Need to use Media Store API

You have requested access to All Files Access permission but it
appears that your app’s core feature requires access to only Media
Files. With the MediaStore API, apps can contribute and access media
that’s available on an external storage volume without the need for
the access all files permission.

Please update your app so that the feature uses Media Store APIs and
remove All Files Access (MANAGE_EXTERNAL_STORAGE) permission.

Policy: All Files Access Permission

Files and directory attributes on a user’s device are regarded as
personal and sensitive user data subject to the Personal and Sensitive
Information policy and the following requirements:

Apps should only request access to device storage which is critical
for the app to function, and may not request access to device storage
on behalf of any third-party for any purpose that is unrelated to
critical user-facing app functionality. Android devices running
Android “R” (Android 11) or later, will require the
MANAGE_EXTERNAL_STORAGE permission in order to manage access in shared
storage. All apps that target R or later and request broad access to
shared storage (“All files access”) must successfully pass an
appropriate access review prior to publishing. Apps allowed to use
this permission must clearly prompt users to enable “All files access”
for their app under “Special app access” settings. For more
information on the R requirements, please see this help article.

Read more about Use of All Files Access Permission See Android storage
use cases and best practices and how to access media files from shared
storage Address this issue in the Play Console.

Answer

After lots of struggle and research I decided to reduced target SDK version to 29 and post the update for my app and I was able to post updates and surprisingly it updated for sdk 30 too, If you’re facing the same issue, just change target sdk to 29 and keep compile sdk to 30, try it, It worked for me maybe it will work for you too. Maybe it’s a loophole in google’s system but it worked for me.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..