We are using projectlombok in our android app. Our approach to use this library is -
We have added lombok.jar to the android studio - inside libs folder and using compile files('libs/lombok.jar')
However, on the project home page of projectlombok the approach explained to add it is like below,
dependencies {
compileOnly 'org.projectlombok:lombok:1.16.18'
}
Is there any performance or app-size impact of one approach over the other?
One of the biggest differences is the amount of work required to upgrade to a new version of the library. If you use Gradle, then all it takes is a small edit to your build.gradle file. The other option requires downloading the JAR file manually and copying it to the libs directory.
For JAR-only libraries, this difference is pretty small. However, for libraries which also include Android resources, a JAR file is insufficient. You have to build a AAR file instead and bring it into your build process. Gradle manages all of this for you.
Related
How do I add a library project (such as Youtube Jar) to Android Studio?
(Not to the old ADT Eclipse-based bundle, but to the new Android Studio.)
i have one more question i if i have old version of youtube library in jar and i never want to update its affected to my future versionof android app or not.
Inside your project's app folder, there is one directory named libs which is empty may be. You need to paste your .jar lib file inside that libs folder.
After then go to your app's build.gradle file. In it inside your dependencies{} block write this line of code.
Inside your app's build.gradle file:
dependencies {
implementation files('libs/youtube_or_your_jar_file_name.jar')
}
Hey I'm pretty new to android studio, and relatively new to android development and it recently occurred to me that I'm not sure whether to put libraries in the libs folder or set them up as as an external library - what's the difference?
Most of what I've found online explains how to include jar files in the libs folder and then compile in the app gradle. This is what I've tended to do, but I've seen projects that work differently and I'm wondering what the protocol is for this.
Also how do you make an external library? Do you just place the jar file in it?
Thanks!
There is no way to create an external library directly in Android Studio. You add a library to your libs folder or add a dependency to your build.gradle, then you reimport the project, and it appears as an external library.
In other words, there is no difference - it's the same thing.
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
I'm struggling to figure out how to import library projects into Android Studio in a fashion that makes them available to multiple projects. The documentation for the new build system implies that you need to import library projects into the root of the project you are working on:
Gradle projects can also depend on other gradle projects by using a multi-project setup. A multi-project setup usually works by having all the projects as sub folders of a given root project
(http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup)
This is problematic since, as I mentioned above, I would like to keep frequently-used libraries accessible to all current and future projects. For example, I am currently trying to integrate Volley into a new project to evaluate it, with the assumption that I will want to use it in multiple other projects in the future. I cloned it to my "${PROJECT_ROOT}/" folder, which is the same level at which I created my test project, giving me:
${PROJECT_ROOT}/TestProject/Test
${PROJECT_ROOT}/volley
After trying to set up my project's build.gradle file in a variety of ways, the only way that I've managed to make the app compile is to move Volley into the TestProject 'main' project, giving me:
${PROJECT_ROOT}/TestProject/Test
${PROJECT_ROOT}/TestProject/volley
Not only does this prevent me from using Volley in other projects that are not a part of TestProject without duplicating it or cloning it a second time, but it means that git wants me to add it to the repo I've established at the root of TestProject.
How can I reference library projects in my Android Studio projects without including them in the projects themselves?
Couldn't you use git with submodules? e.g. In your .gitmodules file, you may add this:
[submodule "volley"]
path = volley
url = https://path/to/volley/repository
You can set the url to Volley's official repository, or to your own in-house version of volley. Other projects can be setup the same way and point to the same volley repository.
I think this way, other users can call git clone and all the dependent projects will be downloaded within the main project folder and they don't have to worry about downloading the library projects separately.
For Volley though, I would just compile it into a JAR file and stick it into the /libs folder of the main project. That is, if you don't need to modify its source.
[Update]
For library projects that you don't need to modify its source, you can try using Android Studio to compile them into AAR files for sharing. AAR file is like a JAR file to Android, so you can add them to your /lib source folder, or publish them to your local/intranet maven repository. If you choose the maven route, add your local/intranet repository in build.gradle, and reference the library project that you've published.
Hopefully in the future more Library projects owner will build their projects into AAR file and publish them to Maven Central Repository, so we can just reference them directly from the build.gradle file.
My objective is to create a single distributable jar file for Android projects which includes a few other jar files. As I understand a "standard" jar file is not allowed to have other jar files inside, so guess I need to learn a trick here.
I have been trying to set up One-Jar for this, but I keep hitting
issues. Are there any dev guides for using One-jar with Android projects (using Eclipse)?
Are there any other good alternatives out there I should look at?
jarjar is pretty good at this. When you use it together with Maven its super easy to make a large collection of dependencies a single jar.
Although, there's nothing stopping you including multiple jars as dependencies in an Android project.