Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by DevGamePlayGame · Nov 18, 2017 at 01:32 AM · android buildandroid sdkandroid-manifest

[ANDROID] How to remove READ_PHONE_STATE

Hi all, I am currently facing a problem where the android build will ask the user "Allow (Project name) to make and manage phone calls" After doing some Google search, I've tried out following

  • Add <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="25"/> to every androidmanifest.

  • Add <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" />

  • Remove SystemInfo.deviceUniqueIdentifier from the codes.

However, the build still asks for the permission. When I checked the AndroidManifest on temp/StagingArea, the file did NOT include <uses-permission android:name="android.permission.READ_PHONE_STATE" /> Here is my current set up.

  • Unity 5.6.3

  • Android SDK tools version 26.1.1

I am also using following plugins

  • Unity IAP (from the asset store)

  • Facebook SDK version 7.10.1

  • Cross Platform Native Plugins

  • Twitter SDK

  • Firebase Analytics

Please give us any suggestions on how to remove this permission. Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by yasirkula · Feb 27, 2018 at 05:44 PM

There are 3 possible solutions. Here we go:

  1. Add <uses-sdk android:minSdkVersion="5" /> to your AndroidManifest and change the number with your Unity project's "Minimum API Level". If you don't have an AndroidManifest in your project, grab the default one from UNITY_INSTALLATION_PATH\Editor\Data\PlaybackEngines\AndroidPlayer\Apk (or somewhere around here) and copy it to the Assets\Plugins\Android folder of your project

  2. Inside your Android SDK installation path, delete the "tools" folder completely and replace it with version 25.2.3, officially available here: https://dl.google.com/android/repository/tools_r25.2.3-windows.zip (click here for all download options)(this one did the trick for me)

  3. If none works, add <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" /> to your AndroidManifest and build your project using Gradle build system

Credit: https://forum.unity.com/threads/unity-2017-read_phone_state-permission-cant-remove.486732/

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Yury-Habets ♦♦ · Oct 12, 2018 at 08:34 AM 0
Share

Please DON'T downgrade the SD$$anonymous$$ tools to 25.2.3.

avatar image
0

Answer by etig · Jan 15, 2018 at 10:15 AM

Did you solve it?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by DavidSWu · Feb 21, 2018 at 02:25 AM

We are facing a similar problem with 2017.3.1, but we have the line:

In the output file

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by skdev3 · Aug 16, 2019 at 12:03 PM

 #if UNITY_ANDROID
 using UnityEngine;
 using UnityEditor;
 using UnityEditor.Build;
 using System.IO;
 using System.Collections;
 using System.Collections.Generic;
 using System.Threading;
 
 class AndroidManifestFixBuildProcessor : MonoBehaviour, IPostprocessBuild
 {
     public int callbackOrder { get { return 1; } }
 
     static string dataPath = "";
     private static Thread _OnPostprocessBuildThread;
 
     public void OnPostprocessBuild(BuildTarget target, string path)
     {
         Debug.Log("OnPostprocessBuild");
         dataPath = Application.dataPath + "/../Temp";
         Application.logMessageReceived += buildLogCallback;
         if (_OnPostprocessBuildThread != null && _OnPostprocessBuildThread.IsAlive)
         {
             _OnPostprocessBuildThread.Interrupt();
             _OnPostprocessBuildThread.Abort();
             _OnPostprocessBuildThread = null;
         }
         _OnPostprocessBuildThread = new Thread(OnPostprocessBuildThread);
         _OnPostprocessBuildThread.Start();
         Debug.Log("Start OnPostprocessBuildThread");
 
     }
 
     private void OnPostprocessBuildThread()
     {
         while (true)
         {
             Debug.Log("Run AndroidManifestFixBuildProcessor");
             AndroidManifestFixBuildProcessor.AndroidManifest(dataPath);
             Thread.Sleep(200);
         }
     }
 
     public static void buildLogCallback(string condition, string stackTrace, LogType type)
     {
         AndroidManifestFixBuildProcessor.AndroidManifest(dataPath);
         if (condition.Contains("Build completed"))
         {
             if (_OnPostprocessBuildThread != null && _OnPostprocessBuildThread.IsAlive)
             {
                 _OnPostprocessBuildThread.Interrupt();
                 _OnPostprocessBuildThread.Abort();
                 _OnPostprocessBuildThread = null;
             }
             Debug.Log("Stop OnPostprocessBuildThread");
             Application.logMessageReceived -= buildLogCallback;
         };
        
     }
     //  
 
     public static void AndroidManifestFinished(object sender, FinishedArgs args)
     {
         if (args.LinesRemoved > 0)
         {
             Debug.Log("<color=#FF8000>File:" + args.Filename + " LinesRemoved:" + args.LinesRemoved + " TotalLines:" + args.TotalLines + " </color>");
         }
     }
 
     public static void AndroidManifest(string buildDir)
     {
         List<string> removedParams = new List<string>();
 
         removedParams.Add("android.permission.BLUETOOTH");
         removedParams.Add("android.permission.CHANGE_WIFI_MULTICAST_STATE");
         removedParams.Add("android.permission.READ_PHONE_STATE");
 
         TextLineRemover.OnFinished += AndroidManifestFinished;
      //   Debug.Log(buildDir);
 
         string[] files =  Directory.GetFiles(buildDir, "*.xml", SearchOption.AllDirectories);
         foreach (string file in files)
         {
             string patchfile = Path.GetFullPath(file);
             string TempPath = Path.GetTempPath();
             string patchfileTMP = TempPath + Path.GetFileNameWithoutExtension(file) + System.DateTime.Now.ToString() + ".tmp";
             TextLineRemover.RemoveTextLines(removedParams, patchfile, patchfileTMP);           
         }
         TextLineRemover.OnFinished -= AndroidManifestFinished;
     }
 }
 /*
 public class FixAndroidManifest
 {
     [MenuItem("Tools/FixAndroidManifest")]
     static void FixAndroidManifestRun()
     {
         AndroidManifestFixBuildProcessor.AndroidManifest(Application.dataPath + "/../Temp");
     }
 }
 */
 
 public static class TextLineRemover
 {
     public static void RemoveTextLines(IList<string> linesToRemove, string filename, string tempFilename)
     {
         // Initial values
         int lineNumber = 0;
         int linesRemoved = 0;
         System.DateTime startTime = System.DateTime.Now;
 
         // Read file
         using (var sr = new StreamReader(filename))
         {
             // Write new file
             using (var sw = new StreamWriter(tempFilename))
             {
                 // Read lines
                 string line;
                 while ((line = sr.ReadLine()) != null)
                 {
                     lineNumber++;
                     // Look for text to remove
                     if (!ContainsString(line, linesToRemove))
                     {
                         // Keep lines that does not match
                         sw.WriteLine(line);
                     }
                     else
                     {
                         // Ignore lines that DO match
                         linesRemoved++;
                         InvokeOnRemovedLine(new RemovedLineArgs { RemovedLine = line, RemovedLineNumber = lineNumber });
                     }
                 }
             }
         }
         // Delete original file
         File.Delete(filename);
 
         // ... and put the temp file in its place.
         File.Move(tempFilename, filename);
 
         // Final calculations
         System.DateTime endTime = System.DateTime.Now;
         InvokeOnFinished(new FinishedArgs { LinesRemoved = linesRemoved, TotalLines = lineNumber, TotalTime = endTime.Subtract(startTime), Filename = filename });
     }
 
     private static bool ContainsString(string line, IEnumerable<string> linesToRemove)
     {
         foreach (var lineToRemove in linesToRemove)
         {
             if (line.Contains(lineToRemove))
                 return true;
         }
         return false;
     }
 
     public static event RemovedLine OnRemovedLine;
     public static event Finished OnFinished;
 
     public static void InvokeOnFinished(FinishedArgs args)
     {
         Finished handler = OnFinished;
         if (handler != null) handler(null, args);
     }
 
     public static void InvokeOnRemovedLine(RemovedLineArgs args)
     {
         RemovedLine handler = OnRemovedLine;
         if (handler != null) handler(null, args);
     }
 }
 
 public delegate void Finished(object sender, FinishedArgs args);
 
 public class FinishedArgs
 {
     public int TotalLines { get; set; }
     public int LinesRemoved { get; set; }
     public System.TimeSpan TotalTime { get; set; }
     public string Filename { get; set; }
 }
 
 public delegate void RemovedLine(object sender, RemovedLineArgs args);
 
 public class RemovedLineArgs
 {
     public string RemovedLine { get; set; }
     public int RemovedLineNumber { get; set; }
 }
 
 
 #endif //UNITY_ANDROID
 

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

78 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to increase number of supported devices when publishing to the google play store 0 Answers

CommandInvokationFailure: Gradle build failed. unity 2019.4.22 1 Answer

CommandInvokationFailure: Failed to re-package resources. 1 Answer

weird error prevent unity building apk PLZ help 2 Answers

com.android.tools.r8 compilation error please help 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges