Android中使用databinding编译时出现的error:Execution failed for task ':app:dataBindingProcessLayoutsDebug'

时间:2023-03-09 07:15:16
Android中使用databinding编译时出现的error:Execution failed for task ':app:dataBindingProcessLayoutsDebug'

Windows环境下使用svn对AndroidStudio更新代码时,总会在源文件中出现一堆乱码,尤其是xml文件中的乱码,不仅找起来费劲,改起来更费劲。

最近从svn更新代码之后,编译时出现了下面这个提示,而且AS中没有错误提示,这可真是捉急了。

databinding error:Execution failed for task ':app:dataBindingProcessLayoutsDebug'

后来,多亏这篇帖子提示,自己写了段代码来尝试下,http://*.com/questions/35097445/android-databinding-errorexecution-failed-for-task-appdatabindingprocesslayo!

果然找到问题了,那么多xml文件,就一个文件头多了一个0xfeff,最终还是找到了那个文件并修改了。下面上一段文件搜索代码,这个解决代码很简单,应该都不是难事吧。

  public static void main(String[] args){
String path="E:\\svn\\ZonetryPlatform\\app\\src\\main\\res\\layout";
File file=new File(path);
String[] list = file.list();
int length = list.length;
System.out.println("file.size="+length);
for (int i = 0; i < length; i++) {
String onePath = list[i];
File oneFile= new File(path, onePath);
FileInputStream fis=null;
FileReader fr=null;
char[] b=new char[1];
try {
// System.out.print("寻找当前文件="+onePath);
fr=new FileReader(oneFile);
fr.read(b, 0, 1);
// System.out.println("the first c of the file = "+b[0]);
if (b[0]==0xfeff){
System.out.println("=========================当前文件出现异常字符, file="+onePath);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fis!=null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// System.out.println("the first c of the file = "+b[0]);
if (b[0]==0xfeff){ }
}
}