-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-webpack): Cordova & Android -> usesCleartextTraffic attribute…
… is always true in the AndroidManifest.xml file #17219
- Loading branch information
1 parent
f4c425f
commit 352e539
Showing
3 changed files
with
37 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fs = require('fs') | ||
const appPaths = require('../app-paths') | ||
|
||
module.exports = function fixAndroidCleartext (action) { | ||
const androidManifestPath = appPaths.resolve.cordova( | ||
'platforms/android/app/src/main/AndroidManifest.xml' | ||
) | ||
|
||
if (fs.existsSync(androidManifestPath) === false) return | ||
|
||
let androidManifest = fs.readFileSync(androidManifestPath, 'utf8') | ||
const hasCleartext = androidManifest.indexOf('android:usesCleartextTraffic="true"') !== -1 | ||
|
||
if (action === 'add') { | ||
if (hasCleartext === false) { | ||
androidManifest = androidManifest.replace( | ||
'<application', | ||
'<application\n android:usesCleartextTraffic="true"' | ||
) | ||
|
||
fs.writeFileSync(androidManifestPath, androidManifest, 'utf-8') | ||
} | ||
|
||
return | ||
} | ||
|
||
// else remove it | ||
if (hasCleartext === true) { | ||
androidManifest = androidManifest.replace( | ||
' android:usesCleartextTraffic="true"\n', | ||
'' | ||
) | ||
|
||
fs.writeFileSync(androidManifestPath, androidManifest, 'utf-8') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.