For my personal purposes I'd like to parse comments in Android Manifest file. In these comments there can be tags with attributes and values that I want to extract. It is similar to tag in html files that is usually commented because some browsers does not support this tag. So I want to implement similar things in android manifest.
I know that in Android manifest file is parsed using SAXParser. Moreover, I think I should use LexicalHandler for this purposes but I've never faced before with this functionality and I want to know how to do this. Code snippets and any help will be highly appreciated!
I'm entirely sure that you cannot parse the raw XML Manifest, because like everything that is in the res folder (except res/raw), the manifest is compiled and stored in a binary format, so the comments are removed.
Maybe you can play with xmlns and capture the manifest parsing... But I doubt it, the Manifest is interpreted by the package manager, and I don't think that you can have access to it.
The solution (from your feedbacks):
The requested feature is impossible, because during the compilation all comments from AndroidManifest file are removed.
You can check this in the following way:
Create a simple app project (Hello World) and add comments in your AndroidManifest file.
Compile project and export an .apk file (signed or unsigned).
Using tools like apktool or similar extract your apk file.
Check the result in AndroidManifest.xml - there are no comments.
You should try to find other way.
I don't think it is possible as the AndroidManifest is not available as a classpath resource. The only way I can think of is to actually make a copy of the AndroidManifest.xml into your source files and have it built as a compiled object using an ant target
Then you just access it like a normal XML file using the XML APIs.
I hate to be that guy, but you should probably maintain your custom XML in /assets/ and not overload the manifest.xml file.
Related
for security reasons is necessary remove all mi sensitive comments like urls, so i wonder if is necessary to remove it from my strings.xml file, because I researched and I found when application is package into *.apk the comments inside of an layout.xml will be suppressed, but i can't figured out if it apply too for the comments in the path res/values/*.xml
Do you have any idea?
Thanks for your support.
No, you don't have to remove the comments from any xml resources. They are removed automatically when you compile the apk file.
I've been using repo for quiet a long time now but never bothered to know what <remove-project> in manifest.xml does.
What does <remove-project> do — it doesn't download the project at all or it downloads it but removes it from codebase later?
It's here somewhere but I'm pretty bad at reading python.
https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.md#Element-remove_project
Element remove-project
Deletes the named project from the internal manifest table, possibly allowing a subsequent project element in the same manifest file to replace the project with a different source.
This element is mostly useful in a local manifest file, where the user can remove a project, and possibly replace it with their own definition.
Is it possible to specify some information, such as API keys, in a file, and then somehow inject this information into the AndroidManifest file (maybe during the build process)?
For my particular use case, the documentation for react-native-maps requires adding a Google Maps API key to the AndroidManifest file. However, I'd like to keep sensitive information out of the AndroidManifest file (instead, inside a file that will eventually be gitignored for example).
On a side note, from this question, it seems that all information inside the AndroidManifest is available to all packages on the same device. Is this still true?
If the information is only needed in the manifest, you can define manifest placeholders in your build.gradle file and reference them using ${} macro syntax in the manifest.
If the information might be needed elsewhere, consider using string resources created via resConfig in your build.gradle file.
The build.gradle file can pull the actual values from gradle.properties, a custom properties file, via some API call to a server, or whatever else you want, given sufficient Gradle/Groovy/Java coding. Typically, I have gradle.properties listed in .gitignore, and so I put this sort of thing in there, though I am not certain if that approach is common practice.
it seems that all information inside the AndroidManifest is available to all packages on the same device. Is this still true?
"All" is a strong term, but I would say that the vast majority of information in the manifest is visible through PackageManager. Sometimes, it's not directly accessible (e.g., I don't recall a way to get the <intent-filter> list for a component), but it's still there if you find the right way to get at it.
I have MyAppProject as android application project and MyLibProject as android library project.
I have strings.xml(2 strings) and one xyz.java class in MyLibProject.
xyz.java class has 2 get methods to access the strings.xml values.
I have added reference library project "MyLibProject" in "MyAppProject" application project.
For some usecase, I will check whether Library project xyz.java class is in classpath then get the
values from xyz.class.
How to access the strings.xml texts in xyz.java class get method?
As far as I'm aware, you should be able to access any references via a fully qualified name for the R file you're attempting to access, via the Context. Something like (untested):
Context.getString(com.YOUR.LIB.R.string.YOURSTRING));
Failing that, you could possibly import the com.YOUR.LIB.R file directly into your activity.
Hope this helps! And I hope that I understand what you're trying to achieve. If not, please provide more information and possibly some code you've already tried, may help explain your problem :)
This question has been very old, but creating Android libraries will never get old. I have been working on creating Android libraries for a few days now, and myself encountered this issue of not been able to use res directory resources in library's java files due to some reason. After 2 days of searching, I found that I was missing package declaration in my library's manifest file.
So, to make it working, check if you have declared package in manifest.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.yourpackage">
</manifest>
It worked for me after this change, now I can use resources in library's java files. I hope it works for you too.
My goal is to create multiple android APKs. All that is different is the package name and I manually override some things in the res folder.
I understand you can do a library project. The problem with that is we have to manage multiple manifest files and the version with that. That is not what I want to do.
I was looking into aapt to create the new package name and shared res folder. The problem is I do not know where to start. I see lots of examples like:
Custom Android build.xml for rename manifest package
also below is exactly what I want to do:
http://blog.uncommons.org/2010/07/19/building-two-versions-of-the-same-android-app/
Can anyone provide direction on where to start?
The best way to do this is to create a library project, and than create separate projects for each of the APKs that you want to have. Each APK project can than have its own Manifest and reference the Library Project. Believe me when I tell you that this is much easier than trying to rename packages during build/compile time. You can easily call into activities that are shared in the library package just as long as you use the fully qualified name in the individual APK's manifest file.
http://developer.android.com/tools/projects/projects-eclipse.html
I had the same problem before and made a batch file to copy files like images, mp3 files, etc. to the workspace folder where I have my application folder in it. You have to make everything dynamic if you don't want to use the library project. I hope this helps, else you can ask me anything you want.