1

Error in gradle file in android studio.

  apply plugin: 'com.android.application'

apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.mih.demo2"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-core:16.0.4'
    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'
}

Error in implementation 'com.android.support:appcompat-v7:28.0.0'

Guide me to solve this Error In the android studio. I search a lot but cannot find the solution. enter image description here

MIH
  • 125
  • 1
  • 14

1 Answers1

1

Put these flags in your gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

then use SDK version 28 for both compileSdkVersion and targetSdkVersion:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.mih.demo2"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.firebase:firebase-core:17.2.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'
}

It works fine!

majid ghafouri
  • 787
  • 2
  • 7
  • 23
  • You should increase target and compile SDK version to 28. Then add those flags to gradle.properties and then sync your gradle. I test it again and it works for your gradle. If not, put more comments with code please. @MIH – majid ghafouri Sep 22 '19 at 07:09
  • sir, I did it but it shows a message "unable to resolve dependency for ':app@debug/compileClasspath': Cannot resolve external dependency com.android.support:appcompat-v7:28.0.0 because no repositories are defined." – MIH Sep 22 '19 at 07:19
  • 1
    check this, its a sample project with your gradle. it works fine http://s2.picofile.com/file/8373101150/test.rar.html @MIH – majid ghafouri Sep 22 '19 at 08:16
  • from this link it cannot be download will you send me google drive link please Sir – MIH Sep 22 '19 at 09:20
  • 1
    use this link: https://drive.google.com/open?id=1h1mVzjO-xN6X6pgNnw_g9qvfe1B_SpEM @MIH – majid ghafouri Sep 22 '19 at 09:23
  • Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:5:3-19:17 to override. – MIH Sep 22 '19 at 09:40
  • I also add screenshot – MIH Sep 22 '19 at 09:45
  • 1
    Of course when I remove these two lines android.useAndroidX=true android.enableJetifier=true from gradle.properties, I have same error. adding these two lines to gradle.properties file, will solve the problem. check it again please. @MIH – majid ghafouri Sep 22 '19 at 10:13