Android Studio: Exclude resource file under resources sourceSets - android

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.

Related

Is there a way to exclude a specific raw resource from an external dependency that is included when i build my android app bundle?

I'm using a library A in my app that in turn also uses another library B. Developers of library B left a raw resource used for testing purposes that is not used used during production but takes up 1mb which is a significant portion of my app bundle.
I want to exclude this resource when i build my app bundle.
I have tried using
packagingOptions {
exclude '/res/raw/file_name.mp3'
}
and
aaptOptions {
ignoreAssetsPattern "!file_name.mp3"
}
But none of them have worked so far.
Is there a way to do this through gradle or any other method ?.

More than one file was found with OS independent path 'META-INFmodule_debug.kotlin_module' in Android studio 4.0

Recently I have updated android studio to 4.0. After updating I am seeing this error when trying to build the project.
It's not frequent but still showing time to time when change something and build again the project.
More than one file was found with OS independent path 'META-INF/module_debug.kotlin_module'
I also added below line in my project build.gradle file in packaging options as mentioned in some other questions but still its not working:
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/*.kotlin_module'
}
Anyone else is facing this issue if so how did you solve it?
The mentioned workaround should work. If not, then make sure you are applying it to the affected module gradle file.

Android API Level Inconsistencies

So I am trying to use this library in my android app to be able to show pdf files. However, when I add the install line to my build.gradle file, Android Studio says that all Android support libraries should use the same version. This happens because the library uses com.android.support:support-compat:26.1.0 while my project is using com.android.support:appcompat-v7:28.0.0.
I want to know if there is a way to get around this and use the library in my project, or if I would have to fork and update the library myself to make it work.
Any help is appreciated.
simply exclude it from the build:
api ("com.github.barteksc:android-pdf-viewer:2.8.2") {
exclude group: "com.android.support", module: "appcompat-v7"
}

How to exclude realm native files from library

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)?

Android Studio exclude package from build [duplicate]

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.

Categories

Resources