gpt4 book ai didi

安卓工作室 : Issue with navigation xml editing and design view

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:56:04 33 4
gpt4 key购买 nike

我们一直在我们的项目中使用导航组件,但偶然发现了一个似乎是我们的项目和 JetBrains Android 插件独有的问题。我无法确定它开始发生的确切时间点,但我在 AS 3.2 发布后注意到了它。

项目构建良好,但是在编辑导航 XML 时,自动完成和突出显示等内容被破坏,Android 支持插件抛出此错误:

java.lang.IllegalArgumentException: Multiple entries with same key: org.jetbrains.android.dom.navigation.NavigationSchema$TypeRef@0=org.jetbrains.android.dom.navigation.NavigationSchema$NavigatorKeyInfo@17d69e53 and org.jetbrains.android.dom.navigation.NavigationSchema$TypeRef@0=org.jetbrains.android.dom.navigation.NavigationSchema$NavigatorKeyInfo@442c4fde
at com.google.common.collect.ImmutableMap.conflictException(ImmutableMap.java:215)
at com.google.common.collect.ImmutableMap.checkNoConflict(ImmutableMap.java:209)
at com.google.common.collect.RegularImmutableMap.checkNoConflictInKeyBucket(RegularImmutableMap.java:147)
at com.google.common.collect.RegularImmutableMap.fromEntryArray(RegularImmutableMap.java:110)
at com.google.common.collect.ImmutableMap$Builder.build(ImmutableMap.java:393)
at org.jetbrains.android.dom.navigation.NavigationSchema.buildCacheKeys(NavigationSchema.java:488)
at org.jetbrains.android.dom.navigation.NavigationSchema.init(NavigationSchema.java:479)
at org.jetbrains.android.dom.navigation.NavigationSchema.createIfNecessary(NavigationSchema.java:389)
at org.jetbrains.android.dom.AttributeProcessingUtil.processNavAttributes(AttributeProcessingUtil.java:408)
at org.jetbrains.android.dom.AttributeProcessingUtil.processAttributes(AttributeProcessingUtil.java:596)
at org.jetbrains.android.dom.AndroidDomExtender.registerExtensions(AndroidDomExtender.java:57)
at org.jetbrains.android.dom.AndroidDomExtender.registerExtensions(AndroidDomExtender.java:29)
at com.intellij.util.xml.reflect.DomExtenderEP.extend(DomExtenderEP.java:83)
at com.intellij.util.xml.impl.DynamicGenericInfo.runDomExtenders(DynamicGenericInfo.java:134)
at com.intellij.util.xml.impl.DynamicGenericInfo.lambda$checkInitialized$0(DynamicGenericInfo.java:64)
at com.intellij.openapi.util.RecursionManager$2.doPreventingRecursion(RecursionManager.java:98)
at com.intellij.util.xml.impl.DynamicGenericInfo.checkInitialized(DynamicGenericInfo.java:63)
at com.intellij.util.xml.impl.DynamicGenericInfo.getAttributeChildrenDescriptions(DynamicGenericInfo.java:241)
at com.intellij.util.xml.impl.DynamicGenericInfo.processAttributeChildrenDescriptions(DynamicGenericInfo.java:254)
at com.intellij.util.xml.impl.DomSemContributor.lambda$registerSemProviders$5(DomSemContributor.java:199)
at com.intellij.semantic.SemServiceImpl$2.lambda$registerSemElementProvider$0(SemServiceImpl.java:93)
at com.intellij.semantic.SemServiceImpl.createSemElements(SemServiceImpl.java:190)
at com.intellij.semantic.SemServiceImpl.getSemElements(SemServiceImpl.java:161)
at com.intellij.semantic.SemService.getSemElement(SemService.java:37)
at com.intellij.util.xml.impl.DomManagerImpl.getDomHandler(DomManagerImpl.java:390)
at com.intellij.util.xml.impl.GenericValueReferenceProvider.getReferencesByElement(GenericValueReferenceProvider.java:47)
at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl.getReferences(ReferenceProvidersRegistryImpl.java:135)
at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl.mapNotEmptyReferencesFromProviders(ReferenceProvidersRegistryImpl.java:123)
at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl.doGetReferencesFromProviders(ReferenceProvidersRegistryImpl.java:102)
at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry.getReferencesFromProviders(ReferenceProvidersRegistry.java:50)
at com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry.getReferencesFromProviders(ReferenceProvidersRegistry.java:44)
at com.intellij.psi.impl.source.xml.XmlAttributeValueImpl.getReferences(XmlAttributeValueImpl.java:110)
at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.checkReferences(XmlHighlightVisitor.java:439)
at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.visitXmlAttributeValue(XmlHighlightVisitor.java:406)
at com.intellij.psi.impl.source.xml.XmlAttributeValueImpl.accept(XmlAttributeValueImpl.java:61)
at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.visit(XmlHighlightVisitor.java:587)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.runVisitors(GeneralHighlightingPass.java:353)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$collectHighlights$5(GeneralHighlightingPass.java:286)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:313)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$analyzeByVisitors$6(GeneralHighlightingPass.java:316)
at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.analyze(XmlHighlightVisitor.java:597)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:316)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.lambda$analyzeByVisitors$6(GeneralHighlightingPass.java:316)
at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.analyze(DefaultHighlightVisitor.java:71)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.analyzeByVisitors(GeneralHighlightingPass.java:316)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectHighlights(GeneralHighlightingPass.java:283)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectInformationWithProgress(GeneralHighlightingPass.java:227)
at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:84)
at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:69)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:423)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1171)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:416)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:582)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:532)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:87)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:415)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:391)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:147)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:222)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:389)
at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:161)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

我们正在运行最新版本的导航组件 (2.0.0-rc2),并且我已经尝试了所有常用的修复(使缓存无效和重新启动等)。我已经尝试在新项目中使用导航,它似乎可以正常工作而不会引发此错误。

我已经尝试从我们的项目中删除所有导航 XML,然后添加一个完全空白的 XML,但它仍然会引发错误。我深入研究了插件的源代码,这似乎发生在插件最初处理设计 View 的导航文件时,如果它为新的导航文件抛出它就没有意义。

我目前不知道为什么会发生这种情况,如果有任何想法,我们将不胜感激!

最佳答案

简短的回答:

我通过将扩展 androidx.navigation.Navigator 的匿名类移动到一个单独的类并添加注释 @Navigator.Name(String name) 来修复它唯一名称。

如果您也遇到此问题,请检查您的项目或其依赖项中是否有任何继承 Navigator 类但缺少 @Navigator.Name(String name) 的类 注释或使用非唯一字符串作为 name 参数。 fragmentactivity 不能使用,因为它们已在 API 中使用。

更多信息:

在深入研究 Android 支持插件源代码以了解发生了什么之后,我设法解决了我们项目中的问题。

在 Android 支持插件中启动 IDE 功能时,它会遍历您的项目和任何依赖项,寻找任何继承 Navigator 类的类,并为其提供一个标签,以便在XML 文件和设计 View 。此标记基于注释 @Navigator.Name(String name)。如果不存在注释,则使用默认值。

这些标签必须是唯一的,因为它们被用作构建标签到导航器类型的不可变映射的键。在我们的项目中,我们有一个匿名类,它扩展了 Navigator 类并且没有注释。

在导航组件源中,还有一个扩展 Navigator 的匿名类,特别是在 NavDeepLinkBuilder 类中。由于标签只有一个默认值,任何其他继承 Navigator 的类在您的项目或其依赖项中不存在任何注释都会导致此问题。

关于安卓工作室 : Issue with navigation xml editing and design view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55067520/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com