conflicting dependencies - android studio - java

I am trying to add a dependency giphy4j in my project and this dependency is using junit 4.8.1 but my project is using the latest junit 4.12.
build.gradle(module:app):
androidTestCompile 'junit:junit:4.12'
compile 'at.mukprojects:giphy4j:1.0.1'
This configuration is giving me error on gradle sync.
When I change androidTestCompile to compile and vice versa, It works. I am not getting this point. I dig into dependency stuff compile, apk, TestCompile etc. but couldn't get the proper idea.( As I am a Freshman). And, this conflicting error is also not comprehensible.
point 1: Is compiling the junit(to release with apk) wrong? junit 4.12 is set by default when I create a new project.
point 2: I don't want to configure my third-party-dependency with androidTestCompile becuase It does not show up in release configuration when I run ./gradlew app:androiddependencies.
./gradlew app:androiddependencies output
Error: Error:Conflict with dependency 'junit:junit' in project ':app'. Resolved versions for app (4.8.1) and test app (4.12) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

Exclude junit from library.
compile ("at.mukprojects:giphy4j:1.0.1") {
exclude group: 'junit', module: 'junit'
}

Related

Error: json defines classes that conflict with classes now provided by Android

I got the following error when doing a release build on Android Studio 3
Error:Error: json 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. [DuplicatePlatformClasses]
The following is my dependencies:
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:26.0.1'
compile 'com.android.support:support-v4:26.0.1'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.evernote:android-job:1.2.0'
compile 'com.amitshekhar.android:android-networking:1.0.0'
compile 'com.facebook.stetho:stetho:1.5.0'
compile "me.tatarka.redux:redux-core:0.10"
compile "me.tatarka.redux:redux-android:0.10"
compile "me.tatarka.redux:redux-android-lifecycle:0.10"
compile "me.tatarka.redux:redux-thunk:0.10"
annotationProcessor "org.immutables:value:2.5.5" // <-- for annotation processor
provided "org.immutables:value:2.5.5" // for annotations
provided "org.immutables:builder:2.5.5" // for annotations
compile "me.tatarka.redux:redux-monitor:0.10"
testCompile 'junit:junit:4.12'
}
It's saying json but I can't find which of the the above dependencies is causing the problem.
Here is what I get when I run
gradlew assembleRelease
Task :app:lintVitalRelease
/Users/kruyvanna/Projects/key/HappyKey_Android2/app/build.gradle: Error: json 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. [DuplicatePlatformClasses]
Explanation for issues of type "DuplicatePlatformClasses":
There are a number of libraries that duplicate not just functionality of
the Android platform but using the exact same class names as the ones
provided in Android -- for example the apache http classes. This can lead
to unexpected crashes.
To solve this, you need to either find a newer version of the library which
no longer has this problem, or to repackage the library (and all of its
dependencies) using something like the jarjar tool, or finally, rewriting
the code to use different APIs (for example, for http code, consider using
HttpUrlConnection or a library like okhttp.)
1 errors, 0 warnings
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:lintVitalRelease'.
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Get more help at https://help.gradle.org
I fixed it by adding:
configurations {
all {
exclude group: 'org.json', module: 'json'
}
}
to module gradle file, no removal of dependencies was needed.
Add this in your app/build.gradle
configurations {
all {
exclude module: 'commons-logging'
}
}
Go to the commandline and look at the dependency tree. This will give you a list of everything that your app uses:
./gradlew dependencies
I added dependencies one by one and found this one causing the error
compile "me.tatarka.redux:redux-monitor:0.10"

Gradle compileTestJava fails during gradle clean build

I'm currently having this strange issue with gradle build. Below are the details.
I currently have a java-spring boot based multi module gradle project in the following structure
RootProjectDir
SubProjectA
SubProjectB
SubProjectCommon
The build.gradle file of each one of projects is as below
RootProjectDir build.gradle
dependencies {
compile project(":SubProjectA")
compile project(":SubProjectB")
compile project(":SubProjectCommon")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
SubProjectA build.gradle
dependencies {
compile project(":SubProjectCommon")
}
SubProjectB build.gradle
dependencies {
compile project(":SubProjectCommon")
}
SubProjectCommon build.gradle
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-web')
.....
.....
}
When I execute the
gradle clean build
the build is failing during the compileTestJava phase of SubProjectA. SubProjectA tests have compile time dependency on classes in SubProjectCommon.
If I just execute the following
gradle :subProjectA compileTestJava
the build is successful again.
It is failing with the message that SubProjectCommon classes could not be resolved.
The strange thing is that in the IntelliJ IDEA it doesn't show any compilation issues for the SubProjectA test classes and test executes fine. Also when I just execute the
gradle clean test
everything works fine.
I even tried putting a testCompile dependency on SubProjectCommon in the SubProjectA build.gradle like this
SubProjectA build.gradle
dependencies {
compile project(":SubProjectCommon")
testCompile project(":SubProjectCommon")
}
but still doesn't work
PS:-I currently have written test cases only for SubProjectA classes.
IDEs do not honor module paths very nicely, especially Eclipse, so everything is usually included together, thus you do not get any path problems.
Gradle makes clean distinctions between different projects.
So if your classes were in the test folder, You may need to reference the test sets properly using the below:
testCompile project(":SubProjectCommon").sourceSets.test.output
or
compile project(":SubProjectCommon").sourceSets.test.output
depending on which sourceSet is using classes from the other project.

Gradle DSL method not found: exclude()

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

Cannot find JUnit and Robolectric using Gradle

I'm trying to create a simple unit test project using JUnit and Robolectric. The build.gradle file is attached below.
evaluationDependsOn(':blitzen')
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
def blitzenModule = project(':blitzen')
compile blitzenModule
testCompile blitzenModule.android.applicationVariants.toList().first().javaCompile.classpath
testCompile blitzenModule.android.applicationVariants.toList().first().javaCompile.outputs.files
testCompile files(blitzenModule.plugins.findPlugin("com.android.application").getBootClasspath())
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:2.4'
}
Where "blitzen" is the app this test project is testing. Gradle was able to download junit and robolectric. However, I still got compiler errors on test code which complains about not being able to find various junit and robolectric packages. Do I need to add anything else in the build script so that the junit and robolectric jars can be used correctly?
Thanks.
Turns out I have put the test code inside "src/main/..." instead of "src/test/...". Relocating the test source files resolves the issue.

How to fix "Couldn't load shared library 'libgdx64.so' for target: Linux, 64-bit"

I am trying to use the headless LibGDX for unit testing, but when I run the test I get this error:
Couldn't load shared library 'libgdx64.so' for target: Linux, 64-bit
I read here that I need to add gdx-natives.jar. Is this correct, and where can I find this file?
Also, where in my project should I add the file?
I found the answer on this BitBucket repo. The README gives a nice explanation of how to implement this using Gradle.
Basically, you just add GdxTestRunner.java from that repo, and then add a #RunWith to each of your test files:
#RunWith(GdxTestRunner.class)
public class MyClassTest {
...
}
Then in your root level build.gradle file, add something like this to your core dependencies:
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
testCompile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
testCompile "com.badlogicgames.gdx:gdx-bullet:$gdxVersion"
testCompile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
Obviously the box2d and bullet dependencies are only necessary if you are using those libraries.
On the BitBucket repo README, the example includes both
testCompile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
and
compile "com.badlogicgames.gdx:gdx-backend-headless:$gdxVersion"
I don't think it is necessary to include this for compile, and if I correctly understand how Gradle works, it will actually slow down your build.

Categories