# 本文首发于https://necydcy.me/ ,欢迎关注浏览。
安卓项目导入AS经常出现问题,做一个总结,grable版本尽量不要太低也不要太高
1 项目打开目录下的build.gradle
把其中的
- // Top-level build file where you can add configuration options common to all sub-projects/modules.
-
- buildscript {
-
- repositories {
- google()
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.4.1'
-
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
-
- allprojects {
- repositories {
- google()
- jcenter()
- }
- }
-
- task clean(type: Delete) {
- delete rootProject.buildDir
- }
classpath 'ccom.android.tools.build:gradle:3.4.1'改成自己对应的AS的版本,在自己的其他项目中可以查看。
2 项目打开目录下的local.properties
sdk的路径设置成自己的
3 gradle\wrapper\gradle-wrapper.properties 文件
把这个文件的
- #Sat Jun 15 20:27:12 CST 2019
- distributionBase=GRADLE_USER_HOME
- distributionPath=wrapper/dists
- zipStoreBase=GRADLE_USER_HOME
- zipStorePath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl的gradle的版本设置为AS的内置版本,同样可以在创建过的项目中查找。
4 app\build.gradle 文件
- apply plugin: 'com.android.application'
-
- android {
- compileSdkVersion 29
- buildToolsVersion "29.0.0"
- defaultConfig {
- applicationId "com.example.dell.link_game"
- minSdkVersion 22
- targetSdkVersion 29
- versionCode 1
- versionName "1.0"
- testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
-
- dependencies {
- implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'com.android.support:appcompat-v7:28.0.0'
- implementation 'com.android.support.constraint:constraint-layout:1.1.3'
- implementation "com.android.support:support-v4:28.0.0"
- implementation 'com.android.support:design:28.0.0'
- testImplementation 'junit:junit:4.12'
- androidTestImplementation 'com.android.support.test:runner:1.0.2'
- androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
- }
修改compileSdkVersion 29和 buildToolsVersion "29.0.0",修改为自己对应的版本,分别为sdk版本和buildTools的版本。