How to use github libraries that has no gradle installation? - android

I've seen lots of libraries in github that has no dependencies for adding them to a project.
The questions are:
How can I use these libraries?
How can I add them to my project?
For instance, this is a gitbub project that I don't know how to use those:
https://github.com/zzhouj/Android-SlidingUpPanel

Normally, you would download a JAR file - if any - or download the project and build the JAR yourself (like you would do for Volley project). But if there is no JAR support, like Android-SlidingUpPanel, just download it and add it as a module in your project.

Try doing this way;
download android-support-v4.jar, add to your LIBS folder,
build project.

Related

Avoid code duplication in Android Studio modules

I've created a project and a library separately using Android Studio, each in a separate folder inside some directory.
I tried to add the library as a module to the project, and noticed that instead of just referencing the library like in Eclipse, the library was copied inside the project directory.
That means that if this happened N times for N projects, then I'll have N copies of the library and I'll need to update them all when any update is to be done.
I'm working on v 1.0.2 of Android Studio.
Any one has a better idea to do it?
Three options I know of:
You can specify the path to the external library:
Android studio add external project to build.gradle
Include the compiled jar file from the library in the libs directory of the N apps.
Publish the artifact (the jar from library project) to a gradle repository and then you can add dependencies to that project just like you would for the support library etc.
See http://gradle.org/docs/current/userguide/artifact_management.html

How to include libraries which both depend on the same library?

My project depends on two libraries, one is ActionBarSherlock and the other is the Facebook SDK.
Both of these library projects depend on the android-support-library.
The problem is now, if I include this library in both library projects, I´m getting this build error
Android Dex: [MyApp] Unable to execute DX
Android Dex: [MyApp] com.android.dex.DexException: Multiple dex files define Landroid/support/v4/view/PagerAdapter;
How can I manage to let both libraries depend on the same library?
This error usually shows up when you have two different versions of the jar file in your app. Just make sure to include the same jar in both your libraries, and the jar will only be included once in the APK.
TO overcome this problem solution is you must have same support library in your all library and main project for that you need to select every project and add support lib as bellow
Right click project
Android tools
Add support library
Repit for all projects done!!
include the android support library in the ActionBarSherlock lib, and then include the ActionBarSherlock library in the Facebook library , and finally include the Facebook library into your project.
At Last : Clean your project
1. Right click on the Project Name
2. Select Build Path -> Configure Build Path
3. In Java Build Path, go to the tab Order and Export
4. Unchecked your .jar library
hope so it help you....:)
Well I had the same problem. I solved it by doing this-
1- go to the libs directory of your project. There would be android support library's jar file which would be from Google. Delete this jar.
2- Copy the android support library jar from Facebook SDK's lib directory.
3- Paste this jar in libs directory in your project(the same place where you have deleted the jar provided by Google in step 1).
4- Now right click on this jar. Select 'Build path'. Select 'Add to build path'
You are done.
Now you have the same JAR file, which is provided packaged in the Facebook SDK at all places.
Note: Copying in the reverse way i.e. copying the Google provided support jar into Facebook SDK did not work for me. It was not able to get LocalBroadcastManager. I do not know why.

Android Dex: UNEXPECTED TOP-LEVEL EXCEPTION: Already added

My app depends on a library project. This library project depends on the Android Compatibility Package V4. I have NOT exported the library project's dependency. In my own project, I've added ACL V13 as a dependency, but when compiling I get the error that essentially there's a duplicate dependency. I thought not exporting the library project's dependency would resolve this issue, but it's not.
How can I resolve this?
EDIT
Also, according to Android tools docs:
Special case for android-support-v4.jar and android-support-v13.jar.
We make a special case for these two libraries because -v13 contains a
full version of -v4 inside. If both are found, then only -v13 will be
used.
So it should just work...
If you use exactly the same lib jar in different projects (libs project or standard projects), the apk tools get rid automatically of the duplicate ones.
The problem starts when you have two libs with the same name but not at the same revision.
The android-support-v4.jar and android-support-v13.jar files can be from different revision since there always have the same name in different support package release (http://developer.android.com/tools/extras/support-library.html#Notes)
I would check that you use exactly the same revision of the support libs in your main project and in your lib project.
To make sure, copy the two support libraries jars (located in the android-sdk folder) to your projects libs folder.
{android-sdk}/extras/android/support/v4/android-support-v4.jar
AND
{android-sdk}/extras/android/support/v13/android-support-v13.jar
It should get rid of the problem.
Delete the v4 package from the library.
Clean the Projects.
In my case, I had just updated one of the JARs in the libs/ folder to a new version.
All it took to fix it was to run Build -> Rebuild Project, i.e. issue a 'clean' task before the 'assembleDebug' etc.
Well, in my story I had to delete module dependencies which were the same, add it in library, and then add this library to each module as a dependence.
So:
Module a : Depends on android-v4 (and has it in it's lib folder)
Module b : Depends on android-v4 (and has it in it's lib folder)
Add to libraries of project "android-v4" (for ex from 1st module). Delete it in module b lib folder.
Delete in modules a and b dependence of android-v4
Add to each module dependence -> library -> android-v4 (which you created in 2 step)
I'm not sure if it is the right solution but it works.
Have you tried to change the dependency of the library from v4 to v13 and export it?
Sometimes simply removing v4 support library does not work, you also need to rebuild or the project.

How to put an external library project to my one?

I want to use a svg-android library to work with *.svg files in Android. For the same, I've installed the apache ant, created a folder in workspace called: SVGAndroid and then added
android.library.reference.1=C:\Android\workspace\SVGAndroid
to project.properties file.
There were no documentation for functions in ReadMe, so I'm wondering if the installation correct or not, how to reinstall an external lib in the second case and where are the examples of using svg-android?
For your including of the project, just include the project into your workspace and in your respective application under the properties of that project just add a dependency on a library that references svgandroid. Make SURE to include the files and ensure that the compile class files are present in the final output of the apk. This typically means that you add the project to your build path/order.
Another approach is to just take the entire project and compile it into a jar file and then include that jar in your libs folder and add that dependency on the jar file of that respective project to your core application.
Useful links
How can I use external JARs in an Android project?
I would rather suggest to not add the path to the project manually, but from Project Properties -> Android and you will have a list with all the library projects in the workspace from which you can choose the desired project.
Also I suggest adding in project.properties the following line:
manifestmerger.enabled=true
in order to have all the AndroidManifest.xml files of the referenced library projects merged into the main project's manifest.
If you want to include a library file in to your project follow the below steps;
Download a jar file and save it in any folder.
open your project.
Right click--> Build path--> Add External Archives---> Add your external jar file to your project

Including Library Projects in Project Android

Is there a way to include a library project in a project without it being a separate project? The ideal situation is to be able to make code changes to the library project and push it to the git repo with the main referencing project.
You can add libraries to your build path.
You can export the library project as a jar file and then you can add that jar file in your libs folder and configure your build path to add it to your project.

Categories

Resources