Android打包上传市场时,报错
attribute: attribute is not a string value
后来发现是因为values下的string文件和values-zh下的string没有对应好,有的字符串其中一个有,另一个文件又没有,可能就会出现这种问题。可以用以下java文件对比两个文件,补全相应字符串。
使用方法:
执行以下java文件,file1和file2分别传需要对比的文件路径,执行完后,相应缺少字符串的文件在标签后,会补全相应字符,把字符剪切粘到resource标签内即可
public class Test {
public static final String encoding = "UTF-8";
public static String file1 = "C:\\Users\\00lix\\AndroidStudioProjects\\app\\src\\main\\res\\values\\strings.xml";
public static String file2 = "C:\\Users\\00lix\\AndroidStudioProjects\\app\\src\\main\\res\\values-zh\\strings.xml";
public static void main(String[] args) {
comparison(new File(file1),new File(file2),null,null);
comparison(new File(file2),new File(file1),null,null);
}
public static void comparison(File file1,File file2,String str,String lineValue){
try {
if(file1.isFile() && file1.exists()){
InputStreamReader read = new InputStreamReader(
new FileInputStream(file1),encoding);
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt = null;
boolean flag = false;
while((lineTxt = bufferedReader.readLine()) != null){
String result = getMatchResult(lineTxt);
if (!isEmpty(result) && isEmpty(str)) {
comparison(file2,null,result,lineTxt);
} else {
if(result.equals(str)){
return ;
}
}
}
if (!isEmpty(str) && file2==null) {
System.out.println("杩藉姞鏂囦欢");
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file1,true), encoding));
writer.newLine();
writer.write(lineValue);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
read.close();
}else{
System.out.println("鎵句笉鍒版寚瀹氱殑鏂囦欢");
}
} catch (Exception e) {
System.out.println("璇诲彇鏂囦欢鍐呭鍑洪敊");
e.printStackTrace();
}
}
public static boolean isEmpty(String str){
if (str == null || str.length() == 0)
return true;
else
return false;
}
public static String getMatchResult(String value){
if(value.indexOf("name=\"") > 0) {
int i = value.indexOf("name=\"");
value = value.substring(i+=6, value.indexOf("\"",i+6));
return value;
}
return "";
}
}