androidstudio升级后gradle配置出现的问题
(可以 ctrl+f 搜索 (需改动) 可以快速定位到要改动的位置)
项目的build.gradle里面有改变
buildscript {
repositories {
google() //(需改动)as3.0以上这里要配置
jcenter()
}
dependencies {
//c:\program files\android\android studio\gradle\m2repository\com\android\tools\build\gradle
//c:\program files\android\android studio 你自己本机的android studio路径(需改动)
classpath 'com.android.tools.build:gradle:3.1.2'
}
}
allprojects {
repositories {
google() //(需改动)as3.0以上这里要配置
jcenter()
maven { url "https://maven.google.com" }
maven {
url 'https://dl.bintray.com/oschinaapp/maven/'
}
}
}
task clean(type: delete) {
delete rootproject.builddir
}
ext {//这个给module里的build.gradle配置的常量
compilesdkversion = 26
buildtoolsversion = "26.1.0"
applicationid = "cn.cn.oschinadome"
minsdkversion = 19
targetsdkversion = 24
versioncode = 288
versionname = "v2.8.8(1708301525)"
supportversion = '25.1.0'
}
项目下的gradle文件配置
project(项目目录下)\gradle\wrapper\gradle-wrapper.properties
distributionbase=gradle_user_home
distributionpath=wrapper/dists
zipstorebase=gradle_user_home
zipstorepath=wrapper/dists
distributionurl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
#目录:例如 c:\users\machenike\.gradle\wrapper\dists 这个在你用户目录下的.gradle\wrapper\dists看有没有
#3.5以上的gradle版本,gradle-4.4-all是我目录下的
#也可以直接删除gradle文件,直接使用在线的gradle
module下的build.gradle文件需要改动
apply plugin: 'com.android.application'
android {
compilesdkversion rootproject.ext.compilesdkversion //在项目中的build.gradle ext{}里面
//buildtoolsversion rootproject.ext.buildtoolsversion //(需改动)在as3.0以上不需要这个配置了
defaultconfig {
applicationid rootproject.ext.applicationid
minsdkversion rootproject.ext.minsdkversion
targetsdkversion rootproject.ext.targetsdkversion
versioncode rootproject.ext.versioncode
testinstrumentationrunner "android.support.test.runner.androidjunitrunner"
versionname rootproject.ext.versionname
// jackoptions.enabled = true //(需改动) 如果你有这个需注释掉
}
// rename the apk with the version name
// applicationvariants.all { variant -> //(需改动)as3.0之后这个是只读,不能这样修改apk的名字,需要注释掉
// variant.outputs.each { output ->
//output.outputfile = new file(
// output.outputfile.parent + "/${variant.buildtype.name}",
// "dome-osc-android-${variant.versionname}-${variant.buildtype.name}.apk".tolowercase())
// }
// }
//signing files settings
signingconfigs {
debug {
storefile ""
storepassword ""
keyalias ""
keypassword ""
}
release {
storefile ""
storepassword ""
keyalias ""
keypassword ""
}
}
sourcesets { //jni进入项目
main {
jnilibs.srcdirs = ['libs']
}
}
// 移除lint检查的error
lintoptions {
abortonerror false
}
//build type setting
buildtypes {
debug {
zipalignenabled false
minifyenabled true
proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'
signingconfig signingconfigs.release
}
release {
minifyenabled true //混淆
proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'
zipalignenabled true //zip算法压缩
signingconfig signingconfigs.release
}
}
// productflavors { //(需改动)(如果有的话)添加flavordimensions "default" dimension "default" 这两个字段
// oschina {
//manifestplaceholders = [umeng_channel: "oschina"]
// }
// }
//或者另一种改动请查看(https://blog.csdn.net/small_technical/article/details/72782671) 改动的 start
flavordimensions "default"
productflavors {
oschina {
dimension "default"
manifestplaceholders = [umeng_channel: "oschina"]
}
}
//改动的 end
}
dependencies {
compile project(':open')//open项目的引用
//(需改动)这里的所有 compile 变为 implementation或者api
//api(如果open里引用里另一个a项目,implementation的话不能使用a项目里的接口,api的话就可以使用a项目的接口)
//ctrl+r 快捷键 按键把 (compile ) 替换所有为 (implementation ) (区分大小写)
//例如(改动后的) implementation "com.android.support:design:$rootproject.ext.supportversion"
compile "com.android.support:design:$rootproject.ext.supportversion"
compile filetree(include: ['*.jar'], dir: 'libs')
//(需改动)这两个也要替换 这个为替换前的
// androidtestcompile('com.android.support.test.espresso:espresso-core:2.2.2', {
// exclude group: 'com.android.support', module: 'support-annotations'
// }) //android测试框架
// testcompile 'junit:junit:4.12' //测试框架
//替换后的为
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'
}