问:
I am compiling an e-commerce application, but I am getting the following errors in the gradle console
I am compiling an e-commerce application, but I am getting the following errors in the gradle console:

```<code> at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
 at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
 at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
 at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
 at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
 at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
 at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
 at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
 at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
 at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
 at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
 at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
 at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
 at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
 at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
 at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
 at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
 at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
 at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
 at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
 at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
 at java.lang.Thread.run(Thread.java:748)
 Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
 java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)

 Go to the documentation to learn how to Fix dependency resolution errors.

 at com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:108)
 at com.android.build.gradle.internal.tasks.CheckDuplicateClassesDelegate.run(CheckDuplicateClassesDelegate.kt:67)
 at com.android.build.gradle.internal.tasks.CheckDuplicateClassesTask.doTaskAction(CheckDuplicateClassesTask.kt:61)
 at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:51)
 at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:31)
 at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:91)
 at com.android.build.gradle.internal.tasks.NonIncrementalTask.taskAction(NonIncrementalTask.kt:34)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:48)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:41)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
 at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:702)
 at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:669)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$5.run(ExecuteActionsTaskExecuter.java:404)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
 at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:393)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:376)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:80)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:213)
 at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$1(ExecuteStep.java:33)
 at java.util.Optional.orElseGet(Optional.java:267)
 at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:33)
 at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
 at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:58)
 at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35)
 at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
 at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:33)
 at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:39)
 at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
 at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
 at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:35)
 at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
 at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:45)
 at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:31)
 at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:201)
 at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:70)
 at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:45)
 at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
 at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:43)
 at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:32)
 at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
 at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
 at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
 at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
 at java.util.Optional.map(Optional.java:215)
 at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54)
 at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
 at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:77)
 at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
 at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
 at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
 at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:90)
 at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:48)
 at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:120)
 ... 38 more
 Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)

 Go to the documentation to learn how to Fix dependency resolution errors.
 at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
 at com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:102)
 ... 102 more
 Caused by: java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)

 Go to the documentation to learn how to Fix dependency resolution errors.
 at com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable.run(CheckDuplicateClassesDelegate.kt:128)
 at com.android.ide.common.workers.ExecutorServiceAdapter$submit$submission$1.run(ExecutorServiceAdapter.kt:68)
 at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
 at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
 at java.util.concurrent.ForkJoinTask.externalInterruptibleAwaitDone(ForkJoinTask.java:361)
 at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1001)
 ... 103 more

</code>```

below my build.gradle

```<code>```
    buildscript {
repositories {
    maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
    classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.3'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
maven { url 'https://maven.google.com' }
}

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
defaultConfig {
    applicationId 'br.com.coalaresolve.appvale'

    manifestPlaceholders = [onesignal_app_id: "ad359056-018a-4db5-ae4f-915e177adf87",
                            // Project number pulled from dashboard, local value is ignored.
                            onesignal_google_project_number: "REMOTE"]

    minSdkVersion 18
    targetSdkVersion 29
    versionCode 7
    versionName '3.1.0'
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
}
compileOptions {
    sourceCompatibility = 1.8
    targetCompatibility = 1.6
}
buildToolsVersion = '28.0.3'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-core:17.2.2'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.onesignal:OneSignal:3.12.6'
implementation 'com.karumi:dexter:6.0.2'
}

apply plugin: 'com.google.gms.google-services'
```

<p>Whenever I am going to compose this error it is presented to me, I have already installed AndroidStudio on another machine but it continues to present the error message, I no longer know what to do.</p>

<p><strong>New Error:</strong></p>

```org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
...

Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:52)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:36)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:100)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:52)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
at org.gradle.api.internal.tasks.compile.AnnotationProcessorDiscoveringCompiler.execute(AnnotationProcessorDiscoveringCompiler.java:51)
at org.gradle.api.internal.tasks.compile.AnnotationProcessorDiscoveringCompiler.execute(AnnotationProcessorDiscoveringCompiler.java:37)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:39)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilerFactory$2.execute(IncrementalCompilerFactory.java:110)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilerFactory$2.execute(IncrementalCompilerFactory.java:106)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalResultStoringCompiler.execute(IncrementalResultStoringCompiler.java:60)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalResultStoringCompiler.execute(IncrementalResultStoringCompiler.java:44)
at org.gradle.api.internal.tasks.compile.CompileJavaBuildOperationReportingCompiler$2.call(CompileJavaBuildOperationReportingCompiler.java:59)
at org.gradle.api.internal.tasks.compile.CompileJavaBuildOperationReportingCompiler$2.call(CompileJavaBuildOperationReportingCompiler.java:51)

... 38 more
```

答:
I did what you asked and remove </p>

```<code>    sourceCompatibility = 1.8 targetCompatibility = 1.6 }
    buildToolsVersion = '28.0.3'

deverything went ok. Thank you very much, it was of great value for your help.
</code>```

Body:
I am compiling an e-commerce application, but I am getting the following errors in the gradle console:

 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
 at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
 at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
 at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
 at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
 at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
 at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
 at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
 at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
 at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
 at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
 at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
 at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
 at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
 at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
 at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:416)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$CallableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:406)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:102)
 at org.gradle.internal.operations.DelegatingBuildOperationExecutor.call(DelegatingBuildOperationExecutor.java:36)
 at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:49)
 at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:43)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:355)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:343)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:336)
 at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:322)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:134)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker$1.execute(DefaultPlanExecutor.java:129)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:202)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.executeNextNode(DefaultPlanExecutor.java:193)
 at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
 at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
 at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
 at java.lang.Thread.run(Thread.java:748)
 Caused by: com.android.ide.common.workers.WorkerExecutorException: 1 exception was raised by workers:
 java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)

 Go to the documentation to learn how to Fix dependency resolution errors.

 at com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:108)
 at com.android.build.gradle.internal.tasks.CheckDuplicateClassesDelegate.run(CheckDuplicateClassesDelegate.kt:67)
 at com.android.build.gradle.internal.tasks.CheckDuplicateClassesTask.doTaskAction(CheckDuplicateClassesTask.kt:61)
 at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:51)
 at com.android.build.gradle.internal.tasks.NonIncrementalTask$taskAction$$inlined$recordTaskAction$1.invoke(AndroidVariantTask.kt:31)
 at com.android.build.gradle.internal.tasks.Blocks.recordSpan(Blocks.java:91)
 at com.android.build.gradle.internal.tasks.NonIncrementalTask.taskAction(NonIncrementalTask.kt:34)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:48)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:41)
 at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:28)
 at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:702)
 at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:669)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$5.run(ExecuteActionsTaskExecuter.java:404)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:394)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor$1.execute(DefaultBuildOperationExecutor.java:165)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:250)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:158)
 at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:92)
 at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:393)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:376)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.access$200(ExecuteActionsTaskExecuter.java:80)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$TaskExecution.execute(ExecuteActionsTaskExecuter.java:213)
 at org.gradle.internal.execution.steps.ExecuteStep.lambda$execute$1(ExecuteStep.java:33)
 at java.util.Optional.orElseGet(Optional.java:267)
 at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:33)
 at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:26)
 at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:58)
 at org.gradle.internal.execution.steps.CleanupOutputsStep.execute(CleanupOutputsStep.java:35)
 at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
 at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:33)
 at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:39)
 at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:73)
 at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:54)
 at org.gradle.internal.execution.steps.CatchExceptionStep.execute(CatchExceptionStep.java:35)
 at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
 at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:45)
 at org.gradle.internal.execution.steps.SnapshotOutputsStep.execute(SnapshotOutputsStep.java:31)
 at org.gradle.internal.execution.steps.CacheStep.executeWithoutCache(CacheStep.java:201)
 at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:70)
 at org.gradle.internal.execution.steps.CacheStep.execute(CacheStep.java:45)
 at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:49)
 at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:43)
 at org.gradle.internal.execution.steps.StoreSnapshotsStep.execute(StoreSnapshotsStep.java:32)
 at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:38)
 at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:24)
 at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:96)
 at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$0(SkipUpToDateStep.java:89)
 at java.util.Optional.map(Optional.java:215)
 at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54)
 at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
 at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:77)
 at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:37)
 at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:36)
 at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:26)
 at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:90)
 at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:48)
 at org.gradle.internal.execution.impl.DefaultWorkExecutor.execute(DefaultWorkExecutor.java:33)
 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:120)
 ... 38 more
 Caused by: java.util.concurrent.ExecutionException: java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)

 Go to the documentation to learn how to Fix dependency resolution errors.
 at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1006)
 at com.android.ide.common.workers.ExecutorServiceAdapter.await(ExecutorServiceAdapter.kt:102)
 ... 102 more
 Caused by: java.lang.RuntimeException: Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)
 Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.1.0-runtime.jar (androidx.core:core:1.1.0) and support-compat-26.0.0-runtime.jar (com.android.support:support-compat:26.0.0)

 Go to the documentation to learn how to Fix dependency resolution errors.
 at com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable.run(CheckDuplicateClassesDelegate.kt:128)
 at com.android.ide.common.workers.ExecutorServiceAdapter$submit$submission$1.run(ExecutorServiceAdapter.kt:68)
 at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
 at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
 at java.util.concurrent.ForkJoinTask.externalInterruptibleAwaitDone(ForkJoinTask.java:361)
 at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1001)
 ... 103 more

below my build.gradle

    buildscript {
repositories {
    maven { url 'https://plugins.gradle.org/m2/'}
}
dependencies {
    classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.3'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
maven { url 'https://maven.google.com' }
}

apply plugin: 'com.android.application'

android {
compileSdkVersion 29
defaultConfig {
    applicationId 'br.com.coalaresolve.appvale'

    manifestPlaceholders = [onesignal_app_id: "ad359056-018a-4db5-ae4f-915e177adf87",
                            // Project number pulled from dashboard, local value is ignored.
                            onesignal_google_project_number: "REMOTE"]

    minSdkVersion 18
    targetSdkVersion 29
    versionCode 7
    versionName '3.1.0'
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
productFlavors {
}
compileOptions {
    sourceCompatibility = 1.8
    targetCompatibility = 1.6
}
buildToolsVersion = '28.0.3'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.balysv:material-ripple:1.0.2'
implementation 'com.github.clans:fab:1.6.4'
implementation 'com.google.firebase:firebase-messaging:20.1.0'
implementation 'com.google.firebase:firebase-core:17.2.2'
implementation 'com.android.volley:volley:1.1.1'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.onesignal:OneSignal:3.12.6'
implementation 'com.karumi:dexter:6.0.2'
}

apply plugin: 'com.google.gms.google-services'

Whenever I am going to compose this error it is presented to me, I have already installed AndroidStudio on another machine but it continues to present the error message, I no longer know what to do.

New Error:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionStateTaskExecuter.execute(ResolveBeforeExecutionStateTaskExecuter.java:75)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:108)
at org.gradle.api.internal.tasks.execution.ResolveBeforeExecutionOutputsTaskExecuter.execute(ResolveBeforeExecutionOutputsTaskExecuter.java:67)
at org.gradle.api.internal.tasks.execution.ResolveAfterPreviousExecutionStateTaskExecuter.execute(ResolveAfterPreviousExecutionStateTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:94)
at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:95)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:56)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:73)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:49)
...

Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:52)
at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:36)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:100)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:52)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
at org.gradle.api.internal.tasks.compile.AnnotationProcessorDiscoveringCompiler.execute(AnnotationProcessorDiscoveringCompiler.java:51)
at org.gradle.api.internal.tasks.compile.AnnotationProcessorDiscoveringCompiler.execute(AnnotationProcessorDiscoveringCompiler.java:37)
at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:39)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilerFactory$2.execute(IncrementalCompilerFactory.java:110)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalCompilerFactory$2.execute(IncrementalCompilerFactory.java:106)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalResultStoringCompiler.execute(IncrementalResultStoringCompiler.java:60)
at org.gradle.api.internal.tasks.compile.incremental.IncrementalResultStoringCompiler.execute(IncrementalResultStoringCompiler.java:44)
at org.gradle.api.internal.tasks.compile.CompileJavaBuildOperationReportingCompiler$2.call(CompileJavaBuildOperationReportingCompiler.java:59)
at org.gradle.api.internal.tasks.compile.CompileJavaBuildOperationReportingCompiler$2.call(CompileJavaBuildOperationReportingCompiler.java:51)

... 38 more

Body:
I did what you asked and remove

    sourceCompatibility = 1.8 targetCompatibility = 1.6 }
    buildToolsVersion = '28.0.3'

deverything went ok. Thank you very much, it was of great value for your help.


来源: stackexchange

问:
How to force cp to overwrite without confirmation
I'm trying to use the cp command and force an overwrite.

I have tried cp -rf /foo/* /bar, but I am still prompted to confirm each overwrite.

答:
So I run into this a lot because I keep cp aliased to cp -iv, and I found a neat trick. It turns out that while -i and -n both cancel previous overwrite directives, -f does not. However, if you use -nf it adds the ability to clear the -i. So:

```<code>cp -f /foo/* /bar  <-- Prompt
cp -nf /foo/* /bar <-- No Prompt
</code>```

Pretty neat huh? /necropost

ContentLicense: CC BY-SA 3.0

Body:
So I run into this a lot because I keep cp aliased to cp -iv, and I found a neat trick. It turns out that while -i and -n both cancel previous overwrite directives, -f does not. However, if you use -nf it adds the ability to clear the -i. So:

cp -f /foo/* /bar  <-- Prompt
cp -nf /foo/* /bar <-- No Prompt

Pretty neat huh? /necropost

ContentLicense: CC BY-SA 4.0


问:
Using fixtures with Stripe CLI
I want to test my API behaviour by triggering some specific requests using Stripe CLI.

For example:

stripe trigger customer.subscription.deleted # with some fixture here

There is a fixtures command documented as a feature but I do not know how to use it. The documentation says:

The fixtures command lets you run a json file as a series of API
  requests. This can be useful for things like filling data, executing
  specific flows, or testing API behavior.

https://github.com/stripe/stripe-cli/wiki/fixtures-command

How do I load fixtures into the CLI?

答:
The first step is to create a JSON file with the fixtures in it. The documentation you linked to gives one such example, but it may make it easier for you to get started if you:

Find the closest available trigger to what you want to do

Locate the corresponding fixture file in the repo

Modify it to suit your needs

You can then execute the fixture with stripe fixtures name_of_your_fixture_file.json

You can look up available triggers in the trigger documentation. Remember that fixtures are just going to make a series of API requests, with each object in the fixtures array representing one API call, so you can do anything specified in the API docs.

Title: Using fixtures with Stripe CLI


问:
c# unexpected backgroundWorker behaviour
I have attached a backgroundWorker component to my main form which runs a parallel task of capturing the screen for an animated gif. The worker's function has a while loop that runs until I use CancelAsync() on the worker, at which point it exits the loop, does some other things like saving the gif file and so on and returns some results to the UI thread.

```<code>private bool capturing = false;

public MainForm()
{
    InitializeComponent();
    backgroundWorker.DoWork += backgroundWorker_DoWork;
    backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
    backgroundWorker.WorkerSupportsCancellation = true;
}

private void captureBtn_Click(object sender, EventArgs e)
{
    Debug.WriteLine("Button clicked");
    if (capturing) { return; }
    if (!backgroundWorker.IsBusy)
    {
        backgroundWorker.RunWorkerAsync();
    }
}

private void stopCaptureBtn_Click(object sender, EventArgs e)
{
    if (backgroundWorker.IsBusy)
    {
        backgroundWorker.CancelAsync();
    }
}

private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
    capturing = true;
    Debug.WriteLine("DoWork running");

    while (!backgroundWorker.CancellationPending)
    {
        Debug.WriteLine("Capturing frame {0}", frames);
        //do the capturing to memory stream
    }

    Debug.WriteLine("DoWork cancelled");

    //do some other things like saving the gif etc
    e.Result = someResult;
}

private void backgroundWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
    Debug.WriteLine("RunWorkerCompleted running");
    capturing = false;
    //does something with the e.Result
}
</code>```

My console output during a normal test is something like this:

```<code>Button clicked
DoWork running
Capturing frame 0
Capturing frame 1
Capturing frame 2
Capturing frame 3
Capturing frame 4
Capturing frame 5
Cancel button clicked
DoWork cancelled
The thread 0x2e4c has exited with code 0 (0x0).
DoWork running
DoWork cancelled
The thread 0x1010 has exited with code 0 (0x0).
RunWorkerCompleted running
</code>```

The function seems to be running twice, I can see 2 separate threads exiting and also I don't seem to get any results from capturing. If I set a breakpoint inside the backgroundWorker_DoWork function and continue later, the first run does the capturing normally. What could be going on?

答:
The thread 0x3108 has exited with code 0 (0x0) means there was no error.
While reading or writing the big data, you should divide it into parts. Otherwise, you cannot progress. Your current while loop is disabled when writing to memory stream.
so your backgroundWorker_DoWork method should be like this :</p>

```<code>    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        var worker = (BackgroundWorker)sender;

        // this is an example file
        string filePath = @"C:\file.gif";

        // it determines how many bytes of data will be received from the stream each time.
        byte[] buffer = new byte[4096];
        int byteCount = 0;

        // we are preparing to read stream.
        using (FileStream fs = new FileStream(filePath, FileMode.Open, System.IO.FileAccess.Read))
        using (MemoryStream ms = new MemoryStream())
        {
            // read the stream bytes and fill buffer
            while ((byteCount = fs.Read(buffer, 0, buffer.Length)) > 0)
            {
                // if the task was canceled
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                // write buffer to memory stream
                ms.Write(buffer, 0, byteCount);
            }
        }
    }
</code>```

Body:
I have attached a backgroundWorker component to my main form which runs a parallel task of capturing the screen for an animated gif. The worker's function has a while loop that runs until I use CancelAsync() on the worker, at which point it exits the loop, does some other things like saving the gif file and so on and returns some results to the UI thread.

private bool capturing = false;

public MainForm()
{
    InitializeComponent();
    backgroundWorker.DoWork += backgroundWorker_DoWork;
    backgroundWorker.RunWorkerCompleted += backgroundWorker_RunWorkerCompleted;
    backgroundWorker.WorkerSupportsCancellation = true;
}

private void captureBtn_Click(object sender, EventArgs e)
{
    Debug.WriteLine("Button clicked");
    if (capturing) { return; }
    if (!backgroundWorker.IsBusy)
    {
        backgroundWorker.RunWorkerAsync();
    }
}

private void stopCaptureBtn_Click(object sender, EventArgs e)
{
    if (backgroundWorker.IsBusy)
    {
        backgroundWorker.CancelAsync();
    }
}

private void backgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
    capturing = true;
    Debug.WriteLine("DoWork running");

    while (!backgroundWorker.CancellationPending)
    {
        Debug.WriteLine("Capturing frame {0}", frames);
        //do the capturing to memory stream
    }

    Debug.WriteLine("DoWork cancelled");

    //do some other things like saving the gif etc
    e.Result = someResult;
}

private void backgroundWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
    Debug.WriteLine("RunWorkerCompleted running");
    capturing = false;
    //does something with the e.Result
}

My console output during a normal test is something like this:

Button clicked
DoWork running
Capturing frame 0
Capturing frame 1
Capturing frame 2
Capturing frame 3
Capturing frame 4
Capturing frame 5
Cancel button clicked
DoWork cancelled
The thread 0x2e4c has exited with code 0 (0x0).
DoWork running
DoWork cancelled
The thread 0x1010 has exited with code 0 (0x0).
RunWorkerCompleted running

The function seems to be running twice, I can see 2 separate threads exiting and also I don't seem to get any results from capturing. If I set a breakpoint inside the backgroundWorker_DoWork function and continue later, the first run does the capturing normally. What could be going on?

Body:
The thread 0x3108 has exited with code 0 (0x0) means there was no error.
While reading or writing the big data, you should divide it into parts. Otherwise, you cannot progress. Your current while loop is disabled when writing to memory stream.
so your backgroundWorker_DoWork method should be like this :

    private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        var worker = (BackgroundWorker)sender;

        // this is an example file
        string filePath = @"C:\file.gif";

        // it determines how many bytes of data will be received from the stream each time.
        byte[] buffer = new byte[4096];
        int byteCount = 0;

        // we are preparing to read stream.
        using (FileStream fs = new FileStream(filePath, FileMode.Open, System.IO.FileAccess.Read))
        using (MemoryStream ms = new MemoryStream())
        {
            // read the stream bytes and fill buffer
            while ((byteCount = fs.Read(buffer, 0, buffer.Length)) > 0)
            {
                // if the task was canceled
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }

                // write buffer to memory stream
                ms.Write(buffer, 0, byteCount);
            }
        }
    }


问:
Kotlin: start an Activity from a fragment
I tried to start an Activity from a fragment (with setOnClickListener), but it doesn't work. I start this fragment from an Activity, in a FrameLayout :

```<code>btn.setOnClickListener {
        supportFragmentManager.beginTransaction()
            .replace(R.id.FrameLayout,
                FirstFragment()
            )
            .commit()
        }
</code>```

Here is my fragment code:

```<code>class FirstFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?
): View {

    return inflater . inflate (R.layout.fragment_first, container, false)
}
</code>```

I searched a lot and found much code but nothing worked.
Thank you in advance!

答:
You never start Activities from Fragments. The navigation control is Activity responsability.

To start any Component in Android you need a Intent.

Here find the official documentation:

https://developer.android.com/guide/components/fragments?hl=es#CommunicatingWithActivity

Body:
I tried to start an Activity from a fragment (with setOnClickListener), but it doesn't work. I start this fragment from an Activity, in a FrameLayout :

btn.setOnClickListener {
        supportFragmentManager.beginTransaction()
            .replace(R.id.FrameLayout,
                FirstFragment()
            )
            .commit()
        }

Here is my fragment code:

class FirstFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater,container: ViewGroup?,savedInstanceState: Bundle?
): View {

    return inflater . inflate (R.layout.fragment_first, container, false)
}

I searched a lot and found much code but nothing worked.
Thank you in advance!


问:
AttributeErrors when adding variables/constraints to Gurobi persistent
I am trying to modify a model by adding variables/constraints and re-solving the updated model, following the guide.

The problem is that both cases fail with attribute errors, for a variable:

```<code>Traceback (most recent call last):
  File "seqdesign.py", line 98, in <module>
    main()
  File "seqdesign.py", line 71, in main
    problem._solver.add_var(problem._model.McBernoulliTrials)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 153, in add_var
    self._add_var(var)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 208, in _add_var
    vtype = self._gurobi_vtype_from_var(var)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 377, in _gurobi_vtype_from_var
    if var.is_binary():
AttributeError: 'IndexedVar' object has no attribute 'is_binary'
</code>```

And for a constraint:

```<code>Traceback (most recent call last):
  File "seqdesign.py", line 98, in <module>
    main()
  File "seqdesign.py", line 71, in main
    problem._solver.add_constraint(problem._model.McBernoulliTrialsSetPositive)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 132, in add_constraint
    self._add_constraint(con)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 272, in _add_constraint
    if is_fixed(con.body):
AttributeError: 'IndexedConstraint' object has no attribute 'body'
</code>```

Is the problem that I am using indexed variables and constraints? How to make this work without migrating all code from pyomo.environ to pyomo.core?

答:
You cannot pass an IndexedVar or and IndexedConstraint into the add_var and add_constraint methods. You have to loop over the individual variables and constraints and add them one at a time:

```<code>for v in my_var.values():
    solver.add_var(v)

for c in my_con.values():
    solver.add_constraint(c)
</code>```

Additionally, you can check if a variable or constraint is indexed with my_var.is_indexed() or my_con.is_indexed().

Body:
I am trying to modify a model by adding variables/constraints and re-solving the updated model, following the guide.

The problem is that both cases fail with attribute errors, for a variable:

Traceback (most recent call last):
  File "seqdesign.py", line 98, in <module>
    main()
  File "seqdesign.py", line 71, in main
    problem._solver.add_var(problem._model.McBernoulliTrials)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 153, in add_var
    self._add_var(var)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 208, in _add_var
    vtype = self._gurobi_vtype_from_var(var)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 377, in _gurobi_vtype_from_var
    if var.is_binary():
AttributeError: 'IndexedVar' object has no attribute 'is_binary'

And for a constraint:

Traceback (most recent call last):
  File "seqdesign.py", line 98, in <module>
    main()
  File "seqdesign.py", line 71, in main
    problem._solver.add_constraint(problem._model.McBernoulliTrialsSetPositive)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/persistent_solver.py", line 132, in add_constraint
    self._add_constraint(con)
  File "/home/edo/miniconda3/envs/spacers/lib/python3.7/site-packages/pyomo/solvers/plugins/solvers/gurobi_direct.py", line 272, in _add_constraint
    if is_fixed(con.body):
AttributeError: 'IndexedConstraint' object has no attribute 'body'

Is the problem that I am using indexed variables and constraints? How to make this work without migrating all code from pyomo.environ to pyomo.core?

Body:
You cannot pass an IndexedVar or and IndexedConstraint into the add_var and add_constraint methods. You have to loop over the individual variables and constraints and add them one at a time:

for v in my_var.values():
    solver.add_var(v)

for c in my_con.values():
    solver.add_constraint(c)

Additionally, you can check if a variable or constraint is indexed with my_var.is_indexed() or my_con.is_indexed().


问:
How to export a CSV file from the MySQL command line
I have a MySQL database containing a single table which is used as a temporary storage point for manipulating and querying data sets and is periodically deleted and replaced with new data. What I would like to be able to do is export the data from the MySQL command line to use for other purposes. I am using the XAMPP Apache server package with phpMyAdmin on Windows 10.

The issue I am having is the INTO OUTFILE syntax I am using returns an error relating to '\n'. Below is an example of the syntax:

```<code>SELECT *
FROM tablename
WHERE work_complete = 'Yes'
INTO OUTFILE 'C:\file path for the file to be exported to\file_name.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY "''"
ESCAPED BY '\'
LINES TERMINATED BY '\n';
</code>```

I have spent some time researching this without any luck, I have even tried using

```<code>LINES TERMINATED BY '\r\n'
</code>```

but the error remained the same

```<code>ERROR: Unknown command '\''.
   ->     LINES TERMINATED BY '\r\n';
</code>```

If anyone could provide any tips that would be greatly appreciated.

答:
The problem is not in LINES TERMINATED BY but in ESCAPED BY.

This:

```<code>ESCAPED BY '\'
</code>```

Is invalid syntax, because the backslash is interpreted as an escape character for the following quote. A decent text editor should let you see that.

You need to escape the backslash, like so:

```<code>ESCAPED BY '\\'
</code>```

Alternatively, you can also use '\b':

```<code>ESCAPED BY '\b'
</code>```

Another probem is that OPTIONALLY ENCLOSED accepts only a single character, while you are giving it two single quotes.

In your query:

```<code>SELECT *  FROM tablename WHERE work_complete = 'Yes'
INTO OUTFILE 'C:\file path for the file to be exported to\file_name.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY "'" ESCAPED BY '\\'
LINES TERMINATED BY '\n'
</code>```

Body:
I have a MySQL database containing a single table which is used as a temporary storage point for manipulating and querying data sets and is periodically deleted and replaced with new data. What I would like to be able to do is export the data from the MySQL command line to use for other purposes. I am using the XAMPP Apache server package with phpMyAdmin on Windows 10.

The issue I am having is the INTO OUTFILE syntax I am using returns an error relating to '\n'. Below is an example of the syntax:

SELECT *
FROM tablename
WHERE work_complete = 'Yes'
INTO OUTFILE 'C:\file path for the file to be exported to\file_name.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY "''"
ESCAPED BY '\'
LINES TERMINATED BY '\n';

I have spent some time researching this without any luck, I have even tried using

LINES TERMINATED BY '\r\n'

but the error remained the same

ERROR: Unknown command '\''.
   ->     LINES TERMINATED BY '\r\n';

If anyone could provide any tips that would be greatly appreciated.

Body:
The problem is not in LINES TERMINATED BY but in ESCAPED BY.

This:

ESCAPED BY '\'

Is invalid syntax, because the backslash is interpreted as an escape character for the following quote. A decent text editor should let you see that.

You need to escape the backslash, like so:

ESCAPED BY '\\'

Alternatively, you can also use '\b':

ESCAPED BY '\b'

Another probem is that OPTIONALLY ENCLOSED accepts only a single character, while you are giving it two single quotes.

In your query:

SELECT *  FROM tablename WHERE work_complete = 'Yes'
INTO OUTFILE 'C:\file path for the file to be exported to\file_name.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY "'" ESCAPED BY '\\'
LINES TERMINATED BY '\n'


问:
lapply and aggregate columns for list of dataframes R
Newbie here, Thanks in advance for the help

I have a list of multiple dataframes (AllExplants), with the same number of columns (with identical names) and different number of rows. I wish to aggregate columns for all the dataframes in the list at once.

My data: I will use a list of two dataframes here for simplicity

```<code>AllExplants <- list(Explant1, Explant2)
</code>```

Explant1:

```<code> `Sample Name`                       `Tissue Category` `Annotation ID`                              All Negative `Non-nuclear`   PD1  PDL1
1 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[10311,49192] 25140     4954            23  4418 15635
2 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[10311,49192]  8788     1678            23  2922  4114
3 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[10311,49192] 16344     3268             0  1496 11521
4 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[10311,51272] 37930     9847           137  9821 17921
5 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[10311,51272] 17400     5700           123  4914  6544
6 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[10311,51272] 20526     4144            13  4907 11377
7 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[12161,50230]  2315     1105            34   334   818
8 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[12161,50230]  1666      934            30   266   427
9 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[12161,50230]   639      164             1    68   391
</code>```

Explant2:

```<code>  `Sample Name`                       `Tissue Category` `Annotation ID`                              All Negative `Non-nuclear`   PD1  PDL1
1 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[10872,46112] 19602     4370            47  3176 11983
2 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[10872,46112]  8479     2158            36  2624  3644
3 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[10872,46112] 11116     2207            11   552  8339
4 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[11335,47845] 14783     2036            10  1697 10973
5 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[11335,47845]  3179      494             6   894  1770
6 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[11335,47845] 11604     1542             4   803  9203
</code>```

I wish to aggregate columns 4-8 (i.e. All, Negative, Non-nuclear ,PD1 ,PDL1) and do so according to column 2 (Tissue Category)

I can do this for each individual dataframe (if it is not in a list), with the code below

```<code>Explant1_agg <- aggregate(Explant1 [,4:8], by=list(Explant1$`Tissue Category`), FUN=sum)
</code>```

However that's time consuming, to apply the same function to all the dataframes in the list, I have tried this code, having looked at posts here:

```<code>AllExplants_agg <- lapply(AllExplants, function(x) {aggregate(x[,4:8], by=list(x[,2]),  FUN=sum)})
</code>```

However R returns the error

```<code> Error in aggregate.data.frame(x[, 4:8], by = list(x[, 2]), FUN = sum) :
  arguments must have same length
</code>```

Any help would be greatly appreciated!

答:
I know this question is already old, but I encountered the same problem and fixed it, and I thought it might still be of interest.

I didn't manage to get R to use a list in aggregate, but I worked around it with a for-loop:

```<code>dat=seq(from=1, by=1, to=length(All_Explants))
#list to ID dataframes
output_All_Explants=list() #create list for output data from for loop
for (i in dat) {
    dummy=as.data.frame(All_Explants[[i]])
    Output_All_Explants[[i]]=aggregate(dummy[,4:8],
    by=list(date=dummy$Tissue Category), FUN=sum)
}
</code>```

Body:
Newbie here, Thanks in advance for the help

I have a list of multiple dataframes (AllExplants), with the same number of columns (with identical names) and different number of rows. I wish to aggregate columns for all the dataframes in the list at once.

My data: I will use a list of two dataframes here for simplicity

AllExplants <- list(Explant1, Explant2)

Explant1:

 `Sample Name`                       `Tissue Category` `Annotation ID`                              All Negative `Non-nuclear`   PD1  PDL1
1 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[10311,49192] 25140     4954            23  4418 15635
2 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[10311,49192]  8788     1678            23  2922  4114
3 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[10311,49192] 16344     3268             0  1496 11521
4 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[10311,51272] 37930     9847           137  9821 17921
5 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[10311,51272] 17400     5700           123  4914  6544
6 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[10311,51272] 20526     4144            13  4907 11377
7 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[12161,50230]  2315     1105            34   334   818
8 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[12161,50230]  1666      934            30   266   427
9 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[12161,50230]   639      164             1    68   391

Explant2:

  `Sample Name`                       `Tissue Category` `Annotation ID`                              All Negative `Non-nuclear`   PD1  PDL1
1 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[10872,46112] 19602     4370            47  3176 11983
2 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[10872,46112]  8479     2158            36  2624  3644
3 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[10872,46112] 11116     2207            11   552  8339
4 LT181- PD1 PDL1 MNF -1_Scan1.qptiff All               LT181- PD1 PDL1 MNF -1_Scan1_[11335,47845] 14783     2036            10  1697 10973
5 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Stroma            LT181- PD1 PDL1 MNF -1_Scan1_[11335,47845]  3179      494             6   894  1770
6 LT181- PD1 PDL1 MNF -1_Scan1.qptiff Tumour            LT181- PD1 PDL1 MNF -1_Scan1_[11335,47845] 11604     1542             4   803  9203

I wish to aggregate columns 4-8 (i.e. All, Negative, Non-nuclear ,PD1 ,PDL1) and do so according to column 2 (Tissue Category)

I can do this for each individual dataframe (if it is not in a list), with the code below

Explant1_agg <- aggregate(Explant1 [,4:8], by=list(Explant1$`Tissue Category`), FUN=sum)

However that's time consuming, to apply the same function to all the dataframes in the list, I have tried this code, having looked at posts here:

AllExplants_agg <- lapply(AllExplants, function(x) {aggregate(x[,4:8], by=list(x[,2]),  FUN=sum)})

However R returns the error

 Error in aggregate.data.frame(x[, 4:8], by = list(x[, 2]), FUN = sum) :
  arguments must have same length

Any help would be greatly appreciated!

Body:
I know this question is already old, but I encountered the same problem and fixed it, and I thought it might still be of interest.

I didn't manage to get R to use a list in aggregate, but I worked around it with a for-loop:

dat=seq(from=1, by=1, to=length(All_Explants))
#list to ID dataframes
output_All_Explants=list() #create list for output data from for loop
for (i in dat) {
    dummy=as.data.frame(All_Explants[[i]])
    Output_All_Explants[[i]]=aggregate(dummy[,4:8],
    by=list(date=dummy$Tissue Category), FUN=sum)
}


问:
Is Logging using FileHandler a bottleneck?
I am considering logging business events in a J2EE web application by using Java logging and FileHandler.

I am wondering whether that could cause a performance bottleneck, since many log records will be written to one file.

What are your experiences and opinions?

Is logging a busy web application to one file with Java logging and FileHandler likely to become performance bottleneck?

答: I think that JavaRevisited blog has a pretty good post on a problem with performance: Top 10 Tips on Logging in Java</p>


问:
How to change Python variables based on JSON response?
I am trying to get a Python variable based on a JSON response.

When I request the JSON I want to save some of the information as

```<code>X = content[0]['OrderItemList'][0]['ItemID']
</code>```

What I need is the variable X to change if it is a certain number.

For example, if x = 3, I need it be changed to x = 5. So far I have been able to change the variable with math and other string or integer changes. I think a loop would work but I am not sure.

```<code>if request.method == 'POST':

    x = content[0]['OrderItemList'][0]['ItemID']

    pseudocode

    if x = 2 chnage to x = 5
</code>```

答:
Simply set x to the value from json, then use if/elif statements to reassign x.

```<code>x = content[0]['OrderItemList'][0]['ItemID']
if x in [2, 3]:
  # if x is 2 or 3, set to 5
  x = 5
elif x == 4:
  x = 2
</code>```

or if you have a lot of conditions on which to change x, consider using a dict :

```<code>changetos = {2: 5,
             3: 5,
             #...
            }
x = content[0]['OrderItemList'][0]['ItemID']
x = changetos.get(x, x) # if x not in changetos, leave x as is
</code>```

Body:
I am trying to get a Python variable based on a JSON response.

When I request the JSON I want to save some of the information as

X = content[0]['OrderItemList'][0]['ItemID']

What I need is the variable X to change if it is a certain number.

For example, if x = 3, I need it be changed to x = 5. So far I have been able to change the variable with math and other string or integer changes. I think a loop would work but I am not sure.

if request.method == 'POST':

    x = content[0]['OrderItemList'][0]['ItemID']

    pseudocode

    if x = 2 chnage to x = 5

Body:
Simply set x to the value from json, then use if/elif statements to reassign x.

x = content[0]['OrderItemList'][0]['ItemID']
if x in [2, 3]:
  # if x is 2 or 3, set to 5
  x = 5
elif x == 4:
  x = 2

or if you have a lot of conditions on which to change x, consider using a dict :

changetos = {2: 5,
             3: 5,
             #...
            }
x = content[0]['OrderItemList'][0]['ItemID']
x = changetos.get(x, x) # if x not in changetos, leave x as is


问:
How to Implement DOM Data Binding in JavaScript
Please treat this question as strictly educational. I'm still interested in hearing new answers and ideas to implement this

tl;dr

How would I implement bi-directional data-binding with JavaScript?

Data Binding to the DOM

By data binding to the DOM I mean  for example, having a JavaScript object a with a property b. Then having an <input> DOM element (for example), when the DOM element changes, a changes and vice versa (that is, I mean bidirectional data binding).

Here is a diagram from AngularJS on what this looks like:

So basically I have JavaScript similar to:

```<code>var a = {b:3};
</code>```

Then an input (or other form) element like:

```<code><input type='text' value=''>
</code>```

I'd like the input's value to be a.b's value (for example), and when the input text changes, I'd like a.b to change too. When a.b changes in JavaScript, the input changes.

The Question

What are some basic techniques to accomplish this in plain JavaScript?

In specific, I'd like a good answer to refer to:

How would binding work for objects?

How listening to change in the form might work?

Is it possible in a simple way to only have the HTML modified on the template level? I'd like to not keep track of the binding in the HTML document itself but only in JavaScript (with DOM events, and JavaScript keeping reference to the DOM elements used).

What have I tried?

I'm a big fan of Mustache so I tried using it for templating. However, I ran into issues when trying to perform the data binding itself since Mustache processes HTML as a string so after I get its result I have no reference to where the objects in my viewmodel are. The only workaround I could think for this was modifying the HTML string (or created DOM tree) itself with attributes. I don't mind using a different templating engine.

Basically, I got a strong feeling that I was complicating the issue at hand and there is a simple solution.

Note: Please do not provide answers that use external libraries, especially ones that are thousands of lines of code. I've used (and like!) AngularJS and KnockoutJS. I really don't want answers in the form 'use framework x'. Optimally, I'd like a future reader who doesn't know how to use many frameworks to grasp how to implement bi-directional data-binding herself. I do not expect a complete answer, but one that gets the idea across.

答:
Late to the party, especially since I've written 2 libs related months/years ago, I'll mention them later, but still looks relevant to me. To make it really short spoiler, the technologies of my choice are:

Proxy for observation of model

MutationObserver for the tracking changes of DOM (for binding reasons, not value changes)

value changes (view to model flow) are handled via regular addEventListener handlers

IMHO, in addition to the OP, it is important that data binding implementation will:

handle different app lifecycle cases (HTML first, then JS, JS first then HTML, dynamic attributes change etc)

allow deep binding of model, so that one may bind user.address.block

arrays as a model should be supported correctly (shift, splice and alike)

handle ShadowDOM

attempt to be as easy for technology replacement as possible, thus any templating sub-languages are a non-future-changes-friendly approach since it's too heavily coupled with framework

Taking all those into consideration, in my opinion makes it impossible to just throw few dozens of JS lines. I've tried to do it as a pattern rather than lib - didn't work for me.

Next, having Object.observe is removed, and yet given that observation of model is crucial part - this whole part MUST be concern-separated to another lib. Now to the point of principals of how I took this problem - exactly as OP asked:

Model (JS part)

My take for model observation is Proxy, it is the only sane way to make it work, IMHO.
Fully featured observer deserves it's own library, so I've developed object-observer library for that sole purpose.

The model/s should be registered via some dedicated API, that's the point where POJOs turn into Observables, can't see any shortcut here. The DOM elements which are considered to be a bound views (see below), are updated with the values of the model/s at first and then upon each data change.

Views (HTML part)

IMHO, the cleanest way to express the binding, is via attributes. Many did this before and many will do after, so no news here, this is just a right way to do that. In my case I've gone with the following syntax:  targerProperty">, but this is less important. What is important to me, no complex scripting syntax in the HTML - this is wrong, again, IMHO.

All the elements designated to be a bound views shall be collected at first. It looks inevitable to me from a performance side to manage some internal mapping between the models and the views, seems a  right case where memory + some management should be sacrificed to save runtime lookups and updates.

The views are updated at first from the model, if available and upon later model changes, as we said.
More yet, the whole DOM should be observed by means of MutationObserver in order to react (bind/unbind) on the dynamically added/remove/changed elements.
Furthermore, all this, should be replicated into the ShadowDOM (open one, of course) in order to not leave unbound black holes.

The list of specifics may go further indeed, but those are in my opinion the main principals that would made data binding implemented with a good balance of feature completeness from one and sane simplicity from the other side.

And thus, in addition to the object-observer mentioned above, I've written indeed also data-tier library, that implements data binding along the above mentioned concepts.

Body:
Please treat this question as strictly educational. I'm still interested in hearing new answers and ideas to implement this

tl;dr

How would I implement bi-directional data-binding with JavaScript?

Data Binding to the DOM

By data binding to the DOM I mean  for example, having a JavaScript object a with a property b. Then having an <input> DOM element (for example), when the DOM element changes, a changes and vice versa (that is, I mean bidirectional data binding).

Here is a diagram from AngularJS on what this looks like:

So basically I have JavaScript similar to:

var a = {b:3};

Then an input (or other form) element like:

<input type='text' value=''>

I'd like the input's value to be a.b's value (for example), and when the input text changes, I'd like a.b to change too. When a.b changes in JavaScript, the input changes.

The Question

What are some basic techniques to accomplish this in plain JavaScript?

In specific, I'd like a good answer to refer to:

How would binding work for objects?

How listening to change in the form might work?

Is it possible in a simple way to only have the HTML modified on the template level? I'd like to not keep track of the binding in the HTML document itself but only in JavaScript (with DOM events, and JavaScript keeping reference to the DOM elements used).

What have I tried?

I'm a big fan of Mustache so I tried using it for templating. However, I ran into issues when trying to perform the data binding itself since Mustache processes HTML as a string so after I get its result I have no reference to where the objects in my viewmodel are. The only workaround I could think for this was modifying the HTML string (or created DOM tree) itself with attributes. I don't mind using a different templating engine.

Basically, I got a strong feeling that I was complicating the issue at hand and there is a simple solution.

Note: Please do not provide answers that use external libraries, especially ones that are thousands of lines of code. I've used (and like!) AngularJS and KnockoutJS. I really don't want answers in the form 'use framework x'. Optimally, I'd like a future reader who doesn't know how to use many frameworks to grasp how to implement bi-directional data-binding herself. I do not expect a complete answer, but one that gets the idea across.

Body:
Late to the party, especially since I've written 2 libs related months/years ago, I'll mention them later, but still looks relevant to me. To make it really short spoiler, the technologies of my choice are:

Proxy for observation of model

MutationObserver for the tracking changes of DOM (for binding reasons, not value changes)

value changes (view to model flow) are handled via regular addEventListener handlers

IMHO, in addition to the OP, it is important that data binding implementation will:

handle different app lifecycle cases (HTML first, then JS, JS first then HTML, dynamic attributes change etc)

allow deep binding of model, so that one may bind user.address.block

arrays as a model should be supported correctly (shift, splice and alike)

handle ShadowDOM

attempt to be as easy for technology replacement as possible, thus any templating sub-languages are a non-future-changes-friendly approach since it's too heavily coupled with framework

Taking all those into consideration, in my opinion makes it impossible to just throw few dozens of JS lines. I've tried to do it as a pattern rather than lib - didn't work for me.

Next, having Object.observe is removed, and yet given that observation of model is crucial part - this whole part MUST be concern-separated to another lib. Now to the point of principals of how I took this problem - exactly as OP asked:

Model (JS part)

My take for model observation is Proxy, it is the only sane way to make it work, IMHO.
Fully featured observer deserves it's own library, so I've developed object-observer library for that sole purpose.

The model/s should be registered via some dedicated API, that's the point where POJOs turn into Observables, can't see any shortcut here. The DOM elements which are considered to be a bound views (see below), are updated with the values of the model/s at first and then upon each data change.

Views (HTML part)

IMHO, the cleanest way to express the binding, is via attributes. Many did this before and many will do after, so no news here, this is just a right way to do that. In my case I've gone with the following syntax: <span data-tie="modelKey:path.to.data => targerProperty"></span>, but this is less important. What is important to me, no complex scripting syntax in the HTML - this is wrong, again, IMHO.

All the elements designated to be a bound views shall be collected at first. It looks inevitable to me from a performance side to manage some internal mapping between the models and the views, seems a  right case where memory + some management should be sacrificed to save runtime lookups and updates.

The views are updated at first from the model, if available and upon later model changes, as we said.
More yet, the whole DOM should be observed by means of MutationObserver in order to react (bind/unbind) on the dynamically added/remove/changed elements.
Furthermore, all this, should be replicated into the ShadowDOM (open one, of course) in order to not leave unbound black holes.

The list of specifics may go further indeed, but those are in my opinion the main principals that would made data binding implemented with a good balance of feature completeness from one and sane simplicity from the other side.

And thus, in addition to the object-observer mentioned above, I've written indeed also data-tier library, that implements data binding along the above mentioned concepts.


问:
Angular - Get Route data in app component
I have the following routes configured in app-routing.module.ts

const routes: Routes = [
  {
    path: 'abc/:id', component: AbcComponent, data: { category: 'Public' }
  },
  {
    path: 'xyz/:id/tester/:mapId', component: XyzComponent, data: { category: 'Private' }
  },
  { path: '**', redirectTo: '/page-not-found', pathMatch: 'full'}
]
```
<p>In <code>app.component.ts</code> I would like to get the category of each Route based on the URL passed:</p>
<p>Ex: going to <code>http://myapp.com/abc/123</code>  should return category as <code>Public</code>
going to <code>http://myapp.com/xyz/123/tester/456</code>  should return category as <code>Private</code></p>
<p>Here is what I have so far:</p>
<pre class="lang-js prettyprint-override"><code>constructor(
    private activatedRoute: ActivatedRoute,
    private router: Router
)
{
  checkRouteAndGetCategory()
}

checkRouteAndGetCategory()
{
  this.router.events.pipe(
        filter(event => event instanceof NavigationEnd),
        map(() => this.activatedRoute),
        map(route => {
          while (route.firstChild) route = route.firstChild
          return route
        }),
        filter(route => route.outlet === 'primary'),
        mergeMap(route => route.data)
      ).subscribe(data =>
        console.log('data', data)
      )
}
</code>```

The above code does not seem to get the right route. Ex: If I am on http://myapp.com/abc/123 page and navigated to http://myapp.com/xyz/123/tester/456, it seems to get the data for  http://myapp.com/abc/123 page.

答:
This is what I have in my app component

```<code>constructor(private route: ActivatedRoute) {
}

ngOnInit(): void {
  this.router.events.pipe(
    filter(event => event instanceof NavigationEnd),
    map(() => this.rootRoute(this.route)),
    filter((route: ActivatedRoute) => route.outlet === 'primary'),
    mergeMap((route: ActivatedRoute) => route.data)
  ).subscribe((event: {[name: string]: any}) => {
    this.titleService.setRouteTitle(event['title']);
  });
}

private rootRoute(route: ActivatedRoute): ActivatedRoute {
  while (route.firstChild) {
    route = route.firstChild;
  }
  return route;
}
</code>```

Where my app routes look like:

```<code>{ path: 'login', component: LoginComponent, data: { title: 'Login' } }
</code>```

And my title service is responsible for setting the title.

The only difference I see between mine and yours is that you bind to the router in your constructor and I do it in ngOnInit. Can you try calling what you have in ngOnInit? I'm not sure if this will make a difference, but it's worth a shot.

Body:
I have the following routes configured in app-routing.module.ts

const routes: Routes = [
  {
    path: 'abc/:id', component: AbcComponent, data: { category: 'Public' }
  },
  {
    path: 'xyz/:id/tester/:mapId', component: XyzComponent, data: { category: 'Private' }
  },
  { path: '**', redirectTo: '/page-not-found', pathMatch: 'full'}
]

In app.component.ts I would like to get the category of each Route based on the URL passed:

Ex: going to http://myapp.com/abc/123  should return category as Public
going to http://myapp.com/xyz/123/tester/456  should return category as Private

Here is what I have so far:

constructor(
    private activatedRoute: ActivatedRoute,
    private router: Router
)
{
  checkRouteAndGetCategory()
}

checkRouteAndGetCategory()
{
  this.router.events.pipe(
        filter(event => event instanceof NavigationEnd),
        map(() => this.activatedRoute),
        map(route => {
          while (route.firstChild) route = route.firstChild
          return route
        }),
        filter(route => route.outlet === 'primary'),
        mergeMap(route => route.data)
      ).subscribe(data =>
        console.log('data', data)
      )
}

The above code does not seem to get the right route. Ex: If I am on http://myapp.com/abc/123 page and navigated to http://myapp.com/xyz/123/tester/456, it seems to get the data for  http://myapp.com/abc/123 page.

Body:
This is what I have in my app component

constructor(private route: ActivatedRoute) {
}

ngOnInit(): void {
  this.router.events.pipe(
    filter(event => event instanceof NavigationEnd),
    map(() => this.rootRoute(this.route)),
    filter((route: ActivatedRoute) => route.outlet === 'primary'),
    mergeMap((route: ActivatedRoute) => route.data)
  ).subscribe((event: {[name: string]: any}) => {
    this.titleService.setRouteTitle(event['title']);
  });
}

private rootRoute(route: ActivatedRoute): ActivatedRoute {
  while (route.firstChild) {
    route = route.firstChild;
  }
  return route;
}

Where my app routes look like:

{ path: 'login', component: LoginComponent, data: { title: 'Login' } }

And my title service is responsible for setting the title.

The only difference I see between mine and yours is that you bind to the router in your constructor and I do it in ngOnInit. Can you try calling what you have in ngOnInit? I'm not sure if this will make a difference, but it's worth a shot.