Android Studio 3.0.2:compile过时及Build Tools版本过低警告咨询
Hey there, let's work through these two Gradle warnings step by step—they're super common when working with older Android Studio setups, so you're not alone!
compile configuration with implementation Starting with Android Gradle Plugin 3.0.0, the compile keyword was deprecated in favor of implementation (and api for specific use cases). implementation is the recommended choice because it limits dependency visibility to only the module that needs it, which speeds up your build times. Here's how to fix it:
- Open your module-level
build.gradlefile (this is the one inside your app module folder, not the root project's build.gradle) - Scan through the
dependenciesblock and find every line that starts withcompile, like this:compile 'com.android.support:appcompat-v7:26.1.0' - Replace
compilewithimplementationfor most cases:implementation 'com.android.support:appcompat-v7:26.1.0'- Note: If you need a dependency to be accessible to other modules in your project, use
apiinstead ofimplementation(but this is less common for app-level dependencies)
- Note: If you need a dependency to be accessible to other modules in your project, use
- Click the "Sync Now" button in the top-right corner of Android Studio to apply the changes
buildToolsVersion configuration Android Gradle Plugin (AGP) 3.1.0 and above require a minimum Build Tools version of 27.0.3. Since your project was using 26.0.2, AGP automatically falls back to the supported version, hence the warning. The fix is straightforward:
- Open the same module-level
build.gradlefile - Locate the line that says:
buildToolsVersion '26.0.2' - Delete this entire line. Starting with AGP 3.0.0, the plugin automatically selects the compatible Build Tools version for you, so you don't need to specify it manually anymore.
- Sync your Gradle project again, and this warning should disappear entirely
A quick side note: If you ever need to manually specify a Build Tools version later, make sure it's compatible with your AGP version. For example, AGP 3.1.x works with Build Tools 27.0.3+, AGP 3.2.x with 28.0.0+, and so on.
内容的提问来源于stack exchange,提问作者Donald P. Benford

