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.
Related
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.
I was wondering why AndroidManifest.xml is named like this and not simply Manifest.xml and if this means that there are different types of Manifests? I was reading the information about AndroidManifest but could not find anything. Or do they only want to emphasize that the coupling between the Manifest and Android (OS) is super tight?
Except for some included settings or icons which make a distinction about android built-in things and the option to include your own I have not seen Android name as a prefix except in the Manifest file. For example: the directories in the res folder have special meaning in android but also don't have the Android prefix or something alike, that makes me wonder even more why they decided to name it AndroidManifest instead of just Manifest.xml.
there are different types of Manifests?
There are many things in Java development that are manifests, such as WEB.XML in a Java servlet, JAR manifests, etc.
Can you write manifest like files yourself with a different name?
You are welcome to write your own framework that has its own manifest-style file structure for whatever purposes you want.
It almost seems by the way they named it that there could be other Manifests as well.
Not in Android. However, Android is not the only framework in existence, either.
Second if it's not possible to create your own Manifests like files I wonder why it was named this way.
Historical reasons, most likely. The name choice was made close to a decade ago. If you own a time machine, hop back in time, figure out where Android Inc. was based, head over there, and ask them.
On the whole, Google (let alone the old Android Inc. firm they bought) has not provided much in the way of detail about why things are named the way that they are.
Every android app has just single AndroidManifeset.xml file. As for why this specific name was chosen, I have no idea, but if you look at it the name kind of makes sense.
I am implementing a library, and I would like the functionality of this library included in applications that I develop with very little effort. For example, I would like each application I develop to implement a content provider that supplies a path to a file.
At present I identify applications that support the library using a meta-data tag. I would prefer it if I could add the content provider's tag at compile time, rather than explicitly adding the tag to the manifest of each new application I develop.
My question: Is there a way of inserting code into the manifest at run-time?
Is there a way of inserting code into the manifest at run-time?
No, sorry.
For example, I would like each application I develop to implement a content provider that supplies a path to a file.
If that is all the ContentProvider is for, this is akin to swatting a fly with a truck. Just call some method on some class exposed by the library from the application, passing in the path. Or, have the path name be held in some pre-defined resource name (e.g., R.string.this_is_the_path_yo), and look up that resource by name at runtime from the library. Or, have the file be in some pre-defined location (e.g., within assets/) and skip the whole resolve-the-path problem.
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.
Can anybody explain me in simple words what is the use of Manifest file and
R.java file in android.
Why do we need these files while making an application?
check this link,
http://developer.android.com/guide/topics/manifest/manifest-intro.html
Manifest
Every application must have an
AndroidManifest.xml file (with
precisely that name) in its root
directory. The manifest presents
essential information about the
application to the Android system,
information the system must have
before it can run any of the
application's code
R.Java
It will have identifier for all resource used in our project
thank you.
Manifest file:
It is a declaration file.
Here only Which activity should start first, that has been declared.
It declares which permissions the application must have.
It also declares the permissions that others are required to have in order to interact.
It declares the minimum level of the Android API.
It lists the libraries that the application must be linked.
All the component should declared here.
The components are activities, services, broadcast receivers, and content providers.
R.java file:
It is an auto-generated file by aapt (Android Asset Packaging Tool) that contains resource IDs for all the resources of res/ directory.
If you create any component in the activity_main.xml file, id for the corresponding component is automatically created in this file.
This id can be used in the activity source file to perform any action on the component.
Every application must have an AndroidManifest.xml file (with precisely that name) in its root directory. The manifest presents essential information about the application to the Android system, information the system must have before it can run any of the application's code.
Check the following link
http://developer.android.com/guide/topics/manifest/manifest-intro.html
A project's R.java file is an index into all the resources defined in the file. You use this class in your source code as a sort of short-hand way to refer to resources you've included in your project. This is particularly powerful with the code-completion features of IDEs like Eclipse because it lets you quickly and interactively locate the specific reference you're looking for.
Check the following link
http://developer.android.com/resources/tutorials/hello-world.html
In short terms Manifest provide the basic information of the application to Android Operating system.
For example say you have a feature in your app that scans a QR code which requires your app to access camera that won't work until unless you get the consent of the user to access their's phone camera which is done by runtime permissions.These permissions needs to be defined in the Manifest file for Android OS to know that this app will be using something related to camera of user's phone.
The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.
The permissions that the app needs in order to access protected parts of the system or other apps.
The hardware and software features the app requires.
The manifest declares anything that the operating system needs to know about your application.
You declare what permissions the OS will grant to your app when it executes.
You will also declare package information about your app. By doing that the OS will know what applications are installed.
Finally, you will declare custom implementations of the Foud Application Components (Activity, Service, BroadcstReceiver and ContentProvider classes) you have made.
You see, your application, any activities and services are not created by you. They are constructed by the OS through intents on behalf of your app. Likewise, all BroadcastReceivers need to be registered at the manifest, so the OS knows what application's receivers are registered to receive a broadcast, so it notifies them. Finally all ContentProviders must also be declared in the manifest so other applications can register to be provided content by your content provider.
In other words, in the manifest you put everything that the OS needs to know about your app in order to execute it and manage its components. Infact, anything you cannot access or declare directly by code, and you need the OS to take care of it...
I think it is a good idea for you to read through the Android Hello World.
Both AndroidManifest and R.java are explained.