Android permissions overrided by Phonegap - android

I have a PhoneGap 3.2 project. I am building this project to Android using:
phonegap build android
The project Manifest.xml generated contains the RECORD_AUDIO permission. However, I do not need this permission. If I remove it, the next time I run the build command, the permission comes back. I makes my deployment cycle a hassle with many manual modifications.
How can I prevent phonegap of always adding it? Or how can I add the required info to the config.xml file to handle this issue?

If it keeps getting defined at build time, check your config.xml if you have it specified there?
<gap:plugin name="org.apache.cordova.media" />
That would cause it to get added again at build.

Related

How to control [Android] permissions with Phonegap?

Sorry for the length of this. Please read on.
How can I configure phonegap's project files so that either phonegap platform add or phonegap build generate APK (or intermediate files that are used to generate APK) without any permissions, while not touching any of the /platform/android/ files manually?
Below describes what I tried.
I'm using the latest Phonegap and I'm trying to use CLI (so, not Adobe's build service). I went through everything that I could find online (documentation, forums, here) trying to find at least some hints on how to control the build process, preferably via config (specifically for Android), so that files in /platforms/android/ (e.g. AndroidManifest.xml) get assembled the way that I want.
For example, even with all plugins removed (phonegap plugin remove [plugin name] + manually removed <plugin element from /config.xml, resulting in nothing but an empty json object in /plugins/fetch.json), I can't get AndroidManifest.xml to get created without these 3:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
I'd really not like to get into the discussion of why I'm trying to remove all permissions without manually changing /platform/android/AndroidManifest.xml. I previously used Visual Studio Cordova project template, and I was able to make this work (it's got a different file merge/replacement system, equivalent of which I'm trying to discover on Phonegap side). Both Phonegap and Cordova documentation in general are very selfish/basic, IMO (but, that's another topic).
Of course, I've been removing/re-adding android-platform via phonegap platform remove/add android + phonegap build android each time after config change attempts (which I tried within /config.xml; I also tried to find a spot in the folder tree to place AndroidManifest.xml that would replace the one in /platform/android), but nothing worked. I've been verifying success/failure of my mission via aapt d permissions "platforms\android\build\outputs\apk\android-debug.apk", and by manually checking generated /platforms/android/AndroidManifest.xml, and - no kidding - by release-bulding + signing + uploading to my Google account for their report of my APK (by that was before I discovered aapt.exe).
If anyone can share some links, samples, book titles, or similar - I'd be grateful.
Thank you.
Add:
xmlns:android="http://schemas.android.com/apk/res/android"
to widget declaration in config.xml.
Then add the following:
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.RECORD_AUDIO" />
</config-file>
</platform>
Hope it helps!

Cordova does not seem to add android.permission.INTERNET

Hi I'm finding lots of posts about people having to many permissions for their android platform when they use cordova.
I'm missing the INTERNET permission. I can add this manually, but I don't want to do this every single time someone wants to compile an app (The platforms dir is on .gitignore and should not be versioned, so whenever someone takes over the project or w/e it should generate fine).
Currently the manifest adds 2 permissions:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
It should however also add INTERNET, which works fine when I add it manually.
I tried adding
in my config.xml, also
But no cigar, I removed the android platform also to see if it was just not being built.
Recently tried using Phonegap Build, causes the same issue, also for Windows Phone. So currently I can only do iOS properly.
It magically started working, I have no clue why it didn't get added before. I did not even update the platforms or w/e.

Visual Studio Cordova App add plugin as optional feature

I am having an issue in publishing my app in Google play when I include some plugins like cordova-plugin-geolocation in my app, as it adds the following 2 permissions in my manifest file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
this causes an issue that some of the phones are not able to view the app in the google play as they tell me that android.hardware.location.network access is not compatible on those devices.
when I researched a bit more, I can see that this can be avoided by converting uses-permission to uses-feature and setting the android:required="false" then I can handle it in my code as this is not a must have feature for me.
My issue is I am unable to find how to change this in my visual studio project. can someone please help me understand whats the way to fix this?
Regards
Kiran
There is no way within VS to add contents to your Android projects manifest file. You will have to hand edit those, but beware that these changes would be over-written every time you build your project through VS. There are couple of ways you can workaround this -
You can add post_build Cordova hook that would update the Manifest file.
You can add a gulp task and hook this to MSBuild post_build event through VS.
SOak
(PM - Microsoft)

Android/PhoneGap local build not working after removing Admob Plugin

I added this plugin: https://github.com/aliokan/cordova-plugin-admob
with the command line in PhoneGap 3.3
However I decided to use a different plugin. After attempting an uninstall:
cordova plugin remove com.google.cordova.plugin.AdMobPlugin
I rebuilt the app and launched it on my device. The application compiles fine but the information I display (an RSS feed) does not display the data. Instead, my error catch displays a message. BUT, when I re-install the plugin, it works!
I have not changed any part of the config.xml file, or Android Manifest so I am lost as to why this is happening. Any help?
The plugin adds some authorisations in AndroidManifest.xml when it's added :
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I think that your issue is that when you remove the plugin, it doesn't know if this authorisations were already there (added by an other plugin or present by default) or not and removes the lines in all cases.
I suggest you manually edit platforms/android/AndroidManifest to add the lines you need.
If you have no plugins in your project, you will at least need to add android.permission.INTERNET which is present in default cordova project and needed for any app accessing network.
If you have FILE plugin or any other plugin needing to write to sdcard, also add android.permission.WRITE_EXTERNAL_STORAGE.

How do you force a landscape orientation for mobile apps built with cordova-cli?

I'm using cordova cli to build my app. I want to target both android and ios (maybe more).
As I want this to be true for all platforms, I was hoping I could simply define this as a preference in the config.xml like this:
<preference name="orientation" value="landscape" />
because this is apparently how it works in the phonegap build https://build.phonegap.com/docs/config-xml
I assume the features supported in config.xml by phonegap build are different to those by cordova-cli?
I know I can force it in the android app by inserting android:screenOrientation="landscape" into my AndroidManifest.xml, but that's no good because it will be over-written the next time I perform a cordova build.
Any suggestions?
This is no longer the case. The "orientation" preference in the config.xml is now honored by the cordova cli starting from version 3.4
This is the corresponding issue : https://issues.apache.org/jira/browse/CB-5634
Simply put, it's not possible to set the orientation using a preference element in the www/config.xml. After inspecting the cordova-cli code it appears that only the version and entry class package are updated in the AndroidManifest.xml.
For a list of supported preferences see the Cordova Docs.
Added configurations to the AndroidManifest.xml file should not be lost on cordova build, unless the config option is pulled from somewhere else (i.e. version).

Categories

Resources