Android和Eclipse:9个补丁资源bug,导致aapt在尝试导出时崩溃
Posted
技术标签:
【中文标题】Android和Eclipse:9个补丁资源bug,导致aapt在尝试导出时崩溃【英文标题】:Android and Eclipse: 9 patch resource bug, causing aapt to crash when trying to export 【发布时间】:2014-03-30 07:49:44 【问题描述】:我刚刚遇到这个错误,当我尝试将 android 项目导出到 apk 时 aapt 崩溃。几乎就像这个aapt.exe crashes when I try to export my Android application from Eclipse。我只遇到了这个错误,因为我已经将我的 Android SDK 工具更新到版本 22.6.2 和 eclipse 到 ADT Bundle 22.6.2
不同之处是,在我的情况下,即使我删除了 9 个补丁资源并重新读取它们,问题也只会卷土重来。我还尝试重做我所有的 9patch png,但没有成功。我已经研究并尝试了导致 aapt 像这样崩溃的不同情况 (Eclipse and Android SDK issue "aapt.exe has stopped"),我得出的结论是只有 9 个补丁 png 会导致问题。
有没有人知道修复这个错误的其他方法,因为我真的需要在项目中包含 9 补丁,或者如果没有,9patch png 的任何好的替代方案?最后,这是自一周前刚刚发布 22.6.2 版本以来的新错误吗?
注意:如果我删除所有 9patch png 资源不会出现问题,但我需要在导出的 apk 中包含这些 9patch png。
编辑:所以在 Window > Preferences > Android > Build > Build Ouput 我选择了正常。然后我删除了 9 补丁并读取了它们,然后在错误日志中我得到了以下信息(注意 @drawable/bubble_me 是 9patch png,所以我要在哪里放那个#?):
java.lang.NumberFormatException: Color value '@drawable/bubble_me' must start with #
at com.android.layoutlib.bridge.impl.ResourceHelper.getColor(ResourceHelper.java:71)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:248)
at android.content.res.BridgeTypedArray.getDrawable(BridgeTypedArray.java:782)
at android.view.View.<init>(View.java:3554)
at android.view.View.<init>(View.java:3484)
at android.view.ViewGroup.<init>(ViewGroup.java:464)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:236)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at android.view.BridgeInflater.onCreateView(BridgeInflater.java:86)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:131)
at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
at android.view.LayoutInflater.inflate(LayoutInflater.java:373)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:399)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:336)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:504)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1584)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1309)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.changed(GraphicalEditorPart.java:725)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.onTargetChange(GraphicalEditorPart.java:1196)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.onDescriptorsChanged(LayoutEditorDelegate.java:916)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegateInitUiRootNode(LayoutEditorDelegate.java:835)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.updateEditor(GraphicalEditorPart.java:953)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.onTargetLoaded(GraphicalEditorPart.java:917)
at com.android.ide.eclipse.adt.AdtPlugin$11.run(AdtPlugin.java:1759)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4145)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3762)
at org.eclipse.ui.internal.dialogs.EventLoopProgressMonitor.runEventLoop(EventLoopProgressMonitor.java:123)
at org.eclipse.ui.internal.dialogs.EventLoopProgressMonitor.isCanceled(EventLoopProgressMonitor.java:97)
at org.eclipse.core.internal.jobs.ThreadJob.isCanceled(ThreadJob.java:144)
at org.eclipse.core.internal.jobs.ThreadJob.waitForRun(ThreadJob.java:233)
at org.eclipse.core.internal.jobs.ThreadJob.joinRun(ThreadJob.java:197)
at org.eclipse.core.internal.jobs.ImplicitJobs.begin(ImplicitJobs.java:92)
at org.eclipse.core.internal.jobs.JobManager.beginRule(JobManager.java:286)
at org.eclipse.core.internal.resources.WorkManager.checkIn(WorkManager.java:118)
at org.eclipse.core.internal.resources.Workspace.prepareOperation(Workspace.java:2283)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2340)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.ui.internal.editors.text.WorkspaceOperationRunner.run(WorkspaceOperationRunner.java:75)
at org.eclipse.ui.internal.editors.text.WorkspaceOperationRunner.run(WorkspaceOperationRunner.java:65)
at org.eclipse.ui.editors.text.TextFileDocumentProvider.executeOperation(TextFileDocumentProvider.java:456)
at org.eclipse.ui.editors.text.TextFileDocumentProvider.saveDocument(TextFileDocumentProvider.java:772)
at org.eclipse.ui.texteditor.AbstractTextEditor.performSave(AbstractTextEditor.java:5073)
at org.eclipse.ui.texteditor.AbstractTextEditor.doSave(AbstractTextEditor.java:4863)
at org.eclipse.wst.sse.ui.StructuredTextEditor.doSave(StructuredTextEditor.java:1916)
at com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor.doSave(AndroidXmlEditor.java:626)
at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.doSave(CommonXmlEditor.java:243)
at org.eclipse.ui.internal.SaveableHelper$2.run(SaveableHelper.java:150)
at org.eclipse.ui.internal.SaveableHelper$5.run(SaveableHelper.java:276)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at org.eclipse.ui.internal.WorkbenchWindow$13.run(WorkbenchWindow.java:1818)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:1815)
at org.eclipse.ui.internal.SaveableHelper.runProgressMonitorOperation(SaveableHelper.java:284)
at org.eclipse.ui.internal.SaveableHelper.runProgressMonitorOperation(SaveableHelper.java:263)
at org.eclipse.ui.internal.SaveableHelper.savePart(SaveableHelper.java:155)
at org.eclipse.ui.internal.WorkbenchPage.saveSaveable(WorkbenchPage.java:3769)
at org.eclipse.ui.internal.WorkbenchPage.saveEditor(WorkbenchPage.java:3782)
at org.eclipse.ui.internal.handlers.SaveHandler.execute(SaveHandler.java:53)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:290)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:90)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:243)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:224)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:167)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:499)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:213)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.executeCommand(KeyBindingDispatcher.java:285)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.press(KeyBindingDispatcher.java:504)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.processKeyEvent(KeyBindingDispatcher.java:555)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.filterKeySequenceBindings(KeyBindingDispatcher.java:376)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher.access$0(KeyBindingDispatcher.java:322)
at org.eclipse.e4.ui.bindings.keys.KeyBindingDispatcher$KeyDownFilter.handleEvent(KeyBindingDispatcher.java:84)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1262)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1056)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1081)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1066)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1108)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1104)
at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1525)
at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4723)
at org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:344)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4611)
at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:340)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4977)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2549)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:138)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:610)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
【问题讨论】:
【参考方案1】:下一行中的Exception
...
java.lang.NumberFormatException: Color value '@drawable/bubble_me' must start with #
也就是说,Color
值必须以 #
开头。
假设,您的Color
值为
FFFFFF
那么将该颜色放入 XML 的正确格式是
#FFFFFF
其中,颜色值FFFFFF
以#
开头。
【讨论】:
我知道,但问题是@drawable/bubble_me 是 9patch png。它不是一个 xml 文件,所以我要把那个 # 符号放在哪里?简而言之,我认为这不应该发生。 您是说,它是 9patch 图像,但您的日志说它是Color
...请仔细检查您的资源。
这就是我要说的,我已经检查过了,我不可能有一个不是图像的@drawable/bubble_me,我安排了我的资源,我 100% 确定我的 drawable/ 中的所有文件都是图像,此外,我将所有动画放在 anim/ 中,所有布局都放在布局中,所有菜单都放在 menus/ 中,等等。以上是关于Android和Eclipse:9个补丁资源bug,导致aapt在尝试导出时崩溃的主要内容,如果未能解决你的问题,请参考以下文章