Using TabLayout in Android Eclipse project - android

I am trying to use a TabLayout in an Android project using Eclipse and Andmore but haven't been able to find a jar containing the required android.support.design.widget.TabLayout class.
Googling a bit, it seems I need the com.android.support:design:22.2.0 library. However, the latest version I can find in my SDK installation (under extras/android/support) is v17.
Where can I find this library (without having to migrate to Android Studio)?

Update your sdk using sdk manager.

With the help of a few other answers I finally managed to import everything. Putting it all together, just copyiing the jar into libs will not be sufficient. Here's how it works in Andmore (ADT should be similar but some options apparently differ):
Make sure your SDK is up to date. Specifically, you want the latest version of Extras > Android Support Library (should be version 22 or higher) and a matching version of Tools > Android SDK Build-tools.
If you have a copy of android-support-v4.jar in the libs folder of your app's source tree, replace it with a recent copy from <sdk>/extras/android/support/v7/appcompat/libs. (If you have other Android support JARs in that location, you may need to update those as well.)
Copy <sdk>/extras/android/support/v7/appcompat and <sdk>/extras/android/support/design into your workspace folder. (Not really necessary, but using a local copy will prevent polluting your SDK setup with Eclipse-generated files.
Select File > New... > Android Project.
Select Create project from existing source and select your copy of the appcompat folder. Be sure to select at least API 22 as a build target (I needed to use API 23, YMMV), and don't forget to give it a meaningful name.
When import has finished, open the properties of the new project, go to Android and check Is Library.
Repeat the same two steps to import the design library. After import, in its project properties, go to Android, and in Libraries add a reference to the appcompat project.
Open the properties of your app project, go to Android, and in Libraries add a reference to the design project.
I had to make some minor modifications to my source code as some resource identifiers are no longer constants as of API 14, requiring me to convert a switch statement to a series of ifs. After that, I could finally build my app.
This should work for other Android libraries as well – their locations are documented in http://developer.android.com/tools/support-library/features.html.
Edit: There may be an easier way: Both ADT and Andmore also have Android Tools > Add Support Library, which might make a few of the aforementioned steps easier, which installs the most recent version of the support library. But you still have to add them to your project by hand.

Got it. Everything's there if you update your SDK to the latest version, things are just a bit hidden in the folder tree. You'll need three JARs:
extras/android/support/v7/appcompat/libs/android-support-v4.jar (the file was already in my project but I upgraded it anyway – not sure if it was necessary)
extras/android/support/v7/appcompat/libs/android-support-v7-appcompat.jar
extras/android/support/design/libs/android-support-design.jar
Copy these three to your project's libs dir, refresh your project in Eclipse (cleaning won't hurt as well) and you should be good.
Library locations are documented in http://developer.android.com/tools/support-library/features.html

Related

appcompat_v7 vs \v7\appcompat library project

When I once built some simple project, Eclipse automatically generated appcompat_v7 library project in my workspace and include it in dependency list for my original project. Meanwhile, I downloaded new support library (via SDK manager) few times. Then I tried to built again the same project, but this time in dependency section, I manually removed appcompat_v7 and added project generated by successful built of Android-SDK\extras\android\support\v7\appcompat library project. This time I faced few build errors in original project, most of them being unable to find resources that match name "TextAppearance.AppCompat. ..." as parent style of some style tag in res\values\styles.xml (of original project). What am I missing ?
Eclipse handles appcompat with many problems. You always must:
Have a copy of appcompat library loaded into your workspace to import it in your project as library
Use the same support library version in your project and in the appcompat library. If you update the support library, update it manually in the appcompat and your project. Right button click over appcompat/project, Android Tools -> Add Support Library.
If you have style compile problems with appcompat library, use compileSdkVersion = 23, targetSdkVersion = 22
Finally, I will recommend to migrate to Android Studio too, much easier and much cleaner.
Later, I made a copy of Android-SDK\extras\android\support\v7\appcompat library project into my workspace (check box when making "new Android project form existing code") and original project compiles well. I considered as better practice not to copy appcompat, but rather to work through reference to it. That way I would have valid link to new version, when I upgrade support library over time. However it appeared as better move to make a copy.

How to use/install certain library in Android Studio

I found this "amazing" library that i think it would look nice in my small project but i don't find how to use it / how to install.
This is the url:
https://github.com/kmshack/Android-ParallaxHeaderViewPager
Thanks.
It seems to be available via Maven (see here). It might be an old version however. You could also import the project into Android Studio, build the jar and put it in your project's libs folder. A third option would be to make it build as part of your own project. For the latter you can use this for inspiration.

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 (:

Failed to build ActionBarSherlock in IntelliJ IDEA

I had included the library module ActionBarSherlock to my project.
Minimal SDK version is 10, target SDK - 13 for both the projects.
But when I'm trying to build the project, I'm getting a lot of errors like:
[Library] /Users/rankor777/src/ActionBarSherlock/library/res/values-v14/abs__styles.xml:4: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ActionBar'.
Why?
Download ActionBarSherlock zip file and extract it next to your application module which will make use of ActionBarSherlock.
Select File->Import Module from IntelliJ IDEASelect library folder under ActionBarSherlock folder and import it as a new module. It will be imported as an Android library module.
Open module settings of ActionBarSherlock library module and export android-support-v4.jar dependency
Open module settings of your application which will make use of ActionBarSherlock and add a new Module Dependency
Select ActionBarSherlock from the list of modules
See step by step instructions with pictures
PS:Some tutorials on the internet directs you to add android-support-v4.jar to your application’s libs folder and add as a library dependency. Since ActionBarSherlock already includes it you do not have to do it, just export it from ActionBarSherlock. If you also add android-support-v4.jar as a library to your own module you may get UNXPECTED TOP LEVEL EXCEPTION.
This issue, if I remember right, is cause by the Java compiler settings. Open the App Settings dialog, select Compiler -> Java Compiler and make sure that you have selected "Javac in-process (Java6+ only)" as the compiler you want to use.
FYI Google recommends using the lastest SDK to build against, so you should probably up your target SDK to 16.
You need to bump your target sdk. (Previous revisions of this Answer incorrectly said "you need to bump your min sdk, but that is incorrect as evidenced by the pasted ABS documentation below).
Even though it is intended to work on older versions of the Android platform, you must still compile ActionBarSherlock against 4.0 (or newer) release of the Android SDK.
Check here:
http://actionbarsherlock.com/usage.html
Requirements
Due to its use of the native action bar and its related classes on Ice
Cream Sandwich, the library requires that both it and your project are
compiled with Android 4.0 or newer. The project also requires that you
are compiling with JDK 1.6 in both your editor and any build systems
that you may be using.
Since the library is an extension of the official support library you
must also have the android-support-v4.jar referenced by your project.
Also here:
http://actionbarsherlock.com/faq.html
The library itself must be built against Android 4.0 (API level 14).
Your project should be built using the latest version of the SDK as
possible as long as it is 4.0 or newer.
Targetting API level 11 or newer is required as it will cause Android
to automatically add the native action bar when run on newer devices.
Since you will be compiling against new APIs but your app will likely
be run on devices with older versions of Android extra care must be
taken to either avoid using or properly check and call any methods
that were introduced after your minimum SDK version.
Go to File->Project Structure->Modules->You App->Dependencies. Click the + in the bottom left corner, and select Module Dependency. Choose ActionBarSherlock.
If it isn't there, make sure it is a library module - expand the ActionBarSherlock module and click Android, then check Is Library Project.

Expose an "Android Library Project"'s included jars to Projects which reference them

One of the newer functions of Android is the ability to create a Library Project.
This is great for unit testing and sharing common functionality across many apps you may be developing, but I seem to have stumbled upon a bug in their implementation.
When you have the following situation:
-LibraryProject contains LibraryProject/libs/folder/lib.jar in it's build path.
-ReferencingProject references LibraryProject.
From ReferencingProject you don't have access to anything inside lib.jar (Such as constant's used to communicate with methods in the Library Project).
A solution to this is to include "lib.jar" as an external library in the referencing project but this approach begins to negate the benefits you gain from having a self contained Library Project by creating multiple manually added references to resources which could move/change during the development of the library project (not to mention cause some pretty confusing errors).
Is there any way to expose an included libs classes to the referencing project without having to manually reference them as external jars?
As #Selvin says,
In the Library Project you can specify which libraries you want to mark as "exported" in the window brought up by using: Project properties => Java Build Path => Order and Export. From this example you would check libs/folder/lib.jar.
Clean and build the Library Project and the "exported" libraries are now included in the produced jar.
EDIT
This is a symptom of upgrading to ADT 17 - (Android Team: Perhaps put a few warnings on your release notes when an update breaks existing architectures?)
http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
If you don't want to add the library to the "Order and Export" then placing local jar's in /libs/ base folder will automatically add it to "Android Dependencies" which are exported in the jar created from your shared library.
EDIT2
Recent ADT upgrade would have you also manually select "Android Dependencies" as "Exported" in your Java Build Path. Again, warning would be nice.

Categories

Resources