android gradle resources exclude file not working. e.g.
android {
sourceSets {
androidTest {
resources {
srcDir "../../src/foo/resources"
exclude "../../src/foo/resources/META-INF/foo.xml"
}
}
}
}
The foo.xml is not excluded.
version: com.android.tools.build:gradle:3.4.1
Your tree shows that foo.xml is excluded in androidTest. You might want to change it to the main android node android.
Related
I know there is a few similar questions on SO, but it does not work for me...
I created Android lib, that use ArCore. It was a question on SO how to don't include .so file if I use created ndk lib? There is also one answer that sounds right
https://stackoverflow.com/a/58963852/5709159
But after I putted libarcore.so files under my jniLib
I got such error
More than one file was found with OS independent path 'lib/armeabi-v7a/libarcore_sdk_jni.so'
So, I tried to fix it this ways
https://stackoverflow.com/a/44962630/5709159
sourceSets.main {
jniLibs.srcDir 'src/main/jniLibs'
jni.srcDirs = [] //disable automatic ndk-build call
}
https://stackoverflow.com/a/56453718/5709159
packagingOptions {
pickFirst 'src/main/jniLibs/arm64-v8a/libarcore_sdk_jni.so'
pickFirst 'src/main/jniLibs/armeabi-v7a/libarcore_sdk_jni.so'
pickFirst 'src/main/jniLibs/x86/libarcore_sdk_jni.so'
pickFirst 'src/main/jniLibs/x86_64/libarcore_sdk_jni.so'
}
then this
packagingOptions {
pickFirst 'lib/arm64-v8a/libarcore_sdk_jni.so'
pickFirst 'lib/armeabi-v7a/libarcore_sdk_jni.so'
pickFirst 'lib/x86/libarcore_sdk_jni.so'
pickFirst 'lib/x86_64/libarcore_sdk_jni.so'
}
and also this
packagingOptions {
exclude 'lib/arm64-v8a/libarcore_sdk_jni.so'
exclude 'lib/armeabi-v7a/libarcore_sdk_jni.so'
exclude 'lib/x86/libarcore_sdk_jni.so'
exclude 'lib/x86_64/libarcore_sdk_jni.so'
}
Nothing helped.
As far as I understand issue is - I have one copy of arcore.so files under my jniLibs dir and one copy created after Build here
So, how to fix it?
You've likely added the shared .so files and build from source (or reference them otherwise).
One cannot do both at the same time, so you'd either need to build from source and delete those .so files - or delete the arcore-android-sdk module and keep the .so files. Java dependencies might also pull in native assembly, while that part of the build.gradle is missing (just browse AR core in the "External Libraries" to see what it contains, in case it exists there). Using pre-built libraries generally builds quicker and saves time - which is suggested, unless needing to edit cpp sources.
Usually one can provide the dependencies alike in this build.gradle:
dependencies {
implementation "com.google.ar:core:1.13.0"
natives "com.google.ar:core:1.13.0"
}
// Extracts the shared libraries from aars in the natives configuration.
// This is done so that NDK builds can access these libraries.
task extractNativeLibraries() {
// Always extract, this ensures the native libs are updated if the version changes.
outputs.upToDateWhen { false }
doFirst {
configurations.natives.files.each { f ->
copy {
from zipTree(f)
into arcore_libpath
include "jni/**/*"
}
}
}
}
tasks.whenTaskAdded {
task-> if (task.name.contains("external") && !task.name.contains("Clean")) {
task.dependsOn(extractNativeLibraries)
}
}
Such Gradle task could also be the reason for the duplicates, when it's not configured properly. packagingOptions are in every case the wrong approach, when the linker already doesn't know which one to link.
this solution will work
https://github.com/facebook/react-native/issues/35210#issuecomment-1304536693
adding the below code in android/gradle
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
configurations.all {
resolutionStrategy {
// Remove this override in 0.66, as a proper fix is included in react-native itself.
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
I want to exclude Kotlin files within a folder from the gradle build in Android Studio. This works fine as long as the files are .java files but when converting them to Kotlin, the exclude command ignores the Kotlin files in the folder.
The following is used within my app modules build.gradle file to exclude the folder:
sourceSets {
main {
java {
exclude '**/folderToExclude'
}
}
}
I already checked the following link, but the suggested solution didn't work:
How to exclude kotlin files from compiling with gradle
try below :
exclude '**/*.kt'
It will exclude all file with extention .kt
Try below, it works on my machine.
android {
...
sourceSets {
main {
java {
exclude '**/your_file_1.kt',
'**/your_file_2.kt',
'**/your_file_3.kt',
'**/your_file_4.kt',
'**/your_file_5.kt'
}
}
}
...
}
You can exclude paths matching pattern like:
android {
sourceSets {
main {
java {
exclude '**/TestExcludeClass.java'
}
kotlin {
exclude '**/TestExcludeKotlinClass.kt'
}
}
}
}
I am building a Android library(.AAR) which is consist of multiple packages. Is there any way to exclude some classes from been compiled to the library?
Answer found.
sourceSets {
main {
java {
exclude '**/className.java'
}
}
}
I am a newbie in creating cordova plugin or apps. I have an android native library i.e. an aar file which I need to make a cordova plugin from. I have read many articles about creating such a folder structure as below:
pluginFolder/
build-extras.gradle
plugin.xml
yourDirContainingYourAAR/
src/
android/
yourFile.gradle
myPlugin.java
I followed this answer for folder structure and put all necessary files in respective folders >> Cordova plugin development - adding aar
In the plugin.xml file :
<framework src="src/android/yourFile.gradle" custom="true" type="gradleReference" />
<resource-file src="yourDirContainingYourAAR/mylib.aar" target="libs/mylib.aar" />
In the gradle file yourFile.gradle :
repositories{
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'mylib', ext:'aar')
}
android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
build-extras.gradle :
android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
}
}
I created folder structure for cordova app using cordova CLI tool and opened the app in Android Studio. I tried making the above folder structure for plugin as it is in Android Studio, but the problem is my gradle files are not getting synced because of that I am not able to access APIs of my aar.
I recently added two Android libraries through JitPack and I have the following error:
Duplicate files copied in APK META-INF/library_release.kotlin_module
I've cleared the cached and I've tried excluding the module using
exclude group: 'org.jetbrains'
and
exclude group: 'org.jetbrains.kotlin'
but neither seems to resolve the issue. Is there any way to stop the kotlin stdlib from being added through JitPack? Oddly, other libraries like DbFlow don't have this issue, though I don't see anything special about their setup (other than that it isn't through JitPack)
As suggested in the post Kotlin M13 is out! by jetbrains:
Make sure these .kotlin_module files are not stripped by your packaging process.
So, we can't use exclude option to exclude this resource file from being generated.
As descripted in Kotlin M13 is out!, we should:
in Maven we use groupId and artifactId for module names, but you can say
<configuration>
<moduleName>com.example.mymodule</moduleName>
</configuration>
in Gradle it’s project name + build task name, to customize:
compileKotlin {
kotlinOptions.moduleName = "com.example.mymodule"
}
This is my configuration for Android library project:
ext {
GROUP_ID = 'custom.group.id'
ARTIFACT_ID = 'artifactid'
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
compileOptions {
kotlinOptions.freeCompilerArgs += ['-module-name', "$GROUP_ID.$ARTIFACT_ID"]
}
defaultConfig {
...
}
buildTypes {
...
}
}
Resource file named META-INF/custom.group.id.artifactId.kotlin_module will be generated instead of META-INF/library_release.kotlin_module.No more duplicate files will be found.
You can read this post and this post for more information.
You should add this to the build.gradle file of your app inside the android tag
packagingOptions {
exclude 'META-INF/library_release.kotlin_module'
}
After looking at other conflicts, it seems like the resolution is
packagingOptions {
pickFirst 'META-INF/library_release.kotlin_module'
}
under android in the app gradle.
This allows the apk to build