How to deal with library mismatches in 3rd party android libraries? - android

I'm writing an android app that uses both ActionBarSherlock and the Facebook Android SDK. Both these libraries provide android-support-v4.jar in their libs folder:
https://github.com/facebook/facebook-android-sdk/blob/master/libs/android-support-v4.jar
https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/libs/android-support-v4.jar
However, in the head revision both versions of the support jar are different. This causes builds of my app using eclipse to fail.
I'm using both libraries by including them in the repo of my app as git submodules. One solution would be to fork one of these libraries, update the version of android-support-v4.jar in the fork, and point my submodule to the fork. While perhaps this is the right way to go, somehow this feels wrong.
I wanted to know if there were other alternatives before I use the above method. A number of popular Android libraries seem to use maven, is using maven a good solution for solving this problem, and a good idea for android apps in general?

First of all Delete android-support-v4.jar from All(yourProject,FacebookSDK etc. ).
Then follow below steps:
Right Click on Project -> Android Tools -> Add Support Library and The again Right Click on Project -> Android Tools -> Fix Project Properties do same on Facebook SDK and Other Libraries.
and Clean-Build all your projects(Facebook SDK,your Project and Libraries).You are Done.

Related

Why "androidx.appcompat" and "android.support.v7" libraries are not compatible for some versions of Android Studio?

I made an android application using Android Studio during lectures at university. Then I uploaded the project to drive and when I got home, after I installed the latest Android Studio, I opened my project and almost every line of code was marked as libraries were not found.
I found that when developing on a computer I use android.support.v7.app.AppCompatActivity but it's not recognized at home. So I tried creating an empty project at home and I found it uses androidx.appcompat.app.AppCompatActivity.
A solution I tried, was to delete all imported libraries and then I let Android Studio to import what he needs, but it's stupid. I have to do that every time I switch the working station.
Why can't it be just one library? Is there other solution, not to re-import all the libraries?
Your problem is "uploaded the project to drive", that also saved the .idea folder where everything regarding the IDE and computer is stored. So you are opening a project on another computer with routes to your old computer. Solutions:
Close Android Studio and then delete the .idea and .gradle folder from the project, re-open it
File/Invalidate Cache and Restart
Recommended Solution Use a version control system like git. Android Studio does a pretty good job integrating with VCS. In the menus look for VCS/Enable Version Control Integration you need to install git previously and know how to use git.
There is another thing, the new AS version has a sync gradle icon, is an elefant with and arrow, sometimes big changes on gradle can go unnoticed so click it. There is also the usual, clean project or rebuild project.
The other part of the problem is: the different libraries. Androidx was introduced to consolidate in 1 library the support libraries. It is recommended to use it. If the latest version of Android Studio dont support it then you will have to, and also update the IDE on the other desktop
You can't mix AndroidX library with support library in modern android application development. support is already deprecated and AndroidX is future. So, migrate your existing project to AndroidX
With Android Studio 3.2 and higher, you can migrate an existing
project to AndroidX by selecting Refactor > Migrate to AndroidX from
the menu bar.
Check official documents for more information

How to add 3rd party libraries to unity android build using Android Studio

I have this Unity 5.4 project, and I build it separately for iOS and Android.
On the iOS side, life is rather easy. Unity generates an XCode project which I then use cocoapods to add 3rd party libraries to.
On the Android side, the Android Project that Unity "builds" (exports), is not a standard Android Studio project, and you need to import it, instead of just opening it.
This leads to some complications, beyond my grasp of how Android studio works.
I believe it all boils down to getting Gradle to include the 3rd party libraries into the build, but since the app does not start the regular way, things don't end up running.
Has anyone added 3rd party libraries to a Unity/Android Studio project? any pointers will be appreciated.
If the third party libraries are in aar/jar format, there is an option in the "inspector" tab to include them when Unity builds.
Usually you will be able to find .aar / .jar versions of the library you want on jCenter or Maven.
Another way is to see if the source code is hosted on Github, and build it into an .aar/.jar yourself in Android Studio

Using Android Support Libraries w/o an IDE

I'm using the Android SDK as a standalone version (since I don't like IDEs very much).
However, now I wanted to use the Support Libraries and downloaded them with the ./android tool. And I checked that the /extras/android/support/v4/android-support-v4.jar exists.
Yet, my compiler doesn't seem to recoginize them (error: package android.support does not exist).
I believe that I have to get them in my classpath somehow, but have no idea how this should work (on the android page it is only explained for IDEs).
Any suggestions?
While the Android Support library documentation focuses on the two main IDEs, the documentation on command-line projects has instructions on how to reference an Android library project.
I needed to specifically get the support libraries (a jar file) to be included in a legacy ant-based Android build, and I wasn't able to get the command line suggested by the links from CommonsWare to work (specifically, the suggestions from https://developer.android.com/tools/projects/projects-cmdline.html#ReferencingLibraryProject required that I actually have a full project to reference.)
As it turns out, all I had to do was put the support library jar (eg: android-support-v4.jar) in the project's lib directory and everything worked. That may be specific to the ant build I'm using, but I think it's the same build file that the google tools used to generate.

Facebook SDK for Android duplicate support library on dependencies

I have implemented the new Facebook SDK 3.0 beta. The library project contains the Android support library v4. I also have the support library on my own proyect (a different version though). When I add the Facebook SDK as a library I get the next error on the console:
Jar mismatch! Fix your dependencies
Found 2 versions of android-support-v4.jar in the dependency list,
but not all the versions are identical (check is based on SHA-1 only at this time).
All versions of the libraries must be the same at this time.
I've tried to exclude the libs folder on the buildpath, but the error remains.
I have to put the same .jar in both places. Am I missing something here? The idea is to use the support library of my own project (to keep it updated).
It seems like the different projects are using two separate support libraries and therefore the checksum is different.
You must repeat this for both the Facebook SDK project and the app you are building.
What I do when I get this error is:
Right click the project.
Hover over Android Tools.
Click on "Add support library..."
Accept the downloading of the library.
This insures two things: a. you get the newest version of the support library from the Google sources, and b. you have the EXACT same library in all your projects.
Happy coding!
Simply delete the one in your project, remove it from the class path and try rebuild your project.
Installing the same version of support libraries via menus mentioned in the top answer is quite a good solution.
Although this sometimes didn't work for me (I think it has something to do with my Workspace folder being synced with Dropbox, so Eclipse won't overwrite files sometimes) so the approach I am using is to link the support library from the central place.
There are these JAR files inside your SDK folder (C:\Program Files (x86)\Android\android-sdk\extras\android\ on Windows for example) which is being updated when you run SDK manager, so you could just reference that one from both the Facebook (or any other library) and your projects. Since in the end, code from JAR files gets packed to your classes.dex. You don't even need the support library in the libs folder.
Also: If you use the Gradle build system and its dependency management or even Maven you will not have problems like these, but they require more time and knowledge to set-up correctly.

Eclipse can't remember included "Android Library Projects"

I have several Android Projects marked as "Library Projects". I also have several Projects which use them, obviously.
The problem is, sometimes if I restart eclipse, all those Classes used from Library Projects are marked as "Not Found" and I can't quickfix that (using imports, etc.)
The only way I can fix it is right-click the project which includes library projects, remove all library projects, apply, then add them again. That is REALLY annoying, and I'd like to fix this permanently.
The Projects are using Android Library Projects and are not Library projects themselves. Eclipse Version: 3.7.1 Build id: M20110909-1335
Try upgrading your Eclipse ADT plugin to the 15.0.1 release that shipped earlier this week. After one last fixup using the steps you outlined above, I haven't had a recurrence of this problem.

Categories

Resources