Android files (Java and XML) being replaced by weird XML [duplicate]

寵の児 提交于 2019-12-19 06:20:09

问题


I encountered a bizarre issue while using Android Studio (v2.3.3, built on 2017-06-06). One of my Java files was replaced with unrelated XML that seemed to be generated by Android Studio. I don't think I did anything to trigger it. A second Java file suffered the same fate soon afterwards, once again, with no discernible cause.

Thankfully I had just ZIPed up a copy of the source code so I deleted the files and replaced them. I don't have an exact copy of the weird code, but this code I found at git.moeryn.com is pretty close to what I saw:

<application>
  <component name="UsageTrigger">
    <counts>
      <entry feature="CreateFile.CreateFileAction" count="1" />
      <entry feature="JSDebugConfig.Debug.browser-default.preferredBrowser-null.no_mappings" count="6" />
      <entry feature="OpenInBrowser.Opera" count="1" />
      <entry feature="execute.Application.Coverage" count="1" />
      <entry feature="execute.Application.Debug" count="1" />
      <entry feature="execute.Application.Run" count="15" />
      <entry feature="execute.GWT.ConfigurationType.Debug" count="12" />
      <entry feature="execute.GWT.ConfigurationType.Run" count="18" />
      <entry feature="execute.GroovyScriptRunConfiguration.Debug" count="1" />
      <entry feature="execute.GroovyScriptRunConfiguration.Run" count="9" />
      <entry feature="execute.JUnit.Coverage" count="4" />
      <entry feature="execute.JUnit.Run" count="86" />
      <entry feature="execute.JavascriptDebugType.Debug" count="6" />
      <entry feature="ide.settings.Appearance" count="4" />
      <entry feature="ide.settings.Colors_&amp;_Fonts" count="1" />
      <entry feature="ide.settings.Console_Font" count="4" />
      <entry feature="ide.settings.Font" count="4" />
      <entry feature="ide.settings.General" count="1" />
      <entry feature="ide.settings.Gerrit" count="4" />
      <entry feature="ide.settings.Java" count="1" />
      <entry feature="ide.settings.Keymap" count="12" />
      <entry feature="ide.settings.Vim_Emulation" count="2" />
      <entry feature="idea.caches.invalidated" count="1" />
      <entry feature="ideaapp.started" count="28" />
      <entry feature="terminal.linux" count="2" />
      <entry feature="uml.ShowDiagram.JAVA" count="1" />
      <entry feature="welcome.screen.WelcomeScreen.Configure" count="1" />
      <entry feature="welcome.screen.WelcomeScreen.CreateNewProject" count="2" />
    </counts>
  </component>
</application>

I found somebody on StackOverflow who encountered a similar problem last week: My Activity Class turn into an xml file, however, there was no resolution or explanation of what happened. I found another instance of someone encountering the same problem here: Android Studio wrong load a source file

Now it has happened to me a third time - this time it affected an XML file in res/anim. This is really puzzling (and worrisome since I am now paranoid it'll happen again). Oddly enough, the file contents are cut off midway through a tag:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="AnalysisUIOptions">
    <option name="SCOPE_TYPE" value="3" />
  </component>
  <component name="AndroidLayouts">
    <shared>
      <config>
        <devices>
          <device id="Nexus 6" />
          <device id="pixel" />
          <device id="Nexus 4" />
          <device id="tv_720p" />
          <device id="tv_1080p" />
          <device id="wear_round_chin_320_290" />
          <device id="Galaxy Nexus" />
          <device id="Nexus One" />
        </devices>
      </config>
    </shared>
  </component>
  <component name="AndroidLogFilters">
    <option name="TOOL_WINDOW_LOG_LEVEL" value="verbose" />
    <option name="TOOL_WINDOW_CONFIGURED_FILTER" value="Show only selected application" />
  </component>
  <component name="BookmarkManager">
    <bookmar

Has anyone else encountered this problem? Any idea what might be causing it?


It happened a few more times when I opened XML files. transition__dialog__slide_out_to_right.xml was replaced with the beginning of my FlagView.java class that I was working on earlier (note that the Java file wasn't open at the time, it had been 2+ hours since I'd been editing it, and this code wasn't in my clipboard):

package co.company.app.views;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatDelegate;
import android.util.AttributeSet;
import android.

transition__dialog__slide_in_from_right.xml got replaced with this partial XML:

<application>
  <component name="UsageTrigger">
    <counts>
      <entry feature="CreateFile.CreateFileAction" count="2" />
      <entry feature="execute.AndroidRunConfigurationType.Debug" count="14" />
      <entry feature="execute.AndroidRunConfigurationType.Run" count="2237" />
      <entry feature="execute.GradleRunCon

The other transition anim files opened normally. However, another file in res/anim got replaced with most of my Canadian flag drawable XML file:

<!-- Canadian flag -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="48dp"
        android:height="24dp"
        android:viewportWidth="1000.0"
        android:viewportHeight="500.0">

    <!-- Background red rectangle -->
    <path
        android:fillColor="#f00"
        android:pathData="M 0,0  L 1000,0  L 1000,500  L 0,500"
        />

    <!-- Center white square -->
    <path
        android:fillColor="#fff"
        android:pathData="M250,0  H750  V500  H250"
        />

    <!-- Maple leaf -->
    <path
        android:fillColor="#ff0000"
        android:pathData=
            "
            M 499.992280,  46.87500
              -34.113120,  63.62529
            c  -3.870860,   6.91501
              -10.806270,   6.27363
              -17.741690,   2.41138
            l -24.696990, -12.78858
               18.407050,  97.72711
            c   3.870860,  17.85419
               -8.548590,  17.85419
               -14.67765,  10.13435
            l -43.101050, -48.25099
               -6.997380,  24.50300
            c  -0.806920,   3.21777
               -4.354810,   6.59744
               -9.677480,   5.79261
            l -54.501770, -11.45912
               14.315240,  52.04475
            c   3.064510,  11.58054
                5.454900,  16.37528
                -3.09375,  19.42959
            l -19.426190,   9.13025
               93.821270,  76.20838
            c   3.713500,   2.88151
                5.589710,   8.06700
                4.267680,  12.76210
            l  -8.211360,  26.94707   
            c  32.304050,  -3.72371
               61.248980,  -9.32594
               93.569390, -12.77619
                2.853230,  -0.30459
                7.629880,   4.40408
                7.610290,   7.71058
            l  -4.280240,  98.72342
               15.706390,   0
               -2.472370, 

Very bizarre...


I closed Android Studio, and when I reopened it, it was using the default light theme instead of my dark theme. A list of errors appeared on the right side of the screen. I closed the application and reopened it. This time I got a popup saying Start Failed:

Internal Error. Please report to https://code.google.com/p/android/issues

com.intellij.ide.plugins.PluginManager$StartupAbortedException: Fatal error initializing 'com.intellij.psi.PsiDocumentManager'
    at com.intellij.ide.plugins.PluginManager.handleComponentError(PluginManager.java:248)
    at com.intellij.openapi.components.impl.PlatformComponentManagerImpl.handleInitComponentError(PlatformComponentManagerImpl.java:43)
    at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:536)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.createComponents(ComponentManagerImpl.java:119)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:103)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:90)
    at com.intellij.openapi.project.impl.ProjectImpl.init(ProjectImpl.java:285)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.initProject(ProjectManagerImpl.java:222)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.lambda$getDefaultProject$2(ProjectManagerImpl.java:280)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:494)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:443)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeNonCancelableSection(CoreProgressManager.java:198)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.getDefaultProject(ProjectManagerImpl.java:277)
    at com.intellij.ide.fileTemplates.FileTemplateManager.getDefaultInstance(FileTemplateManager.java:67)
    at com.android.tools.idea.startup.AndroidStudioInitializer.setUpNewProjectActions(AndroidStudioInitializer.java:270)
    at com.android.tools.idea.startup.AndroidStudioInitializer.run(AndroidStudioInitializer.java:97)
    at com.android.tools.idea.AndroidInitialConfigurator.activateAndroidStudioInitializerExtensions(AndroidInitialConfigurator.java:198)
    at com.android.tools.idea.AndroidInitialConfigurator.<init>(AndroidInitialConfigurator.java:65)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:193)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:220)
    at org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard.observe(ThreadLocalCyclicDependencyGuard.java:53)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:248)
    at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.getComponentInstance(CachingConstructorInjectionComponentAdapter.java:58)
    at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:495)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.createComponents(ComponentManagerImpl.java:119)
    at com.intellij.openapi.application.impl.ApplicationImpl.lambda$createComponents$8(ApplicationImpl.java:429)
    at com.intellij.openapi.progress.impl.CoreProgressManager$3.run(CoreProgressManager.java:170)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:494)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:443)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:155)
    at com.intellij.openapi.application.impl.ApplicationImpl.createComponents(ApplicationImpl.java:436)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:103)
    at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:392)
    at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:384)
    at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:196)
    at com.intellij.idea.MainImpl$1.lambda$null$0(MainImpl.java:47)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:358)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.intellij.openapi.util.ActionCallback
    at com.intellij.openapi.application.impl.LaterInvocator.invokeLater(LaterInvocator.java:137)
    at com.intellij.openapi.application.impl.ModalityInvokatorImpl.invokeLater(ModalityInvokatorImpl.java:46)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeLater(ApplicationImpl.java:379)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeLater(ApplicationImpl.java:369)
    at com.intellij.openapi.application.impl.ApplicationImpl.invokeLater(ApplicationImpl.java:364)
    at com.intellij.psi.impl.DocumentCommitThread.<init>(DocumentCommitThread.java:100)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:193)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:220)
    at org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard.observe(ThreadLocalCyclicDependencyGuard.java:53)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:248)
    at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.getComponentInstance(CachingConstructorInjectionComponentAdapter.java:58)
    at com.intellij.openapi.components.impl.ServiceManagerImpl$MyComponentAdapter.getComponentInstance(ServiceManagerImpl.java:232)
    at com.intellij.util.pico.DefaultPicoContainer.getLocalInstance(DefaultPicoContainer.java:246)
    at com.intellij.util.pico.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:212)
    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.picocontainer.defaults.ImmutablePicoContainerProxyFactory.invoke(ImmutablePicoContainerProxyFactory.java:73)
    at com.sun.proxy.$Proxy43.getComponentInstance(Unknown Source)
    at com.intellij.util.pico.DefaultPicoContainer.getComponentInstance(DefaultPicoContainer.java:217)
    at org.picocontainer.defaults.BasicComponentParameter.resolveInstance(BasicComponentParameter.java:77)
    at org.picocontainer.defaults.ComponentParameter.resolveInstance(ComponentParameter.java:114)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getConstructorArguments(ConstructorInjectionComponentAdapter.java:257)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:217)
    at org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard.observe(ThreadLocalCyclicDependencyGuard.java:53)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:248)
    at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.getComponentInstance(CachingConstructorInjectionComponentAdapter.java:58)
    at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:495)
    ... 54 more

Something seems to have gone terribly wrong with Android Studio...


回答1:


I didn't uncover the root cause of the issue, but following Yashasvi's prompt and the fortunate timing of Android Studio v3's release (5 days before my question on 2017-10-25), I upgraded the software and everything has been working fine since.

Not the most satisfying conclusion to my question, but the my code isn't being screwed up and I'm happy.



来源:https://stackoverflow.com/questions/47020914/android-files-java-and-xml-being-replaced-by-weird-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!