Background info:
My IDE
Android Studio 3.1.3
Build #AI-173.4819257, built on June 4, 2018
JRE: 1.8.0_152-release-1024-b02 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 7 6.1
First solution: Import the project again and don't agree to upgrade the android gradle plug-in.
Second solution: Your files should contain these fragments.
build.gradle:
buildscript {
repositories {
jcenter()
google()//this is important for gradle 4.1 and above
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3' //this android plugin for gradle requires gradle version 4.4 and above
}
}
allprojects {
//...
repositories {
jcenter()
google()//This was not added by update IDE-wizard-button.
//I need this when using the latest com.android.support:appcompat-v7:25.4.0 in app/build.gradle
}
}
Either follow the recommendation of your IDE to upgrade your gradle version to 4.4 or consider to have this in gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Optional change buildToolsVersion in app/build.gradle:
android {
compileSdkVersion 25
buildToolsVersion '27.0.3'
app/build.gradle: comment out the dependencies and let the build fail (automatically or trigger it)
dependencies {
//compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.android.support:appcompat-v7:25.1.0'
}
app/build.gradle: comment in the dependencies again. It's been advised to change them from compile to implementation, but for now it's just a warning issue.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
}
After project rebuilding, the import statement shouldn't be greyed-out anymore; try to invoke Ctrl+h on the class. But for some reason, the error markers on those class-referencing-statements are still present. To get rid of them, we need to hide and restore the project tree view or alternatively close and reopen the project.
Finally that's it.
Further Readings:
Use the new dependency configurations
If you prefer a picture trail for my solution, you can visit my blog