Libraries do not get added to APK anymore after upgrade to ADT 22
Asked Answered
V

7

240

I have a rather big Android App project that is referencing several library projects. Everything was fine until i upgraded the eclipse ADT plugin to the newest version (v22). I also upgraded the SDK of course. I do not see any compile errors in eclipse, but when i run the project on the phone i get a NoClassDefFoundError.

java.lang.NoClassDefFoundError: org.acra.ACRA
....

The arca library is included in one of the referenced library project (in the libs folder) and i can see it in the "Android Private Libraries" in the package explorer, also as i said, no compile errors. The project runs fine on everyone else's computer that did not upgrade ADT.

I have already tried a whole bunch of stuff including but not limited to:

  • re-install the android SDK
  • download a fresh ADT bundle
  • delete all my code an get it again from git
  • copy the library in question to the app project
  • comment out the code that uses this library - i just get the same error for the next library

all without any success, so i'm getting really desperate here.

I would be really happy if anyone could give me a hint on how to solve that problem.

Vallecula answered 16/5, 2013 at 20:34 Comment(0)
F
336

Quoting Streets of Boston from his adt-dev post:

When upgrading, the 'Order and Export' of the new 'Android Private Libraries' is not always checked. And the android-support-v4.jar is now in this 'Android Private Libraries' section.

To fix this, go to 'Order and Export' and check 'Android Private Libraries'. Then refresh/clean/rebuild.

After you done this 'fix' for a library project, you may need to just close and re-open any depending project, because they may not see this 'fix' immediately.

Give this a shot and with luck it will solve your problem.

enter image description here

Fealty answered 16/5, 2013 at 20:35 Comment(25)
Hoora for the private libraries feature, maven developpers have been waiting for this for such a long time :)Alla
CommonsWare is like always one of the first pioneers, thank you so much! :)Overtask
Wow! Great finally, after fighting all day... Thanks CommonsWare! Do not know why every update they change this things.Brogan
That was it. Thanks a lot for the instructions. I wish Google had made it clear what they changed.Stamata
Avery new ADT version a new surprise ;) Hope the new build system will be better. Thank you CommonsWareUpbuild
You just got the badge for "Life Saving Drug", I completed client project, after updating it was not working and today is the submission. Thanks God found the solution else I was dead meat :)Kramlich
Is it just me, or does it sound wrong to have every Developer [that uses Eclipse and Libraries] go in to all of their library projects and mark "Android Private Libraries" as Exported? This makes me think that we have all mistaken the intention of Google adding this new "feature" in the first place. Maybe we aren't supposed to mark the Libraries as Exported. Maybe we are supposed to add any missing jar files directly to our "libs" folder. Ex: This would allow my library project to use the latest android-support-v4.jar [v13], while ABS internally uses android-support-v4-12.jar.Acheron
@swooby: "Is it just me, or does it sound wrong to have every Developer [that uses Eclipse and Libraries] go in to all of their library projects and mark "Android Private Libraries" as Exported?" -- it is "wrong" insofar as it is a bug, acknowledged by the people who wrote the tools. "Maybe we are supposed to add any missing jar files directly to our "libs" folder" -- oh, you need to do that too, as you have for the past year-and-change. However, you still have to check this checkbox.Fealty
@CommonsWare: So just to be clear, we need to tick the checkbox for "Android Private Libraries" under Order and Export, for all the projects, or just the library projects?Coarsegrained
@Phillip: AFAIK, it's all projects. More accurately, I suppose, it's all projects that have stuff in libs/, but you may as well check it for all, in case you add stuff to libs/ some months later and forget about this.Fealty
Thanks @Fealty for the saving answer; it too resolved my issue after two days of pulling my hair out. Like others have said, why isn't Google more clear about these subtle changes that lead people astray?? It says nothing about this on the download page: developer.android.com/sdk/index.html.Coarsegrained
OMG THIS WORKED!!!! Just upgraded to ADT22 as well. Thanks! I had to do a Project > Clean... as well before my app started working again :) I also had to check Android Dependencies as it wasn't checked by default.Calvert
I had to change the order as well as exportSasin
OK and what to do when you don't have an access to source code of native libraries? I have a couple of 3rd party .so files in /libs/armeabi folder and with latest SDK, they're not getting in the APK file at all. Do I have to contact 3rd party developer in order to rebuild them? Also, why is this connected to Eclipse? If I use command-line maven for build, how shall I proceed? Thank youStrode
They also changed the structure of Android SDK folders/tools. Apparently, this has been fixed in android-maven-plugin 3.6.0 (aapt issue), but with 3.6.0, I'm not able to get libs into APK. So, I have created symlinks for aapt, aidl and lib as suggested here stackoverflow.com/questions/16619143/… and stick to android-maven-plugin 3.1.1. Now, it works and I'm getting .so files into APK package. But anyway, this is not nice, Google at all...Strode
Hi @MartinC,@Fealty I am also facing same issue my code uses xtify library I done have source code for that... rest of my library projects I have updated with above solution, for this i have added jar in project lib but still i am getting ClassNotFoundException please helpSoothe
@R World I stick to older android maven plugin (3.1.1) and created symlinks for aapt, etc... then I don't have problem with .so files. They're part of apk file. But, If I use latest plugin (3.6.0), then I see this issue.Strode
@Strode I am not using maven plugin. I have one android library project which uses this xtify jar. this project i have added in my main andorid project. Now after doing this 'Android Private Libraries' project complies but in runtime ClassNotFoundException comes. please guide meSoothe
Thanks! I wonder why they would disable previously included libraries in 22?Talya
Renderscript broke with ADT 22 as well. While this fix (Streets of Boston solution just above) solved my V4-related issues, I went here to resolve Renderscript. Solutions there are hit-and-miss although I did find one that resolved the problem for me. See msgs #32 and #33 in that thread.Aliform
Then refresh/clean/rebuild . This is also imporatntLyon
I modded CommonsWare up for writing to check it all, despite its shotgun approach to solving the problem, because after a lot of effort rooting out the problem, that's pretty much what solved it. In my case, I had also added a Java library (not an Android project library) via the Libraries tab, and I could not get past the same run-time error SimonSays encountered without setting the checkbox to export this library. I encountered this problem after upgrading to ADT 22.Jeth
I think that if you use IntelliJ 12.x this is a problem, because even with the Export checkbox, there may be some crashes. I'm investigating.Higdon
@Fealty is answering everywhere, love their knowledge and the straight answer. ThanksValenta
Mine is already checked, still I have this problem, what to do?Oestrone
T
10

Simply checking Android Private Libraries was not enough, I also had to install Android SDK Build-tools in Android SDK Manager.

Tick answered 4/7, 2013 at 8:37 Comment(2)
I can't confirm this is required, but I did not get past the error SimonSays ran into before installing it. It may only require proper setting of the export checkboxes as described above, but felt I should mention that I did along the way install the Build Tools.Jeth
this works for me. only changing the eclipse preferences is not enough.you might need to check out the installed build-tools in android SDK manager.Pirnot
M
4

I had also the same problem and my adt was 22.0.1. And none of the solution above worked. Further when adding a external library project to a working project.I always check the gen folder of working project and if R of external library project is there (along with package name),then only external library project is exported. And on my gen folder no packagename of external library was shown.

So I checked on project.properties file and there wasn't any external library link present android.library.reference.1= present. So I manually added the external library reference there ,even though I had added from project->properties->Java Build Path->Projects->Add. So manually editing the project.properties did all the work for me.

enter image description here

Mcguigan answered 2/7, 2013 at 8:36 Comment(1)
I think it happened since the gui place to set android.library.reference.n is not java build path, but rather project->properties -> Android -> Library -> Add.... A gotcha.Ratsbane
L
4

I have encountered a similar problem, spent about 3 hours, but none of the proposed here decisions did not help... Finally I found a source of the problem: my project files & project.properties were read-only. Eclipse is simply silently ignoring any changes in library dependencies when I doing it in the GUI!

Lunetta answered 13/10, 2013 at 21:35 Comment(0)
A
3

I had the same problem. It was because of the eclipse project. To solve it I created a new project in eclipse, copy my existing project classes and resources into it and then launched eclipse again and added my custom includes.

Anomalous answered 3/6, 2013 at 9:45 Comment(1)
Too much hassle, CommonsWare's solution worked for me and I believe it would have worked for you too.Topping
M
2

I had the similar issue and my answer is slightly different from CommonsWare's. Here is my screenshot:

enter image description here

After checking the libs back in my build started to work again.

Mhd answered 13/6, 2013 at 22:7 Comment(1)
I would be careful with this solution. Android Dependencies got replaced by Android Private Libraries and might only be still in there for legacy reasons. I guess it could be removed at any time.Vallecula
S
0

I had also the same problem,

i) add gson lib as referecend librairies
ii) check it in java Build Path https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMAWVMrKmltX1ywKmMva3/Gldhs.png

Shorttempered answered 16/7, 2013 at 8:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.