Skip to content

Commit

Permalink
fix(app-webpack): Cordova & Android -> usesCleartextTraffic attribute…
Browse files Browse the repository at this point in the history
… is always true in the AndroidManifest.xml file #17219
  • Loading branch information
rstoenescu committed Sep 19, 2024
1 parent f4c425f commit 352e539
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
36 changes: 36 additions & 0 deletions app-webpack/lib/cordova/android-cleartext.js
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')
}
}
2 changes: 1 addition & 1 deletion app-webpack/lib/cordova/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CordovaRunner {
this.target = ctx.targetName

if (this.target === 'android') {
require('../helpers/fix-android-cleartext')('cordova')
require('./android-cleartext')(this.ctx.dev ? 'add' : 'remove')
}
}

Expand Down
24 changes: 0 additions & 24 deletions app-webpack/lib/helpers/fix-android-cleartext.js

This file was deleted.

0 comments on commit 352e539

Please sign in to comment.