拿到一个别人的Android项目,经常无法直接很顺利的在自己的Android Studio中运行,如果不想重新下载一堆额外的插件,只需要修改三个文件的内容即可。
我们假设项目名称叫master,需要修改的文件如下:
masteruild.gradle
masterappuild.gradle
mastergradlewrappergradle-wrapper.properties
masteruild.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
classpath "com.android.tools.build:gradle:4.2.0"
只需要把这句换成自己本机的Android Studio版本即可
kotlin同理,改成自己编译器的版本,如:ext.kotlin_version = '1.3.71'
masterappuild.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.xinghe.course.mydata"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
对于这个文件,我们应该关注的是:
compileSdkVersion 30
minSdkVersion 16
targetSdkVersion 30
统统改成本机Android Studio预设的值
mastergradlewrappergradle-wrapper.properties
#Tue May 05 20:26:29 CST 2020
distributionBase=GRADLE_USER_HOME
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
这里要修改的是gradle的版本,一般直接将自己本机Android Studio的这个文件内容直接全部复制过来就行或者单独修改Url:
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
如何快速获取本机Android Studio相关预设和版本
直接自己新建一个项目,然后去对应的文件里把对应的需要更改的内容直接复制过来即可