I have developed a app using ionic 5.
http requests are working fine in browser. But not working after build apk.
it shows this error message
[ERROR:ssl_client_socket_impl.cc(960)] handshake failed; returned -1, SSL error code 1, net_error -202
i have code like this:
getCategories(){
return new Promise((resolve,reject)=>{
this.http.get(`${environment.apiUrl}/categories/list`).subscribe((res:any)=>{
resolve(res);
},(err)=>{
reject(err);
})
})
}
Please help me to fix this issue.
Google has updated their policy after android 8. After android 8 it will not allow you to use the HTTP as a api call you will have to use HTTPS in case you want to use.
Please see the below link this may help.
https://medium.com/#mountainappstudio/api-not-running-on-android-oreo-8-0-or-higher-version-problem-solved-ded5cc614d5e
network_security_config.xml add this file in resources/android/xml/ folder
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain>your domain</domain>
<domain includeSubdomains="true">localhost</domain>
</domain-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
Add below code in config.xml
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:networkSecurityConfig="#xml/network_security_config" />
</edit-config>
<resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
Related
I have problem with network_security_config. I google it many hours but nothing changed
added these lines to AndroidManifest.xml:
<application
android:usesCleartextTraffic="true"
android:networkSecurityConfig="#xml/network_security_config"
android:label="divar"
android:name="${applicationName}"
android:icon="#mipmap/ic_launcher">
<uses-library android:name="org.apache.http.legacy" android:required="false"/>
and createdxml folder in this path \android\app\src\main\xml and created network_security_config.xml inside it.
here its code:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>
it shows me this error:
E:\code\onlineShop\build\app\intermediates\packaged_manifests\debug\AndroidManifest.xml:19: AAPT: error: resource xml/network_security_config (aka com.lajward.divar:xml/network_security_config) not found.
I have already enabled cors in my rest API. I can succesfully make a request in my browser, but when i run my application in android studio using this command "ionic cap run android --livereload --external", i cannot get any response from my api. when checking the console i got below error "net: ERR_CONNECTION_REFUSED"
console error
If you want to test your app on Android Studio and your API is running on localhost, you need to send requests to 10.0.2.2 instead of localhost. In your case, instead of using the base API URL http://localhost:3000 in your Ionic app, use http://10.0.2.2:3000.
Next, add android:networkSecurityConfig="#xml/network_security_config" to the application element in the AndroidManifest.xml file:
<application
android:networkSecurityConfig="#xml/network_security_config"
You will need your IPv4 Address. Open Command Prompt, enter ipconfig and take note of the IPv4 Address.
Create a file named network_security_config.xml in the path android\app\src\main\res\xml and replace ipv4address with your IPv4 Address:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">ipv4address</domain>
</domain-config>
</network-security-config>
Finally, run your app with the following command:
ionic cap run android -l --host=0.0.0.0
Source: https://developer.android.com/studio/run/emulator-networking.html
You have to set android:usecleartexttraffic attributes in the config.xml.
<platform name="android">
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
<application android:networkSecurityConfig="#xml/network_security_config" />
<application android:usesCleartextTraffic="true" />
</edit-config>
...
</platform>
Also, you have to add subDomains of RestAPI in network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">localhost</domain>
<domain includeSubdomains="true">127.0.0.1</domain>
</domain-config>
</network-security-config>
The method http.post works on the emulator, but when I run this on real android phone it doesn't work.
Android permission already added.
Main AndroidManifest.xml :
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.niceapp">
<uses-permission android:name="android.permission.INTERNET"/>..
...
...
What could be the problem?
it may be because you are using localhost. check your url and the network you are in.
Try adding this lines:
<application
...
android:networkSecurityConfig="#xml/network_security_config"
android:usesCleartextTraffic="true"
...
This part is optional:
create new folder in res as Android Resource Directory and resource type as xml from dropdown.
add new xml resource file named as "network_security_config"
put this line inside "network_security_config.xml"
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">your url</domain>
</domain-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
Happy coding :D
I have implemented webView in flutter but it is not opening my php website which is on server what I'm doing wrong.
I am new to flutter and tried webview to integrate my website webpage in my application but no luck.
Widget build(BuildContext context) {
// TODO: implement build
return WebviewScaffold(
appBar: AppBar(iconTheme:IconThemeData(color: Colors.white),title: Text("Intake Form",style:new TextStyle(color: Colors.white,fontWeight: FontWeight.bold)),backgroundColor:Colors.indigoAccent,automaticallyImplyLeading: false),
url: url,
//url: "http://xxxxxxxx/",
withJavascript: true,
supportMultipleWindows: true,
withLocalStorage: true,
allowFileURLs: true,
enableAppScheme: true,
appCacheEnabled: true,
hidden: false,
scrollBar: true,
geolocationEnabled: false,
clearCookies: true,
// usesCleartextTraffic="true"
);
}
I expect the output as running webview but error is thrown.
In main directory of your Flutter project you have three main folders:
- lib = your Dart code
- ios = generated structure for iOS platform
- android = generated structure for Android platform
We are interested in android directory.
When you open it, you will see "typical Android app structure".
So you have to do 2 things:
1) Add new file in res
Go to directory:
my_flutter_project/android/app/src/main/res/
Create xml directory (in res!)
And inside xml add new file with name: network_security_config.xml and content:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
</network-security-config>
network_security_config.xml should be located in path:
my_flutter_project/android/app/src/main/res/xml/network_security_config.xml
Here you can find more information about this file:
https://developer.android.com/training/articles/security-config
2) Modify AndroidManifest.xml
Go to:
flutter_project/android/app/src/main/AndroidManifest.xml
AndroidManifest.xml is XML file, with structure:
<manifest>
<application>
<activity>
...
</activity>
<meta-data >
</application>
</manifest>
So for <application> PROPERTIES you have to add 1 line:
android:networkSecurityConfig="#xml/network_security_config"
Remember that you have to add it as property (inside application opening tag):
<application
SOMEWHERE HERE IS OK
>
Not as a tag:
<application> <--- opening tag
HERE IS WRONG!!!!
<application/> <--- closing tag
set usesCleartextTraffic property to true in your AndroidManifest file, like below.
<application
....
android:usesCleartextTraffic="true"
....>
Android:
In flutter_project/android/app/src/main/AndroidManifest.xml
Add
<application
....
android:usesCleartextTraffic="true"
....>
IOS:
In flutter_project/ios/Runner/info.plist
Add
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run flutter clean.Then, run the app.
For ios modify info.plist ./ios/Runner/info.plist
Add the following:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
and run flutter clean before spinning up the app again
make network_security_config.xml file.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
</network-security-config>
add this two line in Manifest file in Application tag.
Getting attribute parallel with value none must have a value from the list "false methods tests class" error on my XML in Eclipse. I am stuck because of this error.
Please help.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite Name" parallel="none">
I did try changing value of parallel to "false", however issue still occurs.
Changed code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite Name" parallel="false">
See this, i dont have any issue
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" preserve-order="true" parallel="false">
<test name="Test1">
<classes>
<class name="com.test.Test1"/>
<class name="com.test.Test2"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Just try by delete and typing again or you can use ctrl+space by typing few chars
Thank You,
Murali
Try with https, replacing "http://testng.org/testng-1.0.dtd" with "https://testng.org/testng-1.0.dtd"