如何修改Android Studio新项目默认SDK及BuildTools版本至27?
Hey there! Let me break down two solutions for you—one that modifies the template path you found, and a far better, sustainable global setting that avoids having to tweak templates every time Studio updates.
Since you already located the template folder at C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle-projects\NewAndroidModule\root, here's exactly what to edit:
- Look for the file named
build.gradle.ftl(it’s a FreeMarker template that generates your project’s build.gradle file) - Open it with a text editor (you’ll likely need admin permissions to save changes—copy the file to your desktop first, edit, then replace it back if you hit permission roadblocks)
- Find the lines defining
compileSdkVersionandtargetSdkVersion—change their values from26to27 - If
buildToolsVersionisn’t already present, add it under the compileSdk line like this:buildToolsVersion "27.0.3" - Save the file, and next time you create a project, it’ll use your desired versions automatically.
Heads up: This change will get overwritten if you update Android Studio, so it’s a temporary fix at best.
This method sets default values for all new projects, and won’t be wiped by Studio updates. Here’s how to do it:
- Open Android Studio, go to
File > New Projects Setup > Structure for New Projects(this menu is dedicated to configuring defaults for every new project you create) - In the left sidebar, select
Project:- Set
Project SDKto Android 27 (make sure you’ve already downloaded this SDK via the SDK Manager first)
- Set
- Next, go to
Modules > Default Configin the left sidebar:- Set
Compile Sdk Versionto27 - Set
Target Sdk Versionto27
- Set
- To lock in the
buildToolsVersionglobally, open your user-level gradle.properties file atC:\Users\[Your Username]\.gradle\gradle.propertiesand add this line:android.buildToolsVersion=27.0.3 - Save all settings, and from now on every new project will automatically use SDK 27 and buildTools 27.0.3 without any manual edits.
Pro tip: Before setting this up, double-check that you’ve installed Android 27 SDK Platform and Build Tools 27.0.3 via File > Settings > Appearance & Behavior > System Settings > Android SDK.
内容的提问来源于stack exchange,提问作者Damn Vegetables

