Android Studio中需从build.gradle移除哪行buildToolsVersion代码?
Hey there! As a fellow Android dev, I’ll walk you through solving this warning and speeding up your Gradle sync—let’s take it step by step since you’re new to the tool.
First, Let’s Understand the Warning
The warning you’re seeing is straightforward:
Warning:The specified Android SDK Build Tools version (25.0.2) is ignored, as it is below the minimum supported version (26.0.2) for Android Gradle Plugin 3.0.1. Android SDK Build Tools 26.0.2 will be used. To suppress this warning, remove "buildToolsVersion '25.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Android Gradle Plugin (AGP) 3.0.1 requires a minimum Build Tools version of 26.0.2, but your project is set to 25.0.2. The system automatically falls back to 26.0.2, but we should fix this properly to avoid confusion.
Step 1: Fix the Build Tools & Compile SDK Version
You have two options here, and the second is more recommended for modern AGP versions:
- Option 1: Keep
buildToolsVersionbut update it to26.0.2 - Option 2: Remove the
buildToolsVersion "25.0.2"line entirely. AGP 3.0+ automatically uses a compatible default Build Tools version, so you don’t need to specify it anymore.
Additionally, since Build Tools 26 pairs with Android SDK 26, you should update your compileSdkVersion to 26 too (this ensures your app targets the latest SDK features and compatibility).
Step 2: Update Dependencies to Match the New SDK Version
Your support libraries, Google Play Services, and Firebase dependencies are all on older versions that don’t match SDK 26. You’ll need to update these to avoid compatibility issues:
- Support libraries (like
appcompat-v7anddesign) should be updated to26.1.0(the latest stable version for SDK 26) - Google Play Services and Firebase dependencies should be updated to
11.8.0(this version is compatible with SDK 26) - OneSignal’s
3.+should work with these updates, but if you run into issues, you can pin it to a specific compatible version like3.10.9
Step 3: Speed Up Gradle Sync
That hour-long sync is way too slow—try these tweaks:
- Enable Offline Mode: Go to
File > Settings > Build, Execution, Deployment > Gradleand check "Offline work". This tells Gradle to use cached dependencies instead of downloading them every time. - Use a Faster Dependency Source: If you’re in a region with slow access to Google’s Maven repo, you can add a domestic mirror repository to your project’s root
build.gradlefile (look for therepositoriesblock and add a mirror URL likemaven { url 'https://maven.aliyun.com/repository/google' }). - Update Gradle: AGP 3.0.1 works best with Gradle 4.1. Android Studio will usually prompt you to update Gradle when you open the project—follow that prompt to get the compatible version.
Modified build.gradle Example
Here’s what your app-level build.gradle should look like after these changes:
apply plugin: 'com.android.application' android { compileSdkVersion 26 // Updated to 26 // Removed buildToolsVersion line (AGP uses default) defaultConfig { applicationId "com.brommko.android.universalwebview" minSdkVersion 15 targetSdkVersion 26 // Updated to match compileSdk versionCode 14 versionName "3.4" manifestPlaceholders = [manifestApplicationId : "${applicationId}", onesignal_app_id : "c0fbadc6-4013-4613-b00b-566eab144d3c", onesignal_google_project_number: "4122760152"] } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:26.1.0' // Updated compile 'com.android.support:design:26.1.0' // Updated compile 'com.onesignal:OneSignal:3.10.9@aar' // Pinned to stable version compile 'com.google.android.gms:play-services-gcm:11.8.0' // Updated compile "com.google.android.gms:play-services-location:11.8.0" // Updated compile 'com.github.quentin7b:android-location-tracker:3.2' compile 'com.google.firebase:firebase-messaging:11.8.0' // Updated compile 'com.google.firebase:firebase-ads:11.8.0' // Updated compile 'com.google.firebase:firebase-crash:11.8.0' // Updated compile 'org.jetbrains:annotations-java5:15.0' compile 'com.github.hotchemi:android-rate:1.0.1' } apply plugin: 'com.google.gms.google-services'
Final Notes
After making these changes, click the "Sync Now" button in Android Studio. It might prompt you to download the SDK 26 components and new dependencies—just follow the prompts to install them. Once that’s done, the warning should disappear, and your sync times should be much faster!
内容的提问来源于stack exchange,提问作者Kardo

