What is difference between adding external jar and using library project in android?
can we extract jar from library project and import it as external jar in our main application?
What is difference between adding external jar and using library project in android?
There is almost no difference in achieving a task between these two except a minor digression. That is if you add jar, you have to go with whatever defined in that external jar and the features that jar provides can't be changed. If you include library project, you can play with the source code and make changes to the features if you don't want to go with the default features. Both have their own cons and pros.
As I said, by including library project, you can customize the features, but you may not know whether if affects any other things that depends on the feature you are playing with. But that's not a big deal if you are very wary. Adding a jar wouldn't let you customize but then again it's easy to follow the pre-defined features :). Hope this helps.
For your second question: can we extract jar from library project and import it as external jar in our main application?
Not exactly, but you can. See this great answer given by CommonsWare with many restrictions.
Related
How I can use com.android.setupwizardlib in my project?
This library isn't on jcenter or as gradle dependency.
This library is used in some apps (Such as Greenify) and it uses the XML tag com.android.setupwizardlib.SetupWizardLayout in my Activity
Any solutions about it?
I know how to import a library, I only need help with this specific google library
Greenify SetupWizardLib
It would be simpler for you to use existing packaged libraries for this functionality, such as some of these or a couple of these.
Otherwise, grab the source code and resources, add them to your project (directly or via a separate library module), and make changes as needed to get it to build.
I want to create an Android jar library which has activities which use layouts that are all within the jar file.
I have been researching and trying different methods for the last few days and exhausted the related posts here. I have managed to get drawables and other raw assets to reside and be loaded from within the jar. However I have not been able to include valid resources which include the layouts. The official view is that it is not supported yet however I am sure it can be done.
I see that this is possible with .aar libraries when using Gradle but I am unsure if .aar libraries are compatible with older Android projects.
Could anyone shed some upto date info on this issue of resources/layouts in jar libraries and also the compatibility of .aar libraries.
Many thanks
I want to create an Android jar library which has activities which use layouts that are all within the jar file.
That is not possible, sorry. However, you are welcome to create an Android library project that serves this role, and that library project can ship a JAR instead of Java source code (see the Play Services SDK's library project for an example). The layouts would not be inside of the JAR file, though.
The official view is that it is not supported yet however I am sure it can be done.
I am sure that you are incorrect in your assessment.
I see that this is possible with .aar libraries when using Gradle but I am unsure if .aar libraries are compatible with older Android projects.
Project age has nothing really to do with it. If you are using Gradle, AAR files work. If you are not using Gradle, AAR files do not work.
I have split out common components into libraries using Eclipse. Everything works great. I have resources/etc in the library. However, I need to make the same functionality work with using make instead of Eclipse. I need the libraries to recompile every time the APK is made.
Completely a noob question, but everything I am finding deals with making it work in Eclipse or creating a Jar file and inserting it into the project.
Thanks - Keith
create jar file:
You could use the Export->Java->Runnable Jar to create a jar that includes its dependencies
check this tutorial, And this similar type question
I'm developing a software layer that I would like to reuse several time for building my Android applications. Basically I want that, once installed, the software layer any other apps can use it (like a system library).
I was wondering what is the best solution for doing this, when I found that recently Android supports library projects (http://developer.android.com/guide/developing/projects/projects-eclipse.html#SettingUpLibraryProject).
So I decided to create my software layer as a library project, making the code it contains re-usable by the other applications I want to realize.
My software layer depends on a set of external jar, which are correctly located in the lib folder of the library project.
The problem is that when I create a new project referencing the library project I'm not able to see the classes defined into the external jars of the library project: i.e. it seems that they are not part of the classpath.
So when referring to a library project is possible to re-use only the source code defined there? If my library project have some other libraries I have to import these libraries also in the other ones (I want to avoid this!)?
I'm also interested to know if there are other ways for doing this, but searching around I haven't found other ways for realizing Android libraries/shared code.
Thanks.
Android library projects definitely incorporate any JARs you have in the library project's libs/ directory. However, if you are using Eclipse, you probably have to somehow manually add those to your build path of the host project (the one reusing the library).
Ok I finally figured out that for solving this is sufficient to add the jars to the host project build-path (no need to re-import them, you can just choose the path from the library project). However it is weird that they are not automatically exported in the host project classpath.
I have an Android code base which uses APIs with settings to get different data for several apps. All apps use the same code base but with one or two design tweaks. So how do I re-use the main code base without having to copy the whole Android project each time?
iPhone uses multiple targets in the same project which works well. If android cant do this do I need to compile binaries of the code base in one project and then import into each new app project? If so how? I'm using Eclipse and am an intermediate Java developer.
Any help much appreciated!
Doug
Check out "Working With Library Projects" from the Android documentation. This should be just what you're looking for: http://developer.android.com/tools/projects/projects-eclipse.html#SettingUpLibraryProject
The current way to approach this issue if you are using Android Studio with Gradle is by using Gradle, Build Type + Product Flavor
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
Build Variants
One goal of the new build system is to enable creating different versions of the same application.
There are two main use cases:
Different versions of the same application
For instance, a free/demo version vs the “pro” paid application.
Same application packaged differently for multi-apk in Google Play Store.
This new concept is designed to help when the differences are very minimum. If the answer to “Is this the same application?” is yes, then this is probably the way to go over Library Projects.
Note: This answer is basically obsolete now that one can create .aar libraries with resources. It still works, though, and there may be times when the portability of a .jar is desirable, so I'm leaving it here.
Blumer's answer is a good one, and you should definitely look into Android's idea of library projects. However, there is another alternative. If you have a module that contains only Java code, but no resources of any kind (images, layouts, etc.), you can compile it to a .jar file separately and use the resulting .jar in multiple application projects. It works like this:
Create a new Java project in Eclipse (not an Android project) and move the source code of your module there.
If your module references any classes from the SDK, you'll need to add the Android SDK .jar to the project's classpath (Project > Properties > Java Build Path > Libraries > Add JAR).
When your module is ready to use, bundle up its .class files into a .jar. You can do this manually, or you can look around to figure out how to get Eclipse to do it for you.
Copy your module .jar file into the "libs" directory of your app's main project.
Add the module .jar to the project's classpath (again, Project > Properties > Java Build Path > Libraries > Add JAR).
Now you should be able to build multiple apps using the same .jar, while maintaining only one copy of the module's source code.
Depending on your particular situation, this may or may not work any better for you than the standard Android library mechanism. But it's worth considering as an alternative.
The Android documentation recommends another approach if there aren't too many "different APIs" used.
The idea is to use reflection instead of making direction references to the code. Make sure to use optimized reflection instead of lookups every time.
References
http://developer.android.com/training/multiple-apks/api.html
http://developer.android.com/google/play/publishing/multiple-apks.html#ApiLevelOptions
You might want to consider using a source control system like Subversion (or GIT). Keep your most feature complete version in the trunk, and make branches for your separate versions that use different data sources or require minor layout changes, etc.