Android library projects libs dependencies - android

I'm currently working on a project where I use multiple libraries. Multiple libraries use the android support library, so when I want to compile my app Eclipse complains about it with a Dalvik error. I already found out that I should only have the support library 1 time in my project. But, this breaks the library projects which causes that I cannot compile anymore.
How should I properly handle this?

If you use support library such as v4 and your project contains other library projects, you should keep the only one version of the v4 library. Choose one of the library file (the one that has the biggest size for example), remove all the duplicates and then copy this v4 into each project library which uses it.

Check if any of your libraries include the support library already. Maybe it's failing because it's already included.

Related

Android Support Libraries

Sorry might be silly question here. First of all i am a bit new to android.There is always confusion in my mind when it comes to Support Library. What killing me most is if I have multiple libraries in my dependencies and each use different Support Library versions. One use V4 and other use "v7" with different build version. Project it's self use another version. Wouldn't be any conflict or duplicate entries cuz each one has separate versions. :-)
Edited
Library A ( v7:22.1.1 )
Library B ( v4:19.1.0 )
Library C ( v4:18.0.0 )
app ( v4:18.0.0 )
As my expectation , there should be conflict but i can run project without any flaw which make me big confusion.
Edited
It is said that v7 include v4 so i removed support library in all sub modules and put v7 in app module. After i had changed ,i've errors and can't even build ..
Would be very appreciate for explanation cuz mostly all beginner might have those confusion
Actually v7 includes the v4 support library. There wont be any conflict and duplicate entries between them.
v4 Support Library
This library is designed to be used with Android 1.6 (API level 4) and higher. It includes the largest set of APIs compared to the other libraries, including support for application components, user interface features, accessibility, data handling, network connectivity, and programming utilities.
v7 Support Libraries
It contains several libraries designed to be used with Android 2.1 (API level 7) and higher. These libraries provide specific feature sets and can be included in your application independently from each other and added extra features.
v7 include v4 support library so if you are importing v7 than no need to add v4
You can check in v7 libs folder it includes v4 library
Now if you have multiple library(module) project which has some hierarchy than attach library to the main parent library and add that parent library to your sub library project or main project
Library_A (Required v4 or v7's some of the classes)
Library_A1 (Required v4 or v7's some of the classes)
Main_Porject(Final one)
Add Support v7 to Library_A only
Add Library_A to Library_A1 as a module
No need to add v7 to both Library_A & Library_A1 it can cause conflicts
Attach only Library_A1 to Main_Project as a Module.
And Using multiple v7 library with different version will cause problem.

Adding library with and without resources in android

I'm new to android development. I wanted to implement Navigation Drawer feature in my application, which requires android.support.v4.jar file to be included in my project. I'm using Android Studio to develop my application so I included the compile "com.android.support:support-v4:18.0.+" in my build.gradle file as mentioned in https://developer.android.com/tools/support-library/setup.html. My project is working fine, I was able to successfully include my library. I did adding library without resources.
What I couldn't figure out is the difference between adding library without resources and adding library with resources. Does adding library with resources mean including some sample project?
Thanks
For Android Studio projects using Gradle (which is what your project is), there isn't an important distinction between libraries with resources and without resources. The Gradle build system's support for Android is more advanced than anything available to Eclipse and can support libraries with and without resources the same way (you just add the compile statement to your dependencies as you have; you can also do it more easily via the Project Structure dialog).
In Eclipse, if you want to include a library with resources, you have to add it as a project (similar to an Android Studio module) to ensure the resources get included directly; there you can't include resourceful libraries as simple jar files.

including support library in project

When i create a new Android project with min sdk as 2.2 in Eclipse , the support libraries are automatically added to Android Private Libraries, Android Dependencies and libs. That's probably because I had setup a support library project(appcompat_v7) earlier as per https://developer.android.com/tools/support-library/setup.html.
So my question is there a better way to include the support libraries in a project rather than have it appear all over the place? Is this the expected way?
Latest ADT automatically creates a new Android library project called appcompat_v7 in your workspace. This library project contains all the jar-files needed for supporting older Android version.
When you create a new Android application project, it will automatically receives a new dependency on that library project. It looks there is a small bug in ADT causing android-support-v4.jar to be added twice. You can safely remove android-support-v4.jar from the libs folder, as this jar-file is already available in appcompat_v7.
The best practice would be to keep a dependency on appcompat_v7 and delete duplicated android-support-v4.jar file.

Adding multiple libraries on Android

I want to add multiples libraries on Android, but every one of them have the support library v4, and need them. I want to add : android-support-v7-appcompact, facebookSDK, PullToRefresh, google-play-services_lib.
I have DEX errors and NoClassDef errors every time.
For each project right click > Android Tools > Add Support Library
Although the support library is already added to the project it will download and install the latest version of the support library.
If you do this for each library project you should no longer see the error.
Hope this helps.
If the support library versions are not same there'll be error.
Either copy one of the support library v4 to all of them or delete all of the support libraries and just leave one of them

Jar mismatch scenario

I'm encountering a lot of jar mismatch errors lately and I'd like to avoid them in the future.
So, here's my question: suppose I have an app that uses 2 library projects, both of which use the v4 support library jar. In total, I have 3 jar files. What can I do to avoid the jar mismatch error?
All I've read so far is the case where you have a project and a single library project. In this case, I think your supposed to delete the jar file in the project and keep the one in the library project.
This is quite common if your project references several libraries, and each library references the same other library.
An example of this, your app is referencing the android support library v4, and you have 2 libraries which are also referencing the support library v4.
If you update your apps reference to the support library, but you don't update the support library v4 in your other libraries you will see this error.
The best thing is on each referenced library and your app, right click on the project > android tools > add support library. This will get the latest version and you should no longer see these errors.
If you're facing mismatch issue then simply copy one of them and paste in remaining libraries. E.g. as you've 3 v4 support library jars then copy one of them and paste at place of remaining two jars.
Try to understood by my example I used Map and Facebook in My project now Facebook,Map and my project have Android support jar so i removed Android Support jar from Facebook,My project but remain jar on Map,now i'm addded Android-Map-Extension as library project on Facebook And finally add Facebook library project on My project .....

Categories

Resources