Recently I started to venture into Android Studio, and one of the projects I'm working on requires a barcode reader, and a great solution I found was the ZXing library.
However, the following doubts arose:
To use this library I used the following commands:
compile 'com.google.zxing:core:3.2.1'
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
If the owner removes this library, will the next build of the application no longer have this library?
If not, would you have any way to work with it local / offline?
A compile directive works because the library is published in the maven central repo.
If you really want to secure that library, you would need to vendor it:
clone it in your own project
declare it as a module
Or: use the jitpack project, which allows you to reference a fork (your own GitHub copy) of the project in a compile directive.
See more at "How to compile forked library in Gradle?".
Related
What are dependencies ?
Why do we add dependencies ?
I searched a lot but could not find the answers to above questions.
In Android Studio, dependencies allows us to include external library or local jar files or other library modules in our Android project.
For example: Suppose I want to show some images in ImageView. But I'm using Glide Library to enhance the smoothness of application. So I have to add a dependency in the build.gradle(Module App) as:
compile 'com.github.bumptech.glide:glide:3.7.0'
So Now I can use Glide library :) and show my images.
Note: Glide library is the bumptech's library but still I can use it in my project from 1 line of code of dependency.
Whenever you add a dependency to your gradle file, it will download the added libraries, and add them to your project so that is available in your project. It makes it easy to manage external libraries in your project.
To study more , visit : https://developer.android.com/studio/build/dependencies.html
if you want to use external libraries or modules in your android
project you have to add the dependancies so that you may be given the
authority to use that particular library otherwise that will not be accessible to you inside the project.
so, its concluded that:
The Gradle build system in Android Studio makes it easy to include external binaries or other library modules to your build as dependencies. The dependencies can be located on your machine or in a remote repository, and any transitive dependencies they declare are automatically included as well
for further you can visit this link:
https://developer.android.com/studio/build/dependencies
I have a library which itself has a few dependencies, namely Realm, Retrofit, as well as a native library. The native library is on github and I can successfully pull it into my project via jitpack.
I have a sample app which im using to test this library. In my sample apps 'app' module build.gradle i my dependencies block looks somewhat like the following:
dependencies {
compile project(':sdk')
...
//compile realm,rx,retrofit, etc..
}
When doing this, my sample app works correctly.
Now lets say I either:
Grab the sdk's generated .jar file and put it in my sample apps /libs
Get the .aar and do the same as above
Put the repo on jitpack and try to download it via compile 'xxxx'
Trying to include the sdk in my sample app any of these other ways does not seem to work and spits out unhelpful errors.
What could possibly be the issue? I got a hint that it may be an issue with 'transitive dependencies' but am not sure where to start.
Ideas?
I have an android library and want to distribute it like jar.
I create the demo project that shows how my library works and add gradle dependency from my library:
compile project(':my-library')
Then I build the project, it works fine. Than I take jar file from my library (from build/intermediates/bundles/release - link), and put it to libs directory and replace the dependency with this:
compile fileTree(dir: 'libs', include: ['*.jar'])
But I was very surprised because the demo app did not work. I tried to clean, make jar more times, clear cache, test it on different Android versions from 4.0 till 6.0.1 but the same picture: it works if library is connected to sources, but does not work if library is connected like jar created from that sources.
My library is quite big, and I'm not sure what exactly goes wrong. In normal conditions it should load some javascript from server, run it and show some results in WebView, but in case of jar file I see only empty screen.
How is this possible?
I found an issue:
In my library I have dependency:
compile 'com.google.android.gms:play-services:8.4.0'
And don't have it on my demo project.
And it hungs on this lines, inside library:
Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(mContext);
The solution is to add dependency on demo also, use some other method to get Google Advertising id.
I am switching from Eclipse to Android Studio. I have couple of 3rd party libraries that I have added features or modified a little bit. Since the libraries in Eclipse are also projects and we can access the code, I had no problem.
In Android Studio compile tag in dependencies is great but in my case I cannot use it unfortunately.
I fork the project and made necessary changes and add the project as a module in Android Studio. Since the library project already has settings.gradle and example and library modules, there is a mess in my project and it does not compile at all.
Has anybody experienced such a problem? What to do and what is the correct way to forked libraries?
What we've done in my project is create gradle scripts for our dependencies that don't have them, and modify the gradle scripts for dependencies that do have them. Gradle does not play very well with modular dependencies, unfortunately: Each sub-project must know its place in the larger overall project. Since you've already forked the github project, modifying it further shouldn't be a problem.
I use Volley, like others, as networking library in my projects. So in most tutorials, guidelines suggest to clone the project and follow the boilerplate steps to build the project.
Does anybody have any idea, why Google has not built the project into a ready-made Jar file, in order to ease the way?
In order to use Volley in your application, you can use a couple of solutions:
Add following dependency to your app's build.gradle file (according to Android the easiest way):
dependencies {
compile 'com.android.volley:volley:1.1.0'
}
Cloning the Github repository and then set as a library. For a complete description please refer to Android developer.
git clone https://github.com/google/volley
If you are using gradle in Android Studio Volley can be added with one line to the gradle.build file's dependencies.
dependencies {
compile 'com.mcxiaoke.volley:library:1.0.+'
}
If you are using Eclipse, Volley can be added as a library project which will save you having to create a jar.
If you use git, you can add the volley library project as a submodule by using 'git submodule add'
https://android.googlesource.com/platform/frameworks/volley/