Android Studio 从 2.3 升级到3.2

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Sindyue/article/details/85089615

Android Studio 从 2.3 升级到3.2以后,对于旧工程的引入,需要如下处理:

  1. 工程下的引入studio 版本和 gradle 的版本需要跟进,如studio 3.2.1和gradle 4.6:
dependencies {
	classpath 'com.android.tools.build:gradle:3.2.1'
	// NOTE: Do not place your application dependencies here; they belong
	// in the individual module build.gradle files
}

distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
  1. project的build.gradle文件中删除
1)classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
	module的build.gradle文件中删除
2)apply plugin: 'com.neenbedankt.android-apt'
	module的build.gradle文件中替换
3)//apt 'com.jakewharton:butterknife-compiler:8.0.1'
	annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'
  1. buildVersionCode 可以删除掉
    高版本中,buildVersionCode可以省略不些,系统会自动选用合适的版本进行编译。
  2. compile 相关关键词替换
Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
Configuration 'androidTestApi' is obsolete and has been replaced with 'androidTestImplementation'.
Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation' and 'androidTestApi'.
Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'.
Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.

‘implementation’ and 'api’的区别,详情可参考链接 https://www.jianshu.com/p/8962d6ba936e
这是因为implementation只能用于当前的module,倘若在库中用这种方式设置依赖,我们在app的module就引用不到。但是api可以。
6. All flavors must now belong to a named flavor dimension.

在主app的build.gradle里面的
defaultConfig {
	targetSdkVersion:***
	minSdkVersion :***
	versionCode:***
	versionName :***
	//版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了
	flavorDimensions "versionCode"
}

PS:升级后会遇到各种问题,一定要尽量正确解决问题,否则可能会出现错误方式导致的错误问题,最终导致无解。。。

猜你喜欢

转载自blog.csdn.net/Sindyue/article/details/85089615