AndroidStudio3.1.1 踩坑

1、升级AndroidStudio后,首先得改各种版本号

  "buildToolsVersion": "27.0.3",
  "compileSdkVersion": 27,
  "targetSdkVersion" : 27,//
  "supportVersion" = "27.1.0"//support报的版本号。例如:com.android.support:appcompat-v7:27.1.0
   classpath 'com.android.tools.build:gradle:3.1.1'

2、项目\gradle\wrapper里文件gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

改完后重新编译一下发型各种抱错:
ERROR:Failed to execute aapt:


AndroidStudio3.1.1 踩坑_第1张图片
屏幕快照 2018-04-12 下午9.46.53.png

解决方案:在设置里的Build,Execution,Deployment ---> Instant Run 里面的Enable instant Run to hot swap........的这个选项取消选中


AndroidStudio3.1.1 踩坑_第2张图片
屏幕快照 2018-04-12 下午9.47.56.png

改完之后再重新运行一下发现还是一大堆的错误信息,乍看50个错误,7个警告,一片红,瞬间吓一跳


AndroidStudio3.1.1 踩坑_第3张图片
屏幕快照 2018-04-12 下午10.02.47.png

仔细看了一下具体的错误发现其实50个错误就是那7个警告导致model/jar包引用失败导致的

Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018.
Configuration 'testCompile' is obsolete and has been replaced with 'testImplementation' and 'testApi'.
It will be removed at the end of 2018.
Configuration 'testApi' is obsolete and has been replaced with 'testImplementation'.
It will be removed at the end of 2018.
Configuration 'androidTestCompile' is obsolete and has been replaced with 'androidTestImplementation'
It will be removed at the end of 2018.

解决办法,直接按照警告内容改就好了:

compile会被在2018年底取消,会被implementation和api替代,所以会报这个警告,解决警告的方式就是换成implementation/api就好了。

更换前

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'
 })
testCompile 'junit:junit:4.12'
compile 'org.greenrobot:eventbus:3.0.0'

更换后:

api fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'junit:junit:4.12'
api  'org.greenrobot:eventbus:3.0.0'

由于Support-V7:27.1.0 版本改了不少东西会导致有些类找不到,因此代码里也存在一些错误:
1、import android.support.v7.appcompat.BuildConfig; 找不到BuildConfig
解决方案:直接应用项目包名的BuildConfig,编译器会自动生成该类

2、import android.support.v4.view.KeyEventCompat; 找不到
解决方案:删掉引用,KeyEvent已经有相关方法判断了

if (KeyEventCompat.hasNoModifiers(event)) {
      handled = arrowScroll(FOCUS_FORWARD);
} else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
     handled = arrowScroll(FOCUS_BACKWARD);
}

改成

if (event.hasNoModifiers()) {
     handled = arrowScroll(FOCUS_FORWARD);
} else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
      handled = arrowScroll(FOCUS_BACKWARD);
}

3、import android.support.v7.app.NotificationCompat;找不到
解决方案:改用其他的引用

解决完了各种错误,重新编译运行终于运行成功了

你可能感兴趣的:(AndroidStudio3.1.1 踩坑)