Skip to content

Commit 7c034d9

Browse files
committed
Add missing Guide
1 parent 34de6d5 commit 7c034d9

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
id: version-0.5-removing-default-permissions
3+
title: Removing Default Permissions
4+
original_id: removing-default-permissions
5+
---
6+
7+
By default, some permissions are added to your Android APK.
8+
9+
The default permissions that get added are:
10+
11+
* android.permission.INTERNET - Required for debug mode.
12+
* android.permission.SYSTEM_ALERT_WINDOW - Required for debug mode.
13+
* android.permission.READ_PHONE_STATE - Not required for debug or production.
14+
* android.permission.WRITE_EXTERNAL_STORAGE - Not required for debug or production.
15+
* android.permission.READ_EXTERNAL_STORAGE - Not required for debug or production.
16+
17+
1. Let's start by removing `READ_PHONE_STATE`, `WRITE_EXTERNAL_STORAGE`, and `READ_EXTERNAL_STORAGE` from both production and debug APKs, as it is not required in either. These storage permissions are still not needed if `AsyncStorage` module is in use, so it is safe to remove from both production and debug.
18+
2. Open your `android/app/src/main/AndroidManifest.xml` file.
19+
3. Even though these three permissions are not listed in the manifest they get added in. We add the three permissions with `tools:node="remove"` attribute, to make sure it gets removed during build. Note that the package identifier will be different, for below it is "com.myapp" because the project was created with `react-native init myapp`.
20+
21+
```diff
22+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
23+
package="com.myappid"
24+
+ xmlns:tools="http://schemas.android.com/tools"
25+
>
26+
27+
<uses-permission android:name="android.permission.INTERNET" />
28+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
29+
+ <uses-permission tools:node="remove" android:name="android.permission.READ_PHONE_STATE" />
30+
+ <uses-permission tools:node="remove" android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
31+
+ <uses-permission tools:node="remove" android:name="android.permission.READ_EXTERNAL_STORAGE" />
32+
33+
<application
34+
android:name=".MainApplication"
35+
android:label="@string/app_name"
36+
android:icon="@mipmap/ic_launcher"
37+
android:allowBackup="false"
38+
android:theme="@style/AppTheme">
39+
<activity
40+
android:name=".MainActivity"
41+
android:label="@string/app_name"
42+
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
43+
android:windowSoftInputMode="adjustResize">
44+
<intent-filter>
45+
<action android:name="android.intent.action.MAIN" />
46+
<category android:name="android.intent.category.LAUNCHER" />
47+
</intent-filter>
48+
</activity>
49+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
50+
</application>
51+
52+
</manifest>
53+
```
54+
55+
4. Now let's remove `SYSTEM_ALERT_WINDOW` from the production APK only.
56+
5. Go to the `android/app/src/` directory. Create a new directory inside this directory, called `release`. (path: `android/app/src/release/`)
57+
6. Inside this `android/app/src/release/` directory create a `AndroidManifest.xml` file. (path: `android/app/src/release/AndroidManifest.xml`)
58+
7. Inside this file paste the following conents. Note, make sure to update your package identifier from "com.myapp" to what yours is.
59+
60+
```diff
61+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
62+
package="com.myapp"
63+
xmlns:tools="http://schemas.android.com/tools">
64+
65+
<uses-permission tools:node="remove" android:name="android.permission.SYSTEM_ALERT_WINDOW" />
66+
67+
</manifest>
68+
```
69+
70+
That's it. We did not remove the `INTERNET` permission as pretty much all apps use it. Now whenever you create a production APK all these 4 permissions will be removed. When you create a debug APK (`react-native run-android`) it will install the APK with only the three permissions removed, and `SYSTEM_ALERT_WINDOW` will remain.

0 commit comments

Comments
 (0)