Search Unity

Unity 2017 - read_phone_state permission, cant remove

Discussion in 'Android' started by CavElliott, Aug 4, 2017.

  1. CavElliott

    CavElliott

    Joined:
    Mar 12, 2017
    Posts:
    4
    Hey unity forum, I am trying to upload my game to the google play store, however it keeps stating that its asking for "read_phone_state" permissions, now I know that one cause of this is using systeminfo, so I have removed all references to systeminfo.

    I also read somewhere that WWW causes the permission to be added, so removed any use of that as well.
    I am using Unity analytics so was wondering if this could be the cause?
    If not what are possible causes for this permission to be added, or is this just a bug on unity's end, as I remember this permission being added by a bug in a previous version of Unity.

    Thanks for reading
     
    waken likes this.
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,053
    FranzBertazzo likes this.
  3. Aminjon_Warshav

    Aminjon_Warshav

    Joined:
    Jan 21, 2015
    Posts:
    4
  4. jknight-nc

    jknight-nc

    Joined:
    Jun 10, 2014
    Posts:
    52
    This is a huge problem for me and my company. How can we get rid of READ_PHONE_STATE!!!!!

    We've been manually removing it for years but now we cant get rid of it!
     
    ErayT and waken like this.
  5. SIDIA2

    SIDIA2

    Joined:
    Mar 18, 2015
    Posts:
    1
    suffering from the same thing here...on an empty project, sure, no permission added, but on our current one, nothing gets rid of it. Tried removing all plugins, setting minSdk, everything...Unity is doing little to adress the issue.
     
  6. ErayT

    ErayT

    Joined:
    Dec 13, 2013
    Posts:
    20
    I have seen thousands of posts talking about the similar issue. It is agreed that Unity injects additional permissions in the build phase. The thing we should ask if you ask me, is "Are there any ways to find and list the things causing that injection?"... Thus we can get rid of that part right!?...

    PS: I am having the same problem in 5.3.5. It is ironic to still have it in 2017...
     
    Last edited: Dec 1, 2017
  7. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    172
    Hard to find what adds it without removing things step by step. We have a plugin that added it in by accident.

    However, you can decompile the apk with apktool and remove it then resign/rezip - this is what we do when a plugin etc adds it in by accident. Not ideal but it should be fairly easy to automate this.
     
  8. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    119
    modify UnityChannel.aar
    there is your problem.
    Remove permissions from their manifest

    It's working fine for me
     
    2rusbekov likes this.
  9. Krstn

    Krstn

    Joined:
    Dec 30, 2012
    Posts:
    22
    Where do you find this file? It's not in the project.
    Not really a solution either.
     
  10. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    119




    I dont know why, but in our projects
    from time to time it permeates to AndroidManifest.xml while build for GooglePlay

    PS
    and look instde aapt folder to
     
  11. TinyCarson

    TinyCarson

    Joined:
    Mar 31, 2016
    Posts:
    1
    So, all of a sudden I seem to be running into this issue as well. Every time a build and install the APK file, I get prompted to allow my game to "Make and Manage Phone Calls."

    I have tried removing every instance of 'READ_PHONE_STATE' from every Android Manifest file in the directory. I have gone through and altered all of the Manifest files to have matching minSDK and targetSDKs.

    After I build my project, I can find an instance of 'READ_PHONE_STATE' in the Manifest file under - *\unity\Temp\StagingArea.

    I am at a loss for what to do next. Any help would be greatly appreciated.
     
    mailovi0988 likes this.
  12. Seraphim-Whiteless

    Seraphim-Whiteless

    Joined:
    Jun 23, 2014
    Posts:
    119
    you can remove it permission in main manifest

    <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" />
     
    dis-s likes this.
  13. CrazyPhysics

    CrazyPhysics

    Joined:
    Apr 20, 2017
    Posts:
    1
    Where is the data located? Cant find it..

    Edit:
    Its working with modifying the manifest int "unityChannel" as you descriped! Thanks
     
  14. dis-s

    dis-s

    Joined:
    Mar 25, 2013
    Posts:
    45
    Tried it. Error: "XmlException: 'tools' is undeclared namespace."

    Unity 5.5.5f1. Do you know why this could be happen?
     
  15. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    172
    You'll need to add the bit in bold to your manifest at the top..

    manifest ... xmlns:tools="http://schemas.android.com/tools">
     
  16. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    5,116
    If you are building for Xiaomi and using UnityChannel, this is a permission requirement by Xiaomi.
     
  17. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,282
    I'm getting this permission in my builds today for what appears to be no reason. I don't use Xiaomi. I can't understand it.
     
  18. LightOwl

    LightOwl

    Joined:
    Mar 28, 2017
    Posts:
    15
    Here is a more complete picture of what is going on:

    1. IF Android API level is less than 4* then this permission is added.
    2. Our Unity projects will often have more than one Android Manifest. If one of them does not specify the minimum target, it will assume API 1 which is less than 4. If it thinks you are using something less than 4, this permission is added.
    3. To "fix" the permission prompt you can add 2 lines to your manifest as described here.
    (namespace for tools and a remove line for the phone).
    https://answers.unity.com/questions...phone-state-unity-55.html?childToView=1433985
    4. If however, you are trying to put this on Google Play, and you don't have privacy statement (and don't want one), then the solution above is not for you. what you need to do, is to search for Android Manifest in your project and make sure that every one has a minimum API greater than 4. For example,
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="26" />

    *Note: If you are wondering...what is she talking about API level 1, then please look here...
    http://mobisir.net/android-name-version-api-level/ . In short, you want Android 2.0 and up.
     
    Last edited: May 22, 2018
    halken and Antony-Blackett like this.
  19. posibillian_tech

    posibillian_tech

    Joined:
    Jan 31, 2017
    Posts:
    12
    Just adding this to the main AndroidMannifest solved the problem for me.
     
  20. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,282
    I wouldn’t remove the write and read external storage permissions, instead set their maxSDK to 18 as they are still required for old android versions
     
  21. panShev4enk0

    panShev4enk0

    Joined:
    Dec 7, 2017
    Posts:
    2
    Tere is my problem with this permission:
    I have a project made by unity 4.7.2. Android sdk tools 25.2.3. In all project I have found only 1 AndroidManifest file. Trying to remove the permission, I added the line: <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove"/> , and <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="26" /> and removed SystemInfo.deviceUniqueIdentifier from the codes.


    Fore the more, I searched all project (including archive) the text line READ_PHONE_STATE and found nothing exept the line in my manifest (<uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove"/>)
    But in apk file I see this permission again.


    What should I do to remove it?
     
    Last edited: Jun 11, 2018
  22. dondbui

    dondbui

    Joined:
    Feb 12, 2014
    Posts:
    2
    If you're using a Unity version that supports Android build system internal and Gradle, please use the Gradle one. Internal build jobs do not like the tools:node="remove" Android manifest merge flags. That's what worked for me.
     
  23. panShev4enk0

    panShev4enk0

    Joined:
    Dec 7, 2017
    Posts:
    2
    Unfortuntly, unity 4.7.2 does't support Gradle build system :(
     
  24. halken

    halken

    Joined:
    Mar 11, 2017
    Posts:
    7
    Wow, thank you! Worked for me. Just added this to all manifest files (mine did not specify a version, so it was adding the READ_PHONE_STATE permission):
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28" />
     
  25. Lingcod

    Lingcod

    Joined:
    Nov 30, 2016
    Posts:
    1
    I solved it!

    I tried adding <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove"/> , and adding <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" /> to all the manifest file. They don't work. The READ_PHONE_STATE will still appear in my final manifest.

    Then I tried adding this line to my main manifest file:

    <uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="18" />

    This line means that this permission will only be requested on or under sdk 18. At the same time, my minsdkversion is 19, so actually nobody will be requested for this permission. Note that, if you want to set a maxSdkVersion for READ_PHONE_STATE, it has to be at least 18. Otherwise you can't upload it to google play.
    From this method, this permission won't even appear in players' SETTINGS.

    I think the above solutions won't work for me because there are a lot of codes that actually access SystemInfo. I can't remove them all. No matter what I do to the manifest file, READ_PHONE_STATE will eventually be added in and override previous settings. But by adding maxSdkVersion for that, it became an extra setting and won't be overridden.
     
  26. Avessalom

    Avessalom

    Joined:
    Jul 12, 2016
    Posts:
    7
    upload_2018-10-16_10-48-7.png you need to uncheck android platform
     
  27. Hapkidos

    Hapkidos

    Joined:
    Apr 14, 2014
    Posts:
    4
    Hi everyone. --- WORKED FOR ME!--
    I tried so many things on manifest, which mentioned here and other forums. At the last, I noticed that the error message, The apk upload error message wants to add "Privacy Policy URL" into Store listing / Privacy policy section. (which checked "Not submitting a privacy policy URL at this time"). So, I add my privacy policy URL from my website, then submit. later, I successfully uploaded my apk.
     
  28. angelochu7

    angelochu7

    Joined:
    Nov 14, 2018
    Posts:
    26
    Hi guys!

    I tried everything you guys mentioned but still couldn't eliminate that READ_PHONE_STATE thing.

    Platform: Mac 5.6.6f2
     
  29. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    37
  30. The-Gabo

    The-Gabo

    Joined:
    Feb 25, 2013
    Posts:
    7
    Hi everybody,

    I can't put the update of my game on the android play store because of the READ_PHONE_STATE permission.

    It edited the main manifest, and some of the manifests in UnityChannel

    It's really frustrating :) I didn't have this kind of problem with my previous build and I changed nearly nothing.

    Here's my main manifest :

    upload_2018-12-7_15-16-58.png
     
  31. angelochu7

    angelochu7

    Joined:
    Nov 14, 2018
    Posts:
    26
    Thanks for your suggestion, Slaye.

    I can't seem to find the "Merged Manifest" tab as you specified in your previous post. My screenshot(as below) does not have any tab under the code view.


    Do you have any clue? Please drop me a line.
     
  32. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    37
  33. angelochu7

    angelochu7

    Joined:
    Nov 14, 2018
    Posts:
    26
    Thanks for your reply, Slaye.

    I finally can see the Merge Manifest tab after I fixed the incompatible Gradle version error. Strangely enough, I check the AndroidManifest.xml (there are a few, like 3 files) but they don't mention the PHONE_STATE permission requirement. I am wondering why it's not the case if it's built from the Unity.
     
  34. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    37
    When you are building from Unity, are you using internal or Gradle builds?
     
  35. angelochu7

    angelochu7

    Joined:
    Nov 14, 2018
    Posts:
    26
    I chose "internal" build and it embedded "READ_PHONE_STATE" permission line.
     
  36. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    37
    For consistency, I'd suggest sticking with Gradle builds. IIRC Internal is technically deprecated. I believe that you will get a closer match between Gradle builds and whatever you see with exporting your project.
     
  37. angelochu7

    angelochu7

    Joined:
    Nov 14, 2018
    Posts:
    26
    Thanks for your suggestion, Slaye. I am a newbie in Unity.

    Before, I felt very comfortable with the "internal" build and have no problem. My experience with export project with gradle is terrible because I have to modify file to resolve the gradle version mismatch issue. Moreover, the MethodHandle.invoke error is another issue when I want to export the apk from Android Studio. Is that normal? Do you guys have similar experience? Please do share.
     
  38. GainfulSage

    GainfulSage

    Joined:
    Apr 30, 2015
    Posts:
    37
    I haven't seen either of those issues, sorry. Maybe start a new thread for those and/or check StackOverflow...?
     
  39. angelochu7

    angelochu7

    Joined:
    Nov 14, 2018
    Posts:
    26
    The project was completed by someone else and passed on to me. But I guess they used some 3rd party plugins and it requires certain requirements (e.g. Gradle version,etc). It might be the reason why I got errors from Android Studio.
     
  40. angelochu7

    angelochu7

    Joined:
    Nov 14, 2018
    Posts:
    26
    Slaye, I think that I managed to solve it. It seems that there is only one way round about this, it's export the project in Android Studio.

    By the way, I followed this doc to configure the gradle in Android Studio.
     
    GainfulSage likes this.
  41. tholmgren2017

    tholmgren2017

    Joined:
    Jul 11, 2017
    Posts:
    1
    Thanks for posting... this worked for me using INTERNAL build not GRADLE. I also updated my IAP to the latest version.
     
  42. TheOtherJoJo

    TheOtherJoJo

    Joined:
    Apr 5, 2015
    Posts:
    6
    Removing Xiaomi and UnityChannel from my project is what did it for me.
     
  43. kadenzarowny

    kadenzarowny

    Joined:
    Jun 18, 2019
    Posts:
    5
  44. skdev3

    skdev3

    Joined:
    Jul 15, 2015
    Posts:
    53
    Solved ))) My Post Build script )))
    Code (CSharp):
    1. #if UNITY_ANDROID
    2. using UnityEngine;
    3. using UnityEditor;
    4. using UnityEditor.Build;
    5. using System.IO;
    6. using System.Collections;
    7. using System.Collections.Generic;
    8. using System.Threading;
    9.  
    10. class AndroidManifestFixBuildProcessor : MonoBehaviour, IPostprocessBuild
    11. {
    12.     public int callbackOrder { get { return 1; } }
    13.  
    14.     static string dataPath = "";
    15.     private static Thread _OnPostprocessBuildThread;
    16.  
    17.     public void OnPostprocessBuild(BuildTarget target, string path)
    18.     {
    19.         Debug.Log("OnPostprocessBuild");
    20.         dataPath = Application.dataPath + "/../Temp";
    21.         Application.logMessageReceived += buildLogCallback;
    22.         if (_OnPostprocessBuildThread != null && _OnPostprocessBuildThread.IsAlive)
    23.         {
    24.             _OnPostprocessBuildThread.Interrupt();
    25.             _OnPostprocessBuildThread.Abort();
    26.             _OnPostprocessBuildThread = null;
    27.         }
    28.         _OnPostprocessBuildThread = new Thread(OnPostprocessBuildThread);
    29.         _OnPostprocessBuildThread.Start();
    30.         Debug.Log("Start OnPostprocessBuildThread");
    31.  
    32.     }
    33.  
    34.     private void OnPostprocessBuildThread()
    35.     {
    36.         while (true)
    37.         {
    38.             Debug.Log("Run AndroidManifestFixBuildProcessor");
    39.             AndroidManifestFixBuildProcessor.AndroidManifest(dataPath);
    40.             Thread.Sleep(200);
    41.         }
    42.     }
    43.  
    44.     public static void buildLogCallback(string condition, string stackTrace, LogType type)
    45.     {
    46.         AndroidManifestFixBuildProcessor.AndroidManifest(dataPath);
    47.         if (condition.Contains("Build completed"))
    48.         {
    49.             if (_OnPostprocessBuildThread != null && _OnPostprocessBuildThread.IsAlive)
    50.             {
    51.                 _OnPostprocessBuildThread.Interrupt();
    52.                 _OnPostprocessBuildThread.Abort();
    53.                 _OnPostprocessBuildThread = null;
    54.             }
    55.             Debug.Log("Stop OnPostprocessBuildThread");
    56.             Application.logMessageReceived -= buildLogCallback;
    57.         };
    58.      
    59.     }
    60.     //
    61.  
    62.     public static void AndroidManifestFinished(object sender, FinishedArgs args)
    63.     {
    64.         if (args.LinesRemoved > 0)
    65.         {
    66.             Debug.Log("<color=#FF8000>File:" + args.Filename + " LinesRemoved:" + args.LinesRemoved + " TotalLines:" + args.TotalLines + " </color>");
    67.         }
    68.     }
    69.  
    70.     public static void AndroidManifest(string buildDir)
    71.     {
    72.         List<string> removedParams = new List<string>();
    73.  
    74.         removedParams.Add("android.permission.BLUETOOTH");
    75.         removedParams.Add("android.permission.CHANGE_WIFI_MULTICAST_STATE");
    76.         removedParams.Add("android.permission.READ_PHONE_STATE");
    77.  
    78.         TextLineRemover.OnFinished += AndroidManifestFinished;
    79.      //   Debug.Log(buildDir);
    80.  
    81.         string[] files =  Directory.GetFiles(buildDir, "*.xml", SearchOption.AllDirectories);
    82.         foreach (string file in files)
    83.         {
    84.             string patchfile = Path.GetFullPath(file);
    85.             string TempPath = Path.GetTempPath();
    86.             string patchfileTMP = TempPath + Path.GetFileNameWithoutExtension(file) + ".tmp";
    87.             TextLineRemover.RemoveTextLines(removedParams, patchfile, patchfileTMP);          
    88.         }
    89.         TextLineRemover.OnFinished -= AndroidManifestFinished;
    90.     }
    91. }
    92. /*
    93. public class FixAndroidManifest
    94. {
    95.     [MenuItem("Tools/FixAndroidManifest")]
    96.     static void FixAndroidManifestRun()
    97.     {
    98.         AndroidManifestFixBuildProcessor.AndroidManifest(Application.dataPath + "/../Temp");
    99.     }
    100. }
    101. */
    102.  
    103. public static class TextLineRemover
    104. {
    105.     public static void RemoveTextLines(IList<string> linesToRemove, string filename, string tempFilename)
    106.     {
    107.         // Initial values
    108.         int lineNumber = 0;
    109.         int linesRemoved = 0;
    110.         System.DateTime startTime = System.DateTime.Now;
    111.  
    112.         // Read file
    113.         using (var sr = new StreamReader(filename))
    114.         {
    115.             // Write new file
    116.             using (var sw = new StreamWriter(tempFilename))
    117.             {
    118.                 // Read lines
    119.                 string line;
    120.                 while ((line = sr.ReadLine()) != null)
    121.                 {
    122.                     lineNumber++;
    123.                     // Look for text to remove
    124.                     if (!ContainsString(line, linesToRemove))
    125.                     {
    126.                         // Keep lines that does not match
    127.                         sw.WriteLine(line);
    128.                     }
    129.                     else
    130.                     {
    131.                         // Ignore lines that DO match
    132.                         linesRemoved++;
    133.                         InvokeOnRemovedLine(new RemovedLineArgs { RemovedLine = line, RemovedLineNumber = lineNumber });
    134.                     }
    135.                 }
    136.             }
    137.         }
    138.         // Delete original file
    139.         File.Delete(filename);
    140.  
    141.         // ... and put the temp file in its place.
    142.         File.Move(tempFilename, filename);
    143.  
    144.         // Final calculations
    145.         System.DateTime endTime = System.DateTime.Now;
    146.         InvokeOnFinished(new FinishedArgs { LinesRemoved = linesRemoved, TotalLines = lineNumber, TotalTime = endTime.Subtract(startTime), Filename = filename });
    147.     }
    148.  
    149.     private static bool ContainsString(string line, IEnumerable<string> linesToRemove)
    150.     {
    151.         foreach (var lineToRemove in linesToRemove)
    152.         {
    153.             if (line.Contains(lineToRemove))
    154.                 return true;
    155.         }
    156.         return false;
    157.     }
    158.  
    159.     public static event RemovedLine OnRemovedLine;
    160.     public static event Finished OnFinished;
    161.  
    162.     public static void InvokeOnFinished(FinishedArgs args)
    163.     {
    164.         Finished handler = OnFinished;
    165.         if (handler != null) handler(null, args);
    166.     }
    167.  
    168.     public static void InvokeOnRemovedLine(RemovedLineArgs args)
    169.     {
    170.         RemovedLine handler = OnRemovedLine;
    171.         if (handler != null) handler(null, args);
    172.     }
    173. }
    174.  
    175. public delegate void Finished(object sender, FinishedArgs args);
    176.  
    177. public class FinishedArgs
    178. {
    179.     public int TotalLines { get; set; }
    180.     public int LinesRemoved { get; set; }
    181.     public System.TimeSpan TotalTime { get; set; }
    182.     public string Filename { get; set; }
    183. }
    184.  
    185. public delegate void RemovedLine(object sender, RemovedLineArgs args);
    186.  
    187. public class RemovedLineArgs
    188. {
    189.     public string RemovedLine { get; set; }
    190.     public int RemovedLineNumber { get; set; }
    191. }
    192.  
    193.  
    194. #endif //UNITY_ANDROID
    195.  
     
    Last edited: Aug 16, 2019