对于一个别人的Android项目,想在本机跑,如果不想重新下载一堆额外的插件,可以在使用Android studio打开项目前先修改设置,只需要一般修改三个文件的内容,就可以很快的将项目跑起来。假设项目名称叫master,需要修改的文件如下:
master\build.gradle 文件 master\app\build.gradle 文件 master\gradle\wrapper\gradle-wrapper.properties 文件master\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.3.2'
classpath 'org.greenrobot:greendao-gradle-plugin:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
classpath 'com.android.tools.build:gradle:3.3.2'
将3.3.2改成自己的Android Studio版本,如3.5.3
如果是kotlin编写的项目,还可以将kotlin版本改成自己编译器的版本,如:ext.kotlin_version = '1.3.71'
master\app\build.gradle 文件
apply plugin: 'com.android.application'
apply plugin: 'org.greenrobot.greendao'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.gugo.gugomain"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
greendao {
schemaVersion 5//每次升级版本号增加
daoPackage 'com.gugo.gugomain.db.green'
targetGenDir 'src/main/java'
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
buildToolsVersion '28.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'org.greenrobot:greendao:3.2.2'
implementation 'com.android.support:design:27.1.1'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.youth.banner:banner:1.4.10'
implementation 'com.lzy.net:okgo:+'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.google.code.gson:gson:2.7'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation project(path: ':apptext')
implementation project(path: ':speechDemo')
implementation project(path: ':zxing')
implementation 'com.rmtheis:tess-two:9.0.0'
}
对于这个文件,我们应该关注的是:compileSdkVersion 28
,minSdkVersion 21
,targetSdkVersion 22
,统统改成Android Studio预设的值
master\gradle\wrapper\gradle-wrapper.properties 文件
#Fri Mar 29 14:03:52 GMT+08:00 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
这里要修改的是gradle的版本,一样,改成自己的,如改成:distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
如果不知道自己Android Studio的预设值怎么办?,那新建一个项目,去对应的文件中查看即可
作者:YDDUONG