I need to exclude a class which is present in a third party library jar file. i don't know the exact syntax format to exclude a group. i tried the following syntax for excluding a class named XMLConstants.class inside the library "javax.xml.stream.jar".
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/xsdlib-1.5.jar')
compile files('libs/relaxngDatatype-2.2.jar')
compile files('libs/javax.xml.stream.jar'){
exclude module: 'javax-xml-stream'
}
compile files('libs/pull-parser-2.jar')
compile files('libs/javax.xml.bind.jar')
compile files('libs/java-rt-jar-stubs-1.5.0.jar')
compile files('libs/jaxen-core.jar')
compile files('libs/jaxen-dom4j.jar')
compile files('libs/jaxen-1.1-beta-2.jar')
}
If i use this syntax i am getting the following error.
Error:(52, 0) Could not find method exclude() for arguments [{module=javax-
xml-stream-XMLConstants}]
I am new to android so i need to know how to write a syntax to exclude a particular class in a third party library jar file. If there is any other method to do this please suggest. Thanks in advance.
Check this post and also this. Both says that you need to add the excluding class name inside sourceSets.
EDIT : Try it like this. I didn't got any error while compiling.
sourceSets {
main {
java {
srcDir 'libs'
exclude 'org.apache.http.protocol.RequestDate.class'
}
}
}
Related
I got the assignment to continue the Android Studio project, but when I will Release the APK there is an error like this.
../../build.gradle: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar.
../../build.gradle: httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jar.
This in my dependencies at build.gradle
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.code.gson:gson:2.4'
compile 'org.apache.httpcomponents:httpcore:4.2.4'
compile 'org.apache.httpcomponents:httpmime:4.3'
compile 'com.android.support:appcompat-v7:28.0.0'
compile 'com.android.support:support-compat:28.0.0'
compile 'com.android.support:design:28.0.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.+'
compile 'com.android.support:support-v4:28.0.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.zxing:core:3.2.1'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:cardview-v7:28.0.0'
compile 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
compile 'me.dm7.barcodescanner:zxing:1.9'
compile 'com.google.firebase:firebase-messaging:11.0.4'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
but i don't know where the problem..
Add this in build.gradle locate in app module
configurations {
all {
exclude module: 'httpclient'
}
}
Hope it will work
Thankew! Happy coding!
i am using a lot of library in my project. And some libraries using same jar file therefore i writed this on build.gradle :
dependencies {
compile fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.twotoasters.jazzylistview:library:1.2.1'
compile 'com.google.firebase:firebase-core:10.2.4'
compile 'com.google.firebase:firebase-database:10.2.4'
compile 'com.orhanobut:dialogplus:1.11#aar'
compile 'com.github.recruit-lifestyle:FloatingView:2.2'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.nineoldandroids:library:2.4.0'
compile ('com.specyci:residemenu:1.6+'){
exclude group: 'com.nineoldandroids', module: 'library' }
compile files('libs/poppyview.jar'){
exclude group: 'com.nineoldandroids', module: 'library' }
}
And i am getting error :
Error:(54, 0) Gradle DSL method not found: 'exclude()'
Possible causes:The project 'DopingEng' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 2.3.1 and sync projectThe project 'DopingEng' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
Gradle already update , how can i solve this problem ?
Here's the problem
compile files('libs/poppyview.jar'){
exclude ...
}
A file based dependency does not work in the same way as a dependency coming from a repository. There is no meta data associated with it (eg no dependency information) so there's also nothing to exclude (since there's no transitive dependencies).
Do you have the pom/ivy meta-data for libs/poppyview.jar? If so then you shouldn't declare it like this (I suggest a local maven repository folder). If you don't then there's nothing to exclude
I'm trying to exclude a class from jar, but it doesn't work.
Let me know hot to do it.
This is my code:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile ('com.google.android.gms:play-services-gcm:8.3.0') {
exclude module: 'com.google.android.gms.iid/zzb'
}
compile 'org.xwalk:xwalk_core_library:14.43.343.17'
compile 'com.google.code.gson:gson:2.4'
compile 'commons-io:commons-io:2.4'
compile 'com.google.android.gms:play-services-analytics:10.2.1'
compile project(":adjust")
}
This is the error message:
Error:Execution failed for task ':app:packageAllReleaseClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/android/gms/iid/zzb$zza$zza.class
In plain Gradle, what you are looking for can be achieved as:
dependencies {
compile('com.example.m:m:1.0') {
exclude group: 'org.unwanted', module: 'x
}
compile 'com.example.l:1.0'
}
This would exclude the module X from the dependencies of M, but will still bring it if you depend on L.
I am trying to use OpenCSV library in my project and it is throwing up this error- I have already tried to delete the library and reinstall it and the error persists.
This is from the build.gradle
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
compile files('libs/opencsv.jar')}
I am curious as to why you have your own opencsv.jar? Is it because you did customizations or do you have firewall issues where you are only allowed to go to an internal maven repository during compilation?
If so Prathmesh hit the nail on the head in that you will have to bring in all the transitive dependencies yourself. The dependencies of the latest version can be found at the opencsv sourceforge page. Currently opencsv is dependent on commons-lang3 and commons-beanutils.
Otherwise just change your "compile files" line to compile 'com.opencsv:opencsv:3.9' and let gradle get all your transitive dependencies for you.
Add the dependency for org.apache.commons.lang3.StringUtils in build.gradle.
I am using 2 libraries in my application,which are having some common jar files.
So when i am trying to compile my application i am getting duplicate entry exception.I tried to exclude those jars in build.gradle for that perticular library project .
The code i wrote is
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:multidex:1.0.1'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
compile(project(':JIRAConnect')) {
exclude module: 'org.apache.httpcomponents:httpcore'
exclude module: 'org.apache.httpcomponents:httpclient'
exclude group: 'com.nostra13', module: 'universalimageloader'
}
compile (project(':..:GlobalLib:MyGlobalLib')){
exclude module: 'org.apache.httpcomponents:httpcore'
exclude module: 'org.apache.httpcomponents:httpclient'}
Can anyone give me the solution? Thanks in advance
In the 'open Module Settings' option and then click on the item MODULES, click the Dependencies tab.
Excluding the two jar files that you added.
(Not to be removed from the project. Merely to exclude. May include back at any time if necessary.)