Tag Archives: ADT

Small issue with ADT 20 and SDK 16 and how to fix it

The latest version of the Android Developer Tools (ADT) brought a lot of improvements for us developers. Sadly there is a little quirk coming with it too.

If you have a project targeting API 16/Jelly Bean and you are using ADT 20, you might have some problems with the Graphical Layout tool. Instead of displaying the UI, you may end up with the following screen :

The error message is java.util.LinkedHashMap.eldest()Ljava/util/Map$Entry; which is totally clear… or not.
By looking inside Eclipse, we can find the corresponding complete Stacktrace :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
java.lang.NoSuchMethodError: java.util.LinkedHashMap.eldest()Ljava/util/Map$Entry;
	at android.util.LruCache.trimToSize(LruCache.java:206)
	at android.util.LruCache.evictAll(LruCache.java:306)
	at android.widget.SpellChecker.resetSession(SpellChecker.java:141)
	at android.widget.SpellChecker.setLocale(SpellChecker.java:147)
	at android.widget.SpellChecker.<init>(SpellChecker.java:112)
	at android.widget.Editor.updateSpellCheckSpans(Editor.java:461)
	at android.widget.Editor.onAttachedToWindow(Editor.java:212)
	at android.widget.TextView.onAttachedToWindow(TextView.java:4455)
	at android.view.View.dispatchAttachedToWindow(View.java:11755)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
	at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2424)
	at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:37)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:329)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:331)
	at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
	at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)
	at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1640)
	at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1391)
	at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:1165)
	at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:679)
	at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:359)
	at org.eclipse.ui.part.MultiPageEditorPart.setActivePage(MultiPageEditorPart.java:1067)

After some research, I found a temporary solution on StackOverflow until this bug is fixed in the next patch of ADT.

The problem seems to be linked to the use of EditText with suggestions in Jelly Bean. On a phone there is no problem but in the Graphical Layout tool it breaks.
We have 2 solutions :

  • Disable the suggestions in the EditText with the inputType textNoSuggestions
    • It fixes the bug but it prevents the users from using the completion in your app. So let’s forget about it and look at the other solution
  • Switch the Graphical Layout to a different API (for example ICS/15 which is nearly the same as JB in terms of UI)

To do that, you just need to use the little droid on the top right and switch to 15 as shown in the screenshot below.

And voila ! :)

Update :
Xavier Ducrohet (who is working on the ADT tool) replied to my post on Google + and told me that the issue doesn’t come from ADT 20 but from the rendering library of Jelly Bean. So if I understand right, we need to wait for an update of JB to have a fix.

Update 2 :
The fix is available in ADT 20.0.1 ! So update the following elements and it will be good :

  • ADT Plugin in version 20.0.1
  • Android SDK Tools 20.0.1
  • Android SDL 16 rev 2

If you don’t see them, clear the cache of the SDK manager in the options

How to fix the “NoClassDefFoundError” with ADT 17

So I updated my SDK and ADT to version 17 and once again I got a big problem :)

Every project I have which use JAR libraries could still be built without problems but as soon as they start on the phone, they crashed with the following error :

03-21 19:20:56.455: E/AndroidRuntime(24471): FATAL EXCEPTION: main
03-21 19:20:56.455: E/AndroidRuntime(24471): java.lang.NoClassDefFoundError: org.acra.ACRA
03-21 19:20:56.455: E/AndroidRuntime(24471): at com.foxykeep.myproject.HomeActivity.onCreate(MyProjectApplication.java:127)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:969)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3925)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.ActivityThread.access$1300(ActivityThread.java:122)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1184)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.os.Looper.loop(Looper.java:137)
03-21 19:20:56.455: E/AndroidRuntime(24471): at android.app.ActivityThread.main(ActivityThread.java:4340)
03-21 19:20:56.455: E/AndroidRuntime(24471): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 19:20:56.455: E/AndroidRuntime(24471): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 19:20:56.455: E/AndroidRuntime(24471): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-21 19:20:56.455: E/AndroidRuntime(24471): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-21 19:20:56.455: E/AndroidRuntime(24471): at dalvik.system.NativeStart.main(Native Method)

I asked Xavier Ducrohet and Tor Norbye (both working on the ADT plugin) on Google+ about the error and they linked to this page which explains how to solve the problem but is not ultra clear (at least for me).

So here is the same solution but explained with screenshots so we can see more easily what changed  :

From left to right, we have :

  • My project with ADT 16 (the small graphic changes are due to the fact the left image is from Eclipse Windows while the 2 on the right are from Eclipse Mac)
  • My project with ADT 17 before the fix
  • My project with ADT 17 after the fix
We can see :
  • In blue, the changes due to the patch (more info on this at the end of this post)
  • In red, the changes for the fix

What I did to fix the bug was :

  • Remove the libraries from the standard Java build path :
    • Right click on the project name > Properties > Java Build Path > tab Libraries > remove everything except the “Android X.X” (2.3.3 in my case) and the “Android Dependencies”
  • Rename the libraries folder from “lib” to “libs”
    • By doing that, all the libraries in the folder “libs” are found by the Android plugin and are added to the “Android Dependencies” item of the project
  • Clean the project (not exactly needed)
  • You are good to go !

This problem is due to the fact that libraries are not managed the same way with the new ADT build.
Instead of having 2 different managements of libraries (one for Android Library Projects, one for the standard jars), now both are merged into the Android Dependencies item.

Other info, the annotations.jar file is for the new lint Java annotations (more info here : http://tools.android.com/recent/ignoringlintwarnings)
Besides this small problem, the ADT version 17 looks really good and I love the new things added to the lint checks !!

[Update]

The DroidUX Team found another solution to fix the problem. I didn’t test it personally but it don’t see why it shouldn’t work : 

Hi,

Just to add to the solution:

If you have references to jars that are not in the ‘libs’ folder, for example if you use ‘classpath variable’, you can resolve the NoClassDefFoundError issue with the new ADT 17 by exporting the references.

To export the references: simply go to “Properties > Java Build Path > Order and Export”, and check all the references you want exported.

Cheers,

DroidUX Team

[/Update]

How to fix the “Conversion to Dalvik format failed with error 1″ with ADT 14

Today I updated my SDK and ADT to the 14 version and I had a big problem !!

Every project I had which used Android Library Project couldn’t be launched on a terminal and crashed during the APK generation with the following error :

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/foxykeep/datadroid/config/LogConfig;
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.run(Main.java:206)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at java.lang.reflect.Method.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:179)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:729)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:602)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:629)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:172)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:282)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:363)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project$1.run(Project.java:545)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:524)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project.build(Project.java:123)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.project.ProjectHelper.build(ProjectHelper.java:869)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:146)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:702)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:924)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1128)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2011-10-19 15:19:18 - MyProject] Dx
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lgreendroid/app/ActionBarActivity;
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.dx.command.dexer.Main.run(Main.java:206)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at java.lang.reflect.Method.invoke(Unknown Source)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:179)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:729)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:602)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:629)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:172)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:282)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:363)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project$1.run(Project.java:545)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:524)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.resources.Project.build(Project.java:123)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.project.ProjectHelper.build(ProjectHelper.java:869)
[2011-10-19 15:19:18 - MyProject] Dx 	at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:146)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:853)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:702)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:924)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1128)
[2011-10-19 15:19:18 - MyProject] Dx 	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2011-10-19 15:19:23 - MyProject] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.ksoap2.transport.KeepAliveHttpsTransportSE$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
[2011-10-19 15:19:23 - MyProject] Dx 2 errors; aborting
[2011-10-19 15:19:23 - MyProject] Conversion to Dalvik format failed with error 1

After searching the web and finding this existing bug in the Android bugtracker, I found the reason of this crash . Below you can see my project hierarchy before and after the update from ADT 12 to ADT 14 :

There is only 3 visible differences : “Library Projects” and a “bin” folder and the “default.properties” has been rename to “project.properties”.

The problem here is that the Library Projects elements contains for each Android Library Projects a jar file with the source code. At the same time we still have the GreenDroid_src and DataDroid_src elements which also contains the source code of the libraries. So we have duplicated code in our projects as mentioned in the error.

I think the update should have removed the useless X_src elements but it’s not the case. So we will have to do it manually :

  1. For each X_src element,right click on it and then Build Path > Remove from build path.
  2. A popup will open. Make sure that “Also unlink the folder from the project” is checked and then accept it.
Your project should changed from the left image to the right one :

Now you can launch your project and it should work !

Page optimized by WP Minify WordPress Plugin