Open esleybonomo opened 2 weeks ago
I found solution.
My suggestion is to include this in the lib in some way, so you don't need to create a plugin to change the AndroidManifest and do the prebuild generating the android and ios folders.
File plugins/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">192.168.0.1</domain>
</domain-config>
</network-security-config>
File plugins/network_security_config.js
const {AndroidConfig, withAndroidManifest } = require('@expo/config-plugins');
const {Paths} = require('@expo/config-plugins/build/android');
const path = require('path');
const fs = require('fs');
const fsPromises = fs.promises;
const { getMainApplicationOrThrow} = AndroidConfig.Manifest
const networkConfig = config => {
return withAndroidManifest(config, async config => {
config.modResults = await setCustomConfigAsync(config, config.modResults);
return config;
});
}
async function setCustomConfigAsync(
config,
androidManifest
) {
const src_file_pat = path.join(__dirname, "network_security_config.xml");
const res_file_path = path.join(await Paths.getResourceFolderAsync(config.modRequest.projectRoot),
"xml", "network_security_config.xml");
const res_dir = path.resolve(res_file_path, "..");
if (!fs.existsSync(res_dir)) {
await fsPromises.mkdir(res_dir);
}
try {
await fsPromises.copyFile(src_file_pat, res_file_path);
} catch (e) {
throw e;
}
const mainApplication = getMainApplicationOrThrow(androidManifest);
mainApplication.$["android:networkSecurityConfig"] = "@xml/network_security_config";
return androidManifest;
}
module.exports = networkConfig;
And in app.json include it:
"plugins": [
"./plugins/network_security_config.js"
],
And it's important run npx expo prebuild --no-install
refs:
I have a project that connects WiFi to an IoT device, generating the APK in --dev-client mode, everything works perfectly, however when I generate the APK for testing in QA, it doesn't work, it seems to create a second network and it doesn't connect to the available.
I created WIfiManager.js
Can anyone help me identify where my error is?