Problem: How to remove Realm .so files in library (aar) published using jitpack (leave only realm java files)
We currently moved part of our functionality to sdk, we are creating. Because Realm adds .so libs for each architecture, our sdk becomes too large.
I wanted to leave our RealmObjects in sdk, but remove native files (we actually use realm in our app, not in sdk).
Clarification:
We share our model for realm and retrofit, so this is why it should stay in sdk
Realm doesn't support inheritance for not realm-object so model can't be extended in app.
So my solution was to add packeging options:
packagingOptions {
exclude 'lib/mips/librealm-jni.so'
exclude 'lib/x86_64/librealm-jni.so'
exclude 'lib/x86/librealm-jni.so'
exclude 'lib/arm64-v8a/librealm-jni.so'
exclude 'lib/armeabi-v7a/librealm-jni.so'
}
And it works well, but only when app using sdk adds it in build.grade. Using this in build.gradle for sdk doesn't work.
Questions
How can this be achived?
What are alternatives to solve this problem (having model in sdk, but having database for that model in app using sdk)?
Related
One library is using org.koin:koin-android:2.1.6 and other is using org.koin:koin-android:1.0.2.
Now if I use both of these libraries together, I get classDefNotFound.
If i force "2.1.6", second library starts crashing, and if i use "1.0.2" first starts crashing.
implementation('library') {
exclude group: 'org.koin', module: 'koin-android'
}
So exclude, force are not possible, as "koin" has added some new classes in their latest version.
What should be the solution in this case. Is it possible to keep different version of libraries, or define some kind of alias, so both libraries use their respective version without any issue.
I am developing my own SDK, which in turn depends on some 3rd party SDKS. For example - OkHttp.
Should I add OkHttp to my build.gradle, or let the users of my SDK include that? In this scenario, they will probably "anyway" use it, so its safe to say they already have it.
Another point to add - not all paths of my SDK needs "OkHttp", so, in theory, some user of my SDK could use those parts only, and have not OkHttp on his APK.
Another thing I am contemplating:
If I do embed OkHttp on by build.gradle - how can users of my SDK use that OkHttp library, instead of consuming another replica?
Should I add OkHttp to my build.gradle, or let the users of my SDK include that?
Adding the dependencies in build.gradle doesn't mean packaging the dependencies inside the aar file.
The aar file doesn't contain the transitive dependencies and doesn't have a pom file which describes the dependencies used by the library.
Uploading the artifact in a maven repository you will have your aar and a pom file which will contains the dependencies list.
In this way gradle will automatically download all the dependencies tree and you can configure gradle to exclude same libraries.
Use implementation and package it - the consumer can still exclude it.
One cannot depend on something and then not package it; this won't build.
In the application package, it can/must only exists once ...so what's the point?
I will answer your questions in a reverse order
Another thing I am contemplating: If I do embed OkHttp on by build.gradle - how can users of my SDK use that OkHttp library, instead of consuming another replica?
How Gradle build system works is suppose, In my project I use your library and I'm using v2 of OkHttp and your library is using V1 of OkHttp, then the gradle will automatically use the latest version. You can read about it here
Another point to add - not all paths of my SDK needs "OkHttp", so, in theory, some user of my SDK could use those parts only, and have not OkHttp on his APK.
In my project I use your library and it uses OkHttp, whereas I don't use it in my project also, I'm not using the part of your library where you are using OkHttp but still my APK will include OKHttp in it. This can be avoided either by splitting your library into two separate libraries or me using proguard in my Project.
Should I add OkHttp to my build.gradle, or let the users of my SDK include that? In this scenario, they will probably "anyway" use it, so its safe to say they already have it.
You should not bundle it in your library you just use implementation and let the user of your library decide if he wants to exclude it or not.
You need knows about api and implementation in the gradle
The link will be helpful
Api:
Role: Declaring ,API, dependencies
Consumable? no
Resolveable? no
Description: This is where you should declare dependencies which are transitively exported to consumers, for compile.
Implemetation:
Role: Declaring, implementation, dependencies
Consumable? no
Resolveable? no
Description: This is where you should declare dependencies which are purely internal and not meant to be exposed to consumers.
I'm developing an android app using android studio as IDE.
My question is:
How to exclude certain files under certain directory during the process of building APK?
In my case, I want to exclude some images from building since the those files used in my project are designated to be downloaded from network in-app while during the development I hope to refer them in the layout.
After googling, I found some solutions:
Gradle 1.2: Exclude directory under resources sourceSets
How to exclude file from resources using Gradle and Android Studio?
And reference from gradle.org
Then I came up my solution in build.gradle:
sourceSets {
main {
resources.exclude '**/drawable/*'
res.exclude '**/drawable/*'
}
}
But it doesn't work, the image under res/drawable/ still shows up(before downloading).
The Android Studio version is currently 0.8.4.
Any idea would be appreciated.
Exclude paths aren't currently supported for Android sourceSets. You can track this at bug https://code.google.com/p/android/issues/detail?id=64957
This is happening because Android sourceSets aren't the same as Java sourceSets; they're a custom implementation in the Android plugin, and don't automatically pick up all the features of their cousins. This will need to be specially implemented for Android, and it hasn't been done yet.
I'm developing an android app using android studio as IDE.
My question is:
How to exclude certain files under certain directory during the process of building APK?
In my case, I want to exclude some images from building since the those files used in my project are designated to be downloaded from network in-app while during the development I hope to refer them in the layout.
After googling, I found some solutions:
Gradle 1.2: Exclude directory under resources sourceSets
How to exclude file from resources using Gradle and Android Studio?
And reference from gradle.org
Then I came up my solution in build.gradle:
sourceSets {
main {
resources.exclude '**/drawable/*'
res.exclude '**/drawable/*'
}
}
But it doesn't work, the image under res/drawable/ still shows up(before downloading).
The Android Studio version is currently 0.8.4.
Any idea would be appreciated.
Exclude paths aren't currently supported for Android sourceSets. You can track this at bug https://code.google.com/p/android/issues/detail?id=64957
This is happening because Android sourceSets aren't the same as Java sourceSets; they're a custom implementation in the Android plugin, and don't automatically pick up all the features of their cousins. This will need to be specially implemented for Android, and it hasn't been done yet.
Basically, I'm using an open-source library in my main project. The library is included by compile project('<path-to-lib>'). The trouble is, there're a lot of files/classes/resources which I don't really need. I only need a small subset of those. Instead of deleting redundant parts, is there any way for me to write Groovy/Gradle script to pick only essential parts for building? This way, ideally, I can make minimal changes to the library.
In the build file for the library you can tailor the source sets to your needs. In general you write something like this:
apply plugin: 'java'
sourceSets {
main {
java {
exclude 'some/unwanted/package/**'
}
}
}
I'm assuming this is a plain Java library. If it's an Android library, the android-library plugin also supports exclude syntax in source sets.
Here's a SO question for reference:
Android Studio Exclude Class from build?
You can also read the Gradle docs for source sets at http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.SourceSet.html#org.gradle.api.tasks.SourceSet:java(groovy.lang.Closure) and the Java plugin at http://www.gradle.org/docs/current/userguide/java_plugin.html