5

There are many different questions about this, but the problems there are about using v7.28.0, v7.28.+, v7.28.0.0-rc02 But when I sync my project I get this error:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:28.0.0.

I've checked Support library setup and followed it's instructions but it didn't help.

This is my module app

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.mobaleghan.nasimnoor"
        manifestPlaceholders = [
                onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: 'REMOTE'
        ]
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 8
        versionName "1.6.3"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation "com.android.support:support-core-utils:28.0.0"
    implementation 'com.onesignal:OneSignal:3.10.3'
}

and project gradle:

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

The android studio internet connection is fine as I've tested in settings and I don't know where else to look.

I even created a new project in AS 3.2.1 But I get same error. I don't know why this happens every time I update AS!

Ghasem
  • 14,455
  • 21
  • 138
  • 171

5 Answers5

10

I'm sure other answers are good and working. but mine got solved by set proxy to Freedom of Developers.

enter image description here

This solution is for Persians like me who suffer from strict limitations for Iranians by google.

Now my app gradle look like this:

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.mobaleghan.nasimnoor"
        manifestPlaceholders = [
                onesignal_app_id: 'b1ced87b-48d1-4857-a68b-9c287aa4003f',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: 'REMOTE'
        ]
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 9
        versionName "1.6.4"
        vectorDrawables.useSupportLibrary = true
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                    'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation "com.android.support:support-core-utils:28.0.0"
    implementation 'com.onesignal:OneSignal:3.10.3'
}

Those repositories are there based on OneSignal documentations.

And top level build:

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

And everything is working fine.

Ghasem
  • 14,455
  • 21
  • 138
  • 171
3

Android project has 2 gradle files: one stored in project scope and one stored in application scope. (noted that one project can have many applications inside, but you usually have one). So you only need to swap defined repository url in those 2 gradle files.

Step 1: Remove these lines of code in your build.gradle (app)

repositories {
    maven { url 'https://maven.google.com' }
}

Step 2: Add this to your build.gradle (project)

    allprojects {
        repositories {
            google()
            jcenter()
            maven { url 'https://maven.google.com' }
            maven { url 'https://jitpack.io' }
            mavenCentral()
        }
    }

One thing you have to aware that 28.0.0 is the last stable version of android.support. So you might want to downgrade version or migrate everything to androidX.

The stable release of 28.0.0 will be the final feature release packaged as android.support. All subsequent feature releases will only be made available as androidx-packaged artifacts.

Check out this link and welcome to the new era of androidX.

hqt
  • 29,632
  • 51
  • 171
  • 250
phatnhse
  • 3,870
  • 2
  • 20
  • 29
0

Try the following:

1) Uncheck offline work from build tools: File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> Build Tools->Gradle->Uncheck Offline work option.

2) If above doesn't work then go to your project's build gradle and add the following under repositories:

allprojects {
     repositories {
         jcenter()
         maven {
             url "https://maven.google.com"
         }
     }
}
HaroldSer
  • 2,025
  • 2
  • 12
  • 23
  • Offile work is already unchecked and the second way doesn't help. As I said I've checked all solutions in other questions and the documents I've linked says it's for older gradle versions – Ghasem Dec 20 '18 at 08:23
0

merge this part from the module's build.gradle into the root project's build.gradle:

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
    }
}

repositories {
    maven { url 'https://maven.google.com' }
}

only keep these lines in the module's build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

android {
   ...
}

the root project's build.gradle should look about like this then:

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:0.12.1'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
0

You can still use version 28.0.0 but it seems its time to migrate to Android X!

According to Support Library Documentation:

Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components.

You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library.

We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well.

VSB
  • 9,825
  • 16
  • 72
  • 145