I have a question, is it possible to read package name inside AndroidManifest.xml
I mean
I have a AndroidManifest.xml as below
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackagename"
android:installLocation="auto"
android:versionCode="1"
android:versionName="1.0" >
....
</manifest>
Now I have to add a permission (used for GCM)
<permission
android:name="MYPACKAGENAME.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
Is it possible to replace MYPACKAGENAME with com.mypackagename dynamically in the above permission tag.
Every app project must have an AndroidManifest. xml file (with precisely that name) at the root of the project source set. The manifest file describes essential information about your app to the Android build tools, the Android operating system, and Google Play.
Just open your APK and in treeview select "AndroidManifest. xml". It will be readable just like that.
It has many attributes such as label, name, theme, launchMode etc. android:label represents a label i.e. displayed on the screen. android:name represents a name for the activity class. It is required attribute.
Element Tags of Manifest File It is the root element of this element. It consists of a package attribute package that tells the activity's package name. It is the subelement of the manifest file that includes the declaration of the namespace. It contains certain attributes.
You can drop the package name part of the name:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackagename">
...
<permission
android:name=".permission.C2D_MESSAGE"
android:protectionLevel="signature" />
...
</manifest>
When you start your permission name with . it gets prefixed with package name automatically.
You cannot change package name dynamically, but you can do certain things by defining applicationId in build.gradle and then prefixing names in android manifest with ${applicationId}.
in build.gradle:
android {
compileSdkVersion 19
buildToolsVersion "19.0.2"
productFlavors {
development {
applicationId = "com.mypackage.development"
}
}
}
And then in your AndroidManifest.xml have:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackagename">
...
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
...
</manifest>
You can find a bit more from here: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger
Later approach will allow you to run development flavor of your app side by side your production version. I hope this helps.
You can use ${applicationId}
to substitute your package name, eg.
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With