2022最新Android项目导入过程(以Android studio2021.2.1为例)

当我们访问别人项目的时候,可能由于别人项目版本太老,总是导入不了。常常报出如下错误。
在这里插入图片描述
也就是Android Studio版本不支持。我们通常需要修改一些配置信息才能正确导入。
常见的Android项目结构如图。
在这里插入图片描述
【注释】打开类型如图
在这里插入图片描述

1.查看自己的Android studio支持的版本号

打开Android studio,新建安卓项目。待自动导入完成后关闭此项目窗口或再打开一个新的窗口开始导入项目。

2.修改项目根目录下面的build.gradle文件

修改classpath对应的gradle版本号,最新版需要在repositories里面添加google()。

// 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:4.0.0'
        // 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
}

3.检查local.properties的Android sdk位置是否正确

sdk.dir=D\:\\TOOLS\\Android\\Sdk

4.修改app目录下面的build.gradle文件。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.wm.remusic"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.01"
        //start
        renderscriptTargetApi 17
        renderscriptSupportModeEnabled true
        //end
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile 'com.facebook.fresco:fresco:0.9.0'
    compile 'com.squareup.okhttp:okhttp:2.7.2'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.2'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    //    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
    compile 'com.github.ksoichiro:android-observablescrollview:1.6.0'
    compile 'com.github.promeg:tinypinyin:1.0.0'
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/mail.jar')
}

5.修改gradle文件夹下面的gradle-wrapper.properties文件。

我们只需要修改distributionUrl即可。

#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

重要提示:修改时只需要修改版本号,不建议删除文件里面的信息。如果有报错再修改。一般情况下只需要修改版本信息就能直接导入项目了。

修改打开类型为Android以方便编码。
在这里插入图片描述

  • 3
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

量子代码时空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值