VS 2022 17.1.0
Xamarin Android SDK 12.2.0.4
We have a Xamarin Forms project that includes an Android target. That Android target has recently been updated to have a targetSdkVersion 31 (Android 12)
We are now getting the following errors when trying to upload our Signed APK to Google Play
Duplicate declarations of permission
android.permission.ACCESS_COARSE_LOCATION with different
maxSdkVersions. Duplicate declarations of permission
android.permission.ACCESS_FINE_LOCATION with different maxSdkVersions.
If I look at the signed APK created by VS2022 build I can see these entries in AndroidManifest.xml
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission-sdk-23
android:name="android.permission.ACCESS_COARSE_LOCATION"
android:maxSdkVersion="30" />
<uses-permission-sdk-23
android:name="android.permission.ACCESS_FINE_LOCATION"
android:maxSdkVersion="30" />
How can I see what is causing these permission values to be merged into our AndroidManifest?
Our currently released build has a targetSdkVersion of 30 (Android 11) and whilst these duplicate permissions are present in the merged manifest for that relesase, Google Play does not complain.
Other AndroidManifest values that might be important are
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="3.7.0"
android:installLocation="0"
android:compileSdkVersion="31"
android:compileSdkVersionCodename="12"
package="com.OurCompany.OurApp"
platformBuildVersionCode="31"
platformBuildVersionName="12">
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="31" />
OTHER VALUES REMOVED
</manifest>
I finally managed to trace which component was adding ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permission entries.
The only way I found to track it down was from all the entries in the "obj" folder under "lp" e.g. \obj\Debug\120\lp
This was wear the various libraries I was using would unpack themselves. I search that folder for occurences of "ACCESS_COARSE_LOCATION" and that gave me the library name that was the problem
The change I made in our AndroidManifest was
<uses-permission-sdk-23
android:name="android.permission.ACCESS_FINE_LOCATION"
tools:node="remove"
android:maxSdkVersion="30" /
Note the use of the tools:node attribute, the Android docs for this are here, https://developer.android.com/studio/build/manage-manifests
I have imported a project that was developed on Eclipse into Android Studio.
The project is working perfectly when running\debugging it from Eclipse on my device.
When debugging from the Android Studio on my device, the application is crashing and no exception is being caught on the Android Studio.
When I place breakpoints, they work fine, so I know i'm debugging the correct code :)
Edit:
I have run it again and got the following Exception in the logcat (shouldn't the debugger stop somewhere in the code to show the Exception? like in the line that tries to access the file?):
2018-10-24 11:25:26.027 25903-25903/? E/libpersona: Couldn't open the File - /data/system/users/0/personalist.xml - No such file or directory
2018-10-24 11:25:31.735 23290-23301/? E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=25858, uid=10314 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:639)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:505)
at android.content.ContentProvider$Transport.query(ContentProvider.java:217)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102)
at android.os.Binder.execTransact(Binder.java:682)
Although I do have permissions set in the AndroidMenifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.eibimalul.smartgallery"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_SOCIAL_STREAM"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Edit 2: The Solution:
So apparently I was missing 2 things:
run-time permissions which I understood using this link here and with the help of #Pier Giorgio Misley's comment
I was missing permissions on the AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
The solution:
Apparently I was missing 2 things:
Run-time permissions which I understood using this link here and
with the help of #Pier Giorgio Misley's comment
I was missing permissions on the AndroidManifest.xml:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
I am not sure if that's the right way to do it (answering my own question that is), since I got help from few developers here (#Pier Giorgio Misley in particular) in the comments only, but I thought it is important to mark the question as answered.
I am getting the following error when I run my application on my phone:
java.lang.SecurityException: Permission denied (missing INTERNET permission?)
I have already added that permission in my manifest file as follows:
<uses-permission android:name="ANDROID.PERMISSION.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I am getting the error only when I run the app on my phone. It runs fine on my GenyMotion emulator. I read similar questions on SO before posting it. Also, I have made a couple of apps before with same permissions, and this error had never occurred then. So I don't get why Android is messing it up this time.
P.S.: I updated my SDK tools before starting with this new application. Somehow felt that it was important to mention it!
Use small caps
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
I am compiling a project that does not explicitly request the READ_PHONE_STATE permission, but when I compile I am seeing the permission in my compiled Android Manifest file. I'm assuming some library that's being pulled in is adding it explicitly or forgot to set its minimum SDK version (which would add it).
The only thing I have to go on is that in the final manifest, the permissions I requested myself look like this:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
And the READ_PHONE_STATE looks like this:
<android:uses-permission android:name="android.permission.READ_PHONE_STATE" />
Does the android prefix mean anything?
Is there any way to narrow down which library is adding this permission?
You can exactly see if a (or because of) library adds some extra Permission to your manifest. Check at file generated (see below) during build process and look for the unwanted permission within the file!
Go to your project folder and look for this path:
[ProjectFolder]/build/outputs/logs/manifest-merger---report.txt
open the file and search for the permission
In my case I found these lines at the
uses-permission#android.permission.READ_PHONE_STATE IMPLIED from
C:\..\...\AppFolder\src\..\AndroidManifest.xml:2:1-14:12 reason:
com.some.evil.library has a targetSdkVersion < 4
This generated file show the output of the merge process described here in Android Developers site.
I would look at:
Android Library Manifest vs. App Manifest
This isn't really a duplicate so I won't flag, however I think he covers the topic fairly well in his answer to that question.
After that and assuming you can't figure it out, I would do the following:
Locate your gradle cache
Crack open the artifacts of each of your dependences (rename to .zip and extract is the easiest way to do this)
check if they have manifests included and see whats in the,
I declared the permission ACCESS_NETWORK_STATE in Application manifest as below.
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Everything is good on Android 2.x. But on Android ICS, it failed with below log cat.
java.lang.SecurityException: ConnectivityService: Neither user 10093
nor current process has android.permission.ACCESS_NETWORK_STATE. at
android.os.Parcel.readException(Parcel.java:1327) at
android.os.Parcel.readException(Parcel.java:1281) at
android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:663)
at
android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:455)
at com.tapfortap.AdView.getNetwork(AdView.java:146) at
com.tapfortap.AdView.loadAdsWithAppId(AdView.java:133) at
com.tapfortap.AdView.access$100(AdView.java:47) at
com.tapfortap.AdView$1$1.run(AdView.java:88) at
android.os.Handler.handleCallback(Handler.java:605) at
android.os.Handler.dispatchMessage(Handler.java:92) at
android.os.Looper.loop(Looper.java:137) at
android.app.ActivityThread.main(ActivityThread.java:4503) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:511) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576) at
dalvik.system.NativeStart.main(Native Method)
I updated the permissions like this and it works.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
this is because ACCESS_NETWORK_STATE is used as connectivityManger and this needs INTERNET connection.
I believe this is an issue with Eclipse; it fails to refresh the manifest to load the permission.
I had the same problem as the original poster and solved it by adding the permission a second time--but then I was able to remove the permission without affecting behavior. This makes me suspect that Eclipse didn't load permissions correctly until I touched the file.
Just add the below permission and it will work fine, i had this a problem before and resolved with me
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET" />
Clean and then Build project solved the issue for me.
Uh-oh,If u adding by default,it will be:
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE"/>
if u re-add permission by:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
It works fine.
Unbelievable ! It costs me 2 days
you are missing the Internet permission.add this permisssion it will correct your problem
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Just cut the <uses-permission android:name="android.permission.INTERNET" /> and paste all the above permissions. It will work fine...
Clean Project. Check the manifest file. Some package name changes or misplaced data may causes this error.
Clean the project will work.
In your code, There would be places where you would be checking the Internet Availability before making your calls so that your app doesn't crash at runtime. For that, you have to access the 'NETWORK STATE' which requires the permission :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
And when the Internet is available, your device communicates with the server using the 'INTERNET' which requires the permission :
<uses-permission android:name="android.permission.INTERNET" />
In my case, neither Clean Project not Rebuild Project worked, and I spent hours to figure out how to get rid of this lint error.
I was also afraid to use the final option Invalidate Caches and Restart because I might roll back to any Local History of a file in future, in case any bug arises.
So finally, I opted for the following option.
I chose File->Invalidate Caches and Restart.
It opened a popup. I then selected the option Just Restart.
And guess what!!It solved my problem. So if any of you are still struggling to get rid of this error, you might wanna try my solution. Do let me know if it worked.