8

I was in the middle of a project when i decided to upgrade android studio from 3.0.1 to 3.1.2 and ever since i did, i get this error when building my app. I know questions similar to this one has been asked before but the difference is, it doesn't provide the version of the library it has problem with. So it's obviously a different problem. Here is screenshot

Screenshot

app level build.gradle:

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "..."
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 16
        versionName "1.1.1"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        }
    }    

ext {
    lifecycleLibVersion = '1.1.1'
    supportLibVersion = '27.1.1'
    daggerLibVersion = '2.15'
    gmsLibVersion = '11.8.0'
    persistenceLibVersion = '1.0.0'
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "android.arch.lifecycle:extensions:$lifecycleLibVersion"
    implementation "android.arch.persistence.room:runtime:$persistenceLibVersion"
    implementation "com.android.support:appcompat-v7:$supportLibVersion"
    implementation "com.android.support:cardview-v7:$supportLibVersion"
    implementation "com.android.support:design:$supportLibVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibVersion"
    implementation "com.android.support:support-vector-drawable:$supportLibVersion"
    implementation 'com.android.support:multidex:1.0.3'
    implementation "com.google.android.gms:play-services-location:$gmsLibVersion"
    implementation "com.google.android.gms:play-services-maps:$gmsLibVersion"
    implementation "com.google.dagger:dagger-android-support:$daggerLibVersion"
    implementation "com.google.firebase:firebase-core:$gmsLibVersion"
    implementation 'com.github.bumptech.glide:glide:4.3.1'
    implementation 'com.github.lawloretienne:discreteslider:0.0.9'
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'com.journeyapps:zxing-android-embedded:3.5.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    implementation "com.commonsware.cwac:saferoom:0.3.4"

    annotationProcessor "android.arch.persistence.room:compiler:$persistenceLibVersion"
    annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'
    annotationProcessor "com.google.dagger:dagger-compiler:$daggerLibVersion"
    annotationProcessor "com.google.dagger:dagger-android-processor:$daggerLibVersion"
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}

And project level build.gradle:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        maven { url 'https://plugins.gradle.org/m2/' }
    }
dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:3.2.0'
        classpath 'io.fabric.tools:gradle:1.25.1'
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.8.2'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com' }
        maven { url "https://jitpack.io" }
        maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
    }
}
Peyman
  • 941
  • 8
  • 28
  • Does adding: implementation 'com.android.support:support-v4:27.1.1' to the Gradle and resyncing solve the problem? – Elletlar May 05 '18 at 10:53
  • How about `invalidate cache > Restart`? – Paresh P. May 05 '18 at 10:55
  • I tried both (adding support-v4:27.1.1 and invalidate cache), didn't work – Peyman May 05 '18 at 11:00
  • do File/invalidate cache / restart like @Wizard said and/or clean and rebuild your project might solve the problem. I have copied your gradle code into my own project and performed gradle sync with no error. – Fazan Cheng May 05 '18 at 11:01
  • @TRIENTRAN i tried these but nothing happened. I know the gradle code is ok, because it had no issues before upgrade. My guess is android studio is doing something wrong – Peyman May 05 '18 at 11:06
  • i just upgraded android studio to 3.1.2 this afternoon. so there shouldn't be any problem with android studio 3.1.2 i think? – Fazan Cheng May 05 '18 at 11:08
  • u might go to File/Project Structure/ module: app/ tab: dependencies to check if the library Support v4 still not removed yet? – Fazan Cheng May 05 '18 at 11:12
  • @TRIENTRAN I have another machine that runs android studio 3.0.1. App has no issues on that machine! but because it's so weak i can't work on it so i have to figure out a way to make it work here. – Peyman May 05 '18 at 11:13
  • Already checked Project Structure. – Peyman May 05 '18 at 11:16
  • I wonder if downgrading android studio or reinstalling it would help – Peyman May 05 '18 at 11:19
  • Or File->Close project followed by File->Open? I'd be happy to download it and create the project in my 3.1.2 if you want to put it up on github or similar... – Elletlar May 05 '18 at 11:37
  • @Elletlar nope that doesn't work either. sorry i can't do that. it's not an open source project – Peyman May 05 '18 at 11:40

3 Answers3

21

After days of struggling with this problem, I finally found a way. The solution is to delete the caches folder inside ~/.gradle and download dependencies again.

Peyman
  • 941
  • 8
  • 28
  • 1
    Cool :) Odd that 'Invalidate Caches and Restart' does not fix that. Seems like a bug. – Elletlar May 07 '18 at 12:39
  • 4
    Yeah well, Android studio is just full of bugs, I guess this is another one! – Peyman May 07 '18 at 19:34
  • Unfortunately this did not do it for me. Nothing obvious showing up in the build logs either. A difficult bug to figure out :/. – fawaad Oct 31 '18 at 02:32
  • OMG... thanks!!! have been figuring this out for weeks (a couple of minutes a week) then I just asked a coworker to build... but now I can! thanks! thanks and thanksss! – eljamz Feb 07 '19 at 22:59
  • When google removes everything about Java from Android will be Awesome – Everton Santos Sep 03 '19 at 03:11
10
allprojects {
    repositories {    
        mavenLocal()
        google()
        maven {
            url 'https://maven.google.com'
        }
        jcenter()            
    }
}

I finally resolved it by using maven { url 'https://maven.google.com' } above the jcenter().

https://github.com/rebeccahughes/react-native-device-info/issues/414

alphacat2018
  • 198
  • 3
  • 8
  • Placing the google maven url above the jcenter() under the allprojects repositories solved my issue, i've been scratching my head for few days regarding this problem. thanks – 2MuchSmoke Oct 30 '18 at 03:29
1

Gradle build log explained the problem:

> Could not find support-v4.aar (com.android.support:support-v4:26.1.0).
  Searched in the following locations:
      https://jcenter.bintray.com/com/android/support/support-v4/26.1.0/support-v4-26.1.0.aar

Even though I didn't have support-v4 anywhere explicitly, this library implementation 'com.android.support:percent:26.1.0' was the real reason.

Upgrading to compileSdkVersion 27 solved the problem.

soshial
  • 5,906
  • 6
  • 32
  • 40