Android Studio 3.0.1升级至3.1时补丁更新冲突报错求助
嘿,我之前升级AS版本时也碰到过一模一样的冲突提示,大概率是你自定义的simple.xml.ftl模板文件出了问题——要么是语法错误,要么是和AS 3.1的模板规则不兼容。结合你给出的代码片段,我给你几个可行的解决步骤:
第一步:先备份你的模板文件
这个文件的位置一般是:- Windows:
Android Studio安装目录/plugins/android/lib/templates/activities/simple/res/layout/simple.xml.ftl - Mac:
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/activities/simple/res/layout/simple.xml.ftl
先把它复制到安全的地方,避免操作时丢失你的自定义内容。
- Windows:
第二步:修复模板文件的语法错误
从你贴的代码片段来看,你的ConstraintLayout起始标签根本没闭合!你写的代码里:<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" <#if hasAppBar &&...看到没?
android:layout_height="match_parent"后面少了一个>,这是明显的XML语法错误,AS升级时检测到这个问题就会触发冲突提示。先把这个错误补上,改成:<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <#if hasAppBar &&...修复后再重新启动升级流程试试。
第三步:如果语法修复后还是冲突,尝试合并模板差异
AS 3.1的模板可能有一些变量或依赖的变化,比如如果你的项目准备迁移到AndroidX,AS可能默认模板会用androidx.constraintlayout.widget.ConstraintLayout替代旧的android.support.constraint.ConstraintLayout。你可以打开升级时的冲突对比界面(如果AS提供的话),把AS 3.1默认模板的新特性合并到你的自定义模板里,确保变量引用、标签格式都符合新版本要求。第四步:终极方案——干净安装
如果上面的方法都不管用,那就彻底卸载AS 3.0.1,清理掉残留的配置文件(比如Windows的C:\Users\你的用户名\.AndroidStudio3.0,Mac的~/Library/Application Support/AndroidStudio3.0),然后直接安装AS 3.1,之后再把你备份好的模板文件修改兼容后复制回去。
内容的提问来源于stack exchange,提问作者Amrish Kakadiya

