6

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
}
Aashish Kumar
  • 2,771
  • 3
  • 28
  • 43

2 Answers2

9

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

HawkPriest
  • 272
  • 2
  • 8
  • I already tried to invalidate the cache and restart but the error still persists. – Aashish Kumar Mar 27 '18 at 15:03
  • did you add `api` instead of `implementation` inside your library's module like `api "com.android.support:appcompat-v7:${supportLibVersion}"` ? – HawkPriest Mar 27 '18 at 15:07
  • Thanks, it works when I replace implementation with api all error vanishes. But I want to known why it suggest to replace with `implementation` instead of `api`. – Aashish Kumar Mar 27 '18 at 15:17
  • 1
    as mentioned in the comment the `implementation` is a final import for project level and you cannot have transitive property for that you need to have `api` check that answer https://stackoverflow.com/questions/44493378/whats-the-difference-between-implementation-and-compile-in-gradle – HawkPriest Mar 27 '18 at 15:26
  • 1
    It is better to put this comment link in your answer as reference. – Aashish Kumar Mar 27 '18 at 15:35
0

Been there; just make sure your gradle plugin is up to date and you didn't add or remove anything to the plugins source code and you're good to go