Editing an XMLFile gives a read-only error
I am trying to modify and XML file, but when I try to run the code it is saying that the file in read-only and cannot be modified.
How do I change the file to writable. I have checked the system settings and the file is not marked as read-only.
// Look for the Android Manifest
PsiFile androidManifest = Utils.findLayoutResourceByName(psiFile, project, "AndroidManifest");
// Create XML element
StringBuilder xmlTagBuilder = new StringBuilder();
// <uses-permission android:name="android.permission.INTERNET" />
xmlTagBuilder.append(" <uses-permission android:name=\"android.permission.");
xmlTagBuilder.append(permissionsMaps[2].getPermission());
xmlTagBuilder.append("\" />");
String xmlTag = xmlTagBuilder.toString();
XmlTag tagFromText = XmlElementFactory.getInstance(project).createTagFromText(xmlTag);
XmlFile containingFile = (XmlFile) androidManifest.getContainingFile();
containingFile.getRootTag().addSubTag(tagFromText, false);
Please sign in to leave a comment.
bump
Please give the exact error message you get.
Alright I found out why the file was Read only. It was because a search via this method was bringing the AndroidManifest from a jar thats part of a dependency from Android SDK, and not the project's own AndroidManifest.xml.
Here's the method I am using.
I am probably searching incorrectly.