Kotlin the compiler warning and application cannot be executed - android

I have a project using androidx and kotlin, I get an error message when running the application as follows:
w: JAR runtime files in the classpath should have the same version. These files were found in the classpath:
w: /Users/arjava/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre7/1.2.31/98678431965f7487d6dc9b399e59b6c4b3921073/kotlin-stdlib-jre7-1.2.31.jar: kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead
and one more message directed me to the directory :
.gradle / caches / modules-2 / files-2.1 / org directory. Jetbrains.kotlin / kotlin-stdlib-jre7 / and xxxxxxx
I'm really confused about this problem, even though I don't apply jre in my app.gradle, I try to delete the files and then there will be more and more.
this is my app.gradle file :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.mhdfdl41.android.gotoclinic"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
androidTestImplementation "android.arch.core:core-testing:1.1.1"
implementation 'com.google.android.material:material:1.1.0-alpha03'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.github.smarteist:autoimageslider:1.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.github.smarteist:autoimageslider:1.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.github.humazed:RoomAsset:1.0.3'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.basgeekball:awesome-validation:1.3'
// AAC (Room, Live Data, View Model)
implementation "android.arch.persistence.room:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
// ViewModel and LiveData
androidTestImplementation "android.arch.persistence.room:testing:1.1.1"
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
//room asset access databases
implementation 'com.github.humazed:RoomAsset:1.0.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation "androidx.test.ext:junit:1.1.0"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
//anko
implementation "org.jetbrains.anko:anko:$anko_version"
}
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
}
repositories{
mavenCentral()
}
what made this happen?

This is how the root project's build.gradle should look alike. when I add kotlin-stdlib-jdk7, it still complains about a version mismatch; only kotlin-stdlib (without the postfix) works for me.
buildscript {
ext.kotlinVersion = "1.3.30"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.4.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
}
}
plugins {
id "org.jetbrains.kotlin.jvm" version "1.3.30"
}
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}"
}
...

Related

Android studio could not resolve retrofit2 converter scalars 2.5.0

Android studio displays this strange error whenever I add some dependency to the grade file. It was working perfectly earlier. Further it displays no cached version of retrofit2 scalars available for offline mode.
Currently I tried almost all options from uninstalling and reinstalling android studio but no luck. I am running out of time so please help me resolve this.
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.protabler"
minSdkVersion 23
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.preference:preference:1.1.0-alpha05'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation "androidx.cardview:cardview:1.0.0"
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'de.hdodenhof:circleimageview:3.0.1'
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

dependencies gradle android studio

good evening, i am starting in android but the projects that I have downloaded to base myself on most of them throw me errors in the grandle does anyone know why I get error in almost all dependencies? already try to "update" them to their latest version in the gradle file, the project download it from git hub.
build. gradle (Proyect)
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.google.gms:google-services:4.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.bigohealth"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.5'
implementation 'com.google.firebase:firebase-firestore:17.1.2'
//implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
//androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
def lifecycle_version = "2.0.0"
def room_version = "2.2.0-alpha02"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.github.christophesmfvvFet:android_maskable_layout:v1.3.1'
implementation 'com trrf r.squareup.retrofit2:adapter-rxjava2:2.6.0'
implementation 'de. , tk./;cx v/8.c8x8hdodenhof:circleimageview:3.1.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
implementation 'com.squareup.retrofit2:converter-scalars:2.6.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.android.gms:play-services-gcm:17.0.0'
implementation 'com.google.firebase:firebase-messaging:20.3.0'
implementation 'com.android.volley:volley:1.1.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation platform('com.google.firebase:firebase-bom:25.12.0')
implementation 'com.google.firebase:firebase-analytics'
}
apply plugin: 'com.google.gms.google-services'
Can you check, if you are under proxy and your android studio is able to connect to internet? Go to file>settings>type 'proxy' > in proxy settings there is a check connection button which will test if android studio is able to connect.
if there is a proxy, then provide the details and check again.
also make sure you do not have offline mode in your gradle settings turned on. Refer following screenshot:
Also your build tools are 4.0.1. Hope you should have the latest android studio too..

Android Studio Kotlin Complier Error node.sym must not be null

Suddenly my android studio gradle build fails with unknown error:
java.lang.IllegalStateException: failed to analyze: com.sun.tools.javac.util.ClientCodeException: java.lang.IllegalStateException: node.sym must not be null
I tried everything like reverting my project back to previous version and invaliding cache and restart but still the error persists i don't really know what is happening:
Here is my gradle:
ext {
configuration = [
compileVersion: 27,
minSdk : 14,
targetSdk : 25,
version_code : 5,
version_name : "1.0.0"
]
libraries = [
supportVersion: '1.0.0-beta01'
]
}
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
classpath "io.realm:realm-gradle-plugin:6.0.1"
classpath 'io.fabric.tools:gradle:1.27.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// classpath "com.android.tools.build:gradle:${buildConfig.gradlePlugin}"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://jitpack.io"
}
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Build gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.social.media.post.graphics.template.card.maker"
minSdkVersion 21
targetSdkVersion 29
versionCode 6
versionName "1.5"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
jumboMode true
javaMaxHeapSize "4g"
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.github.smarteist:autoimageslider:1.3.2'
implementation 'me.grantland:autofittextview:0.2.1'
//noinspection GradleCompatible
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha10'
implementation 'com.github.QuadFlask:colorpicker:0.0.13'
implementation 'com.github.kaushikthedeveloper:squarelayout:0.0.3'
implementation project(':imagelibrary')
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.github.bumptech.glide:glide:4.10.0'
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
implementation 'com.intuit.sdp:sdp-android:1.0.5'
implementation 'com.intuit.ssp:ssp-android:1.0.5'
implementation 'androidx.percentlayout:percentlayout:1.0.0'
implementation 'com.github.MasayukiSuda:BubbleLayout:v1.2.1'
//Fuel
implementation 'com.github.kittinunf.fuel:fuel:2.2.1'
implementation 'com.github.kittinunf.fuel:fuel-android:2.2.1'
implementation 'com.github.kittinunf.fuel:fuel-gson:2.2.1'
implementation 'com.google.android.material:material:1.0.0'
//Gson
implementation 'com.google.code.gson:gson:2.7'
implementation 'com.github.fondesa:kpermissions:2.0.2'
//Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.30.1-eap13'
implementation 'com.isseiaoki:simplecropview:1.1.4'
implementation 'com.github.hotchemi:permissionsdispatcher:2.3.1'
annotationProcessor 'com.github.hotchemi:permissionsdispatcher-processor:2.3.1'
// all common code dependencies
implementation 'com.eyalbira.loadingdots:loading-dots:1.0.2'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.github.sujithkanna:smileyrating:1.6.8'
implementation 'com.daimajia.slider:library:1.1.5#aar'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.github.warkiz.widget:indicatorseekbar:2.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'
implementation 'com.github.Theophrast:SquareImageView:1.0.1'
//For Firebase
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
//For Google Mediation
implementation 'com.google.android.gms:play-services-ads:18.2.0'
// For Fb Mediation and FB ads
implementation 'com.facebook.android:audience-network-sdk:5.6.0'
implementation 'com.google.ads.mediation:facebook:5.6.0.0'
implementation 'com.makeramen:roundedimageview:2.3.0'
//for unzip .zip file
implementation 'com.github.ghost1372:Mzip-Android:0.4.0'
//lottie animation
implementation 'com.airbnb.android:lottie:3.0.7'
// for equal spacing around recycler view
/* implementation('com.github.thekhaeng:recycler-margin:1.2.1') {
exclude group: 'com.android.support', module: 'recyclerview-v7'
}*/
// subscribe and in - app
implementation 'com.anjlab.android.iab.v3:library:1.0.44'
implementation 'androidx.core:core-ktx:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//Sectioned Recyclerview
implementation 'com.github.IntruderShanky:Sectioned-RecyclerView:2.1.1'
//Ripple Effect
implementation 'com.github.traex.rippleeffect:library:1.3'
//Tagview
compile 'com.veinhorn.tagview:library:1.0.4'
}
apply plugin: 'com.google.gms.google-services'
repositories {
mavenCentral()
}
I had the same error, and it was related to kotlin and java files with the same name.
The issue appeared after I converted a java file to kotlin in one branch, and then merged my branches, but both files remained in the project.
The error didn't show the duplicated file name, but after adding
kapt.incremental.apt=false
to "gradle.properties" as suggested by this article:
https://medium.com/#tashpemhiwa/after-a-rather-long-hiatus-without-writing-an-article-i-have-had-recent-new-inspiration-to-start-7f1f5187ba53
after disabling incremental build, the duplicate file error appeared in my build results and I knew the duplicated file name, so I removed the java file.
I enabled incremental kapt afterwards, because incremental build is faster.
It also happened when source is set like:
sourceSets {
main {
java.srcDirs += 'build/generated/data_binding_base_class_source_out/'
}
}
And there are multiple build types. Folders in data_binding_base_class_source_out intercepts and it causes the problem.
Fix:
sourceSets {
debug {
java.srcDirs += 'build/generated/data_binding_base_class_source_out/debug/'
}
release {
java.srcDirs += 'build/generated/data_binding_base_class_source_out/release/'
}
}
I've had this issue a few times.
The only thing that has worked for me is upgrading/downgrading Android Gradle Plugin. Try using 3.5.3.
In my case, I was using 3.6.0-rc02. After downgrading to 3.5.3, the issue went away.

add kapt androidx room in gradle makes data binding error

After I add kapt "androidx.room:room-compiler:2.1.0-alpha05"
I get error when doing data binding. Here is my app gradle :
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "insure.onoff"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// Gradle automatically adds 'android.test.runner' as a dependency.
useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'
applicationVariants.all {
variant ->
variant.outputs.all {
outputFileName = "./" + outputFileName
}
}
}
dependencies {
kapt "androidx.room:room-compiler:2.1.0-alpha05"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0'
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.room:room-runtime:2.1.0-alpha05'
implementation 'android.arch.work:work-runtime-ktx:1.0.1-rc01'
implementation 'android.arch.navigation:navigation-fragment:1.0.0'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.1'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
implementation 'androidx.viewpager:viewpager:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
// AWS Dependencies
implementation "com.amazonaws:aws-android-sdk-core:2.11.1"
implementation "com.amazonaws:aws-android-sdk-auth-core:2.11.1"
implementation("com.amazonaws:aws-android-sdk-auth-userpools:2.11.1") { transitive = true }
implementation("com.amazonaws:aws-android-sdk-auth-ui:2.11.1") { transitive = true }
implementation 'com.facebook.android:facebook-login:4.36.0'
implementation "com.google.android.gms:play-services-auth:16.0.1"
// Testing dependencies
androidTestImplementation "androidx.arch.core:core-testing:2.0.0"
androidTestImplementation "androidx.test.espresso:espresso-contrib:3.1.1"
androidTestImplementation "androidx.test.espresso:espresso-core:3.1.1"
androidTestImplementation "androidx.test.espresso:espresso-intents:3.1.1"
androidTestImplementation "androidx.test.uiautomator:uiautomator:2.2.0"
testImplementation "junit:junit:4.12"
}
project gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.20'
repositories {
google()
jcenter()
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Error :
My Android Studio version :
Android Studio 3.3
Build #AI-182.5107.16.33.5199772, built on December 25, 2018
JRE: 1.8.0_152-release-1248-b01 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.12.5
When you get databinding errors, they are usually the result of a compilation error within the code.
Using the picture you have posted as reference, there are 4 Icons on the vertical toolbar on the left side of the screen. The top icon is the green hammer. Click the icon just below that (the 2nd one, it looks like two screens layered on top of each other). Clicking this icon opens up a different view that describes in detail what the compiler did not like - you generally will find what is causing the problems.
You can also run "gradle build -debug" or some other debug tracing cmd for gradle that will print in detail what the errors are.
Double check kotlin is compiling to your target jvm version 1.8
If all else fails, try clean/build + invalidate/cache + restart. Hope this helps.

Dependency conflict when adding mockwebserver to android project

I have two separate android projects where I'm implementing integration tests. I finished adding the integration tests to the first one, and I'm moving to my second project, but I encountered a problem while doing the setup and adding the mockwebserver dependency.
Top level gradle file (same for both apps)
buildscript {
ext.kotlin_version = '1.3.21'
repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'io.fabric.tools:gradle:1.+'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "http://tokbox.bintray.com/maven" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App gradle file for app 1 (working)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-kapt"
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://jitpack.io' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
mavenCentral()
jcenter()
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myApps.appone"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "0.9"
testInstrumentationRunner "com.myApps.CustomTestRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".dev"
versionNameSuffix '-DEBUG'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == "com.android.support") {
if (!requested.name.startsWith("multidex")) {
details.useVersion "26.+"
}
}
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":domain")
implementation project(":data")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.11.0")
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-intents:3.0.2'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'org.mockito:mockito-core:2.5.0'
androidTestImplementation('com.android.support.test.espresso:espresso-contrib:2.0') {
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
kaptAndroidTest 'com.google.dagger:dagger-compiler:2.16'
kapt 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
implementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.makeramen:roundedimageview:2.2.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.maps.android:android-maps-utils:0.5+'
implementation 'com.google.maps:google-maps-services:0.1.20'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation "io.reactivex.rxjava2:rxandroid:2.1.0"
implementation 'com.android.support:multidex:1.0.3'
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
kapt 'com.google.dagger:dagger-compiler:2.16'
kapt "com.google.dagger:dagger-android-processor:2.16"
//testImplementation
testImplementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.11'
testImplementation 'org.jetbrains.kotlin:kotlin-test-junit:1.0.6'
testImplementation "com.nhaarman:mockito-kotlin:1.5.0"
testImplementation 'android.arch.core:core-testing:1.1.1'
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-invites:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
}
apply plugin: 'com.google.gms.google-services'
App gradle file for app 2 (Error)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: "kotlin-kapt"
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://jitpack.io' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
mavenCentral()
jcenter()
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myApps.apptwo"
minSdkVersion 17
targetSdkVersion 28
versionCode 22
versionName "2.0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
versionNameSuffix '-DEBUG'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
kapt {
generateStubs = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":domain")
implementation project(":data")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.11.0")
kaptAndroidTest 'com.google.dagger:dagger-compiler:2.16'
implementation 'com.android.support:cardview-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
kapt 'com.jakewharton:butterknife-compiler:8.8.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation "io.reactivex.rxjava2:rxandroid:2.1.0"
implementation 'com.jakewharton:kotterknife:0.1.0-SNAPSHOT'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-places:16.0.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.maps.android:android-maps-utils:0.5+'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:multidex:1.0.3'
def nav_version = "1.0.0-alpha06"
implementation 'com.android.support:design:28.0.0'
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
// use -ktx for Kotlin
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version" // use -ktx for Kotlin
implementation "android.arch.lifecycle:extensions:1.1.1"
implementation "android.arch.lifecycle:viewmodel:1.1.1"
kapt "android.arch.lifecycle:compiler:1.1.1"
kapt 'com.google.dagger:dagger-compiler:2.16'
kapt "com.google.dagger:dagger-android-processor:2.16"
//Firebase
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.7#aar') {
transitive = true
}
}
apply plugin: 'com.google.gms.google-services'
The error that is thrown is this :
Cannot find a version of 'com.squareup.okhttp3:okhttp' that satisfies the version constraints:
Dependency path 'apptwo:app:unspecified' --> 'com.squareup.okhttp3:mockwebserver:3.11.0' --> 'com.squareup.okhttp3:okhttp:3.11.0'
Dependency path 'apptwo:app:unspecified' --> 'com.squareup.picasso:picasso:2.71828' --> 'com.squareup.okhttp3:okhttp:3.10.0'
Dependency path 'apptwo:app:unspecified' --> 'com.squareup.retrofit2:retrofit:2.4.0' --> 'com.squareup.okhttp3:okhttp:3.10.0'
Dependency path 'apptwo:app:unspecified' --> 'apptwo:data:unspecified' --> 'com.squareup.okhttp3:logging-interceptor:3.8.1' --> 'com.squareup.okhttp3:okhttp:3.8.1'
Dependency path 'apptwo:app:unspecified' --> 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' --> 'com.squareup.retrofit2:retrofit:2.4.0' --> 'com.squareup.okhttp3:okhttp:3.10.0'
Constraint path 'apptwo:app:unspecified' --> 'com.squareup.okhttp3:okhttp' strictly '3.10.0' because of the following reason: apptwoDevelopmentDebugRuntimeClasspath uses version 3.10.0
Constraint path 'apptwo:app:unspecified' --> 'com.squareup.okhttp3:okhttp' strictly '3.10.0' because of the following reason: apptwoDevelopmentDebugRuntimeClasspath uses version 3.10.0
Constraint path 'apptwo:app:unspecified' --> 'com.squareup.okhttp3:okhttp' strictly '3.10.0' because of the following reason: apptwoDevelopmentDebugRuntimeClasspath uses version 3.10.0
I ran ./gradlew dependencies, and what I saw was that in app 1, the one that is working, gradle solves the conflict and uses okhttp:3.11.0 for all the child dependencies, while in app 2 gradle is unable to solve the conflict.
The only way that I managed to solve this conflict is to downgrade the dependency declaration of mockwebserver, changing
androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.11.0")
to
androidTestImplementation("com.squareup.okhttp3:mockwebserver:3.10.0")
What is the problem here? Why does it work in one app and not on the other?
The gradle version of MockWebServer and Retrofit both utilize okhhtp. You need to match compatible versions.
The reason why it most likely works in one app but not the other is probably that a valid version is either cached or is required for a different package eg okio.
You will need to either downgrade mockwebserver or update retrofit

Categories

Resources