ADT 21 and library projects - android

Yesterday I updated adt to v 21. Today, after minor corrections I rebuild and start project, but it crashes. In my project i use few library progects. ActionbarSherlock is one of them. Logcat says "java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable at..."

The solution in my case was different though.
We need to make sure that in the library projects there aren't projects with the same package name.
If 2 library projects have the same package name, the build process will not generate R for any of them. Changing the package name of one of them (so both libraries have different package names) fixed the issue.

After few minutes of looking to logcat and head scratching i noticed, that R classes for library projects hasn't been generated in my project /gen folder. Why? It's a secret for me.
I just rebuilded library projects, than my - it solves the problem.
From adt release notes:
Updated the build to generate R resource classes for library projects with only the IDs needed by the libraries, reducing the risk of hitting DEX file limits for fields and methods.
It seems adt just ignore library projects build under the version prior v21

Related

Android multidex support library using eclipse

Using Eclipse, is possible to generate an Android project using multidex for creating multiple
dex files? Searching over the net I found how to do that using gradle but nothing about to use that on
Eclipse without gradle
It looks like ADT's ant-tasks project is no longer maintained (it resides under 'legacy' folder).
So if you can't migrate to Gradle, you can edit the DexExecTask manually. You'll have of course to rebuild the project locally..
[Edit - 10/25/2014] maven-android-plugin does support multi-dex. However, it currently has a small issue: secondary dex files placed in wrong location. This pull request strives to fix that, so stay tuned! (Fixed in 4.0.0)

Android Library Project Java Files Not Working

I have two versions of an android library, one is paid and one is free. Rather than having to keep copying code and resources between them, I created an Android Library Project.
I created the library project, marked it as a library, and then set my paid and free projects to use the library as a library.
I copied everything synonymous between the paid/free projects into the library project (source code, drawables, layouts, etc) and works great EXCEPT for the source files.
The src file in my library project holds my source code in a package called "(default package)" except my free/paid projects aren't finding the files. They claim that they don't exist, even though it can find other things from my library, such as the drawables and layouts.
I've tried cleaning all of the projects, and I'm not sure what I'm doing wrong. Does anyone have an idea, or run into this problem before?
A library project requires a package name. Re-factor the project by Right-clicking on the package -> Refactor -> Rename.
Using the default package is generally discouraged.

ActionBarSherlock android-support-v4 jar checksum difference

Can someone explain why the android-support-v4.jar included with ActionBarSherlock has a different size (and, therefore, checksum) then the one added automatically by Android when setting up a new project? Are their customizations to the support code included with ActionBarSherlock? If not, is it safe to replace this jar with android-support-v13.jar since it already includes all of the code in android-support-v4.jar?
Remove the default android-support-v4.jar from android project and copy that jar from ActionBarSherlock library project. or vice verse. It is safe.
That will resolve the confict.
Reason
It would be the reason that our sdk copies the newer version of that jar into new project but ActionBarSherlock would have the older version of the same.
The android-support-v4.jar included in ActionBarSherlock is 5 months old. Since then Google has released several new versions of the support library. Since the two versions differ their checksums won't match.
It is safe to replace the version included in ABS with the version you're using in your main project.
This is a more elegant fix than deleting and adding files!
You just need to :
Right Click the project App Free
Go To "Android Tools" > "Add Support Library"
Approve the permissions and let it update the library
Repeat this process for the project App Library
The Android Support Library will then be in sync (:

Android SDKTools r21 library errors

I have updated today to the latest SDKTools, r21 and the projects are no longer packed correctly.
I am using for instance ActionBarSherlock as a library project, and when I run the application I get the following error :
java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable
I have reverted back to r20 and it works again.
Did anything changed, and we should add different the library projects? I can't see something like this in the Release General Notes.
Yeh, it is ADT r21 causing it.
http://tools.android.com/download/adt-21-preview#TOC-New-in-ADT-21-Preview-5
The R classes for library projects are generated with only the IDs needed by the libraries, reducing the risk of hitting dex files limits for fields and methods.
You need to clean up the bin folder in the library project manually.
You can check the update on Tor Norbye google+ page
https://plus.google.com/116539451797396019960/posts/KVax2483Erk
Same problem but i have fixed it.
What i did:
Project / Clean / Build on all library projects
Removed the library projects and readded it on the android project
Android Tools / Fix Project Properties on the android project
Project / Clean / Build on the android project
Hope this helps and is also working for you.

Building Android project with ant having a library project dependency on another library project

I have maybe this not so common setup:
(> = dependency)
Android project > Android library project 1 > Android library project 2
So I have an Android library project which has a dependency to another library project.
When I'm building project in Eclipse everythings works fine but I cannot get my build working with Ant.
First Ant compiles Android library project 2 which generates a classes.jar and puts this file in the bin folder.
Then Ant tries to compile the Android library project 1 but then I'm getting errors becouse it is missing classes from Android library project 2.
Well this is not so weird becouse the jar file is not included in the libs folders.
But in project.properties i've made a dependency to the library project 2 so why does Ant not copy the classes.jar to the libs folders of library project 1?
Well I can think of a solution to use an Ant task to copy the file to the libs folder, but then I have to modify the build.xml which I do not prefer.
** EDIT
The problem is that the R class is missing, when I look in classes.jar this java file does not contain the R class. So my solution would proberly not work.
This behaviour was caused by a change in R17 of the build tools: http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
In a nutshell: R files for libraries are no longer packaged in the classes.jar for that library. However, since the pareent.R for the parent-library (project1 in your example) also contains the resource-references for the 'child' library (project2 in your example), you don't have to refer to the child-R anyway.
Replace all project2.R-import statements in project1 with project1.R import statements and you should be fine.
For ant to compile add dependency in ant.properties.
eg:
android.library.reference.1=../path/to/library
This sounds like a very brittle setup - you may have good reason for this, but could you instead decouple the libraries dependence on each other?
For example; implement a bridge pattern to translate the calls between both libraries, and make the calling Android project attach them. This way, you have no code in either library that depends on the other, and the only project that needs to handle dependency setup is your main project.
One of the main reasons for using a library is to make the code re-usable, this approach ensures someone (you, a colleague, your successor...) could plug in just one library and create their own implementation of the other one.
Here is another good article on applying the bridge pattern in Java: http://java.dzone.com/articles/design-patterns-bridge
Well the problem was that the R class was missing.
So i removed the R class dependency between the two library projects.
I don't know if this is fixable but i think it is bad practice any way.
Without this dependency Ant builds fine.
Old question, but like me, others might be banging their head on this...
The official answer is "it cannot be done", specifically:
At build time, the libraries are merged with the application one at a time, starting from the lowest priority to the highest. Note that a library cannot itself reference another library and that, at build time, libraries are not merged with each other before being merged with the application.
(extracted from the official documentation: "Referencing a Library Project").
Which means that anything goes, as there is no "clean" way to do it with the tools (and dirty methods are in order).
Hope it helps

Categories

Resources