Library giving java.lang.NoClassDefFoundError - android

I have an internal library hosted on a maven repo. And it is being downloaded successfully and I am able to access it. But once I run the code, it crashes saying that the retrofit library that my library uses cannot be found.
Although the build was successful when deploying the internal library and it works when I run it through the code of the library by including it as a submodule rather than a maven dependency.
EDIT
Ok. So I was able to fix the crash by including the retrofit library in my main project as a dependency as well (which was weird)
But now I am confused regarding "implementation" and "api" in gradle file.
My Understanding was that if I have built a library using retrofit as "implementation", making available my library through maven. That retrofit library will be available when some use my library. But it seems like if you use "implementation", you have to explicitly include that retrofit library in your project dependency as well.
Should I be using "api" so that my library automatically includes retrofit so that the main project doesn't require it to be added?

Related

Implementation vs API using maven dependency

I have a utility library that I have pushed to a JFrog artifactory.
Now I am able to include that library in another project through gradle implementation (Not including it as a submodule, but getting it from local maven repo).
My question is the utility library uses some other libraries which my main project also requires.
Now, in my understanding using "api" with internal dependencies of my utility library, should have allowed those dependencies to be available to my main project, but it's not happening.
I wanted some clarification on this as to how I can allow my library internal dependencies to be available to my main project. Because, otherwise I will just be importing them again in my main project, which I do not want to do.

Android: library project with play-services-auth results in NoClassDefFoundError

(This is basically the same question as in Android: library project with Retrofit results in NoClassDefFoundError but for play-services-auth).
I'm trying to build an android library project which uses play-services-auth to access SmartLock for Passwords.
It seems to be working as long as I use api instead of implementation on my gradle-dependency for com.google.android.gms:play-services-auth. It seems that this is the only dependency needing this (all others can used with implementation).
When using implementation here as well, the calling app will crash with NoClassDefFoundError:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/GoogleApiClient$Builder;
I'm using consumerProguardFiles with a bunch of proguard-rule-files (e.g. one for okhttp3, retrofit2 etc. from this repo). All this will then be packed into an AAR, so rules from the dependencies should be added as well.
It seems that I'm missing a proguard-rule for play-services-auth. Can somebody post the rules needed to use com.google.android.gms:play-services-auth in a library project?

Sample app runs fine with library as a module, but not as an external dependency?

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?

Gradle dependency from own server

I have some projects uses same code, for example my custom logger. I use Gradle for assembling my projects. I want to extract this logger as dependency for all project needs it. It is simple to add it as module for project, it is clear.
But I want to put this logger module (as Gradle module or aar) at my server and use link for it in dependencies for include into my project. There is guide how I can add my own project to maven central, but is it real to have just simple web-server for this purpose.

Android/Gradle: Where is this dependency embedded?

I'm using the new Android build system that is based on Gradle, together with the early access preview Android Studio. Now, I have two projects: an Android library project, and an Android app project (basically a demo for the library).
In the library project I have added a dependency to the gson library, so my build.gradle file looks like this:
dependencies {
compile 'com.android.support:support-v4:13.0.+'
compile 'com.google.code.gson:gson:2.2.+'
}
Still, everything works fine and dandy and I'm able to use gson in my library and then my app. But I want to understand where this library is embedded. I've opened both the .aar that is built by the library project and the .apk of the demo app. I was expecting to find the jars for the two dependencies in at least one of these, but I didn't.
So where are they?
From Android Tools website:
These items, plus the output of the compilation of the project’s own source code, are sent to dex for bytecode conversion and inclusion in the final APK.
In other words, they are in your *.dex file inside the APK.
As #SharkyXTS said, the code from any external dependencies is compiled into the final .dex file inside your APK. The reason why you can't find any references to these dependencies in the .aar is because there aren't any.
The .aar format is only supported through Maven for now, so dependencies are found through there. I believe there are plans to eventually support local .aar dependencies (without Maven), but the Android plugin isn't quite there yet. You can see this issue for more information.

Categories

Resources