Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: when I replace compile with implementation in gradle(dependency)

I update my Android Studio from 3.0.1 to 3.1.0

But after the update when I build my project it shows 2 warning:

1. Replace compile with implementation (and compile support will be ended at end of 2018)

2. Replace testCompile with testImplementaion (and testCompile support will be ended at end of 2018)

So, finally do these changes but after that, it shows some error:

error

build.gradle(Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "biz.coolpage.aashish.app"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 4
        versionName "1.2.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:design:27.1.0'
    implementation project(':library')
}

build.gradle(Project:Abc)

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

allprojects {
    repositories {
        jcenter()
        google()
        maven {
            url "https://maven.google.com"
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
like image 933
Aashish Avatar asked Mar 27 '18 14:03

Aashish


People also ask

What can I use instead of compile in Gradle?

You should always use implementation rather than compile for dependencies, as compile is now deprecated or removed in the case of Gradle 7+.

How do I resolve Gradle dependencies?

Given a required dependency, with a version, Gradle attempts to resolve the dependency by searching for the module the dependency points at. Each repository is inspected in order. Depending on the type of repository, Gradle looks for metadata files describing the module ( .

What is implementation and compile in Gradle?

implementation. Gradle adds the dependency to the compile classpath and packages the dependency to the build output. However, when your module configures an implementation dependency, it's letting Gradle know that you do not want the module to leak the dependency to other modules at compile time.


1 Answers

Try using api instead of implementation inside your library's gradle. If you have submodules and want to expose the libraries in a transitive manner api should be used. implementation would import the library for the specific project. Also you might have to add

implementation (project(":library")) {
    transitive = true
}

For example in your build.gradle file of your library module use:

api 'com.android.support:appcompat-v7:27.1.0' 

instead of

implementation 'com.android.support:appcompat-v7:27.1.0'

If nothing works you can try to invalidate cache and restart

like image 168
HawkPriest Avatar answered Sep 23 '22 21:09

HawkPriest