Reputation: 133
android studio version 3.6.3
i've just at my first steps learning flutter over Android studio
fluter doctor -v output is OK:
[✓] Flutter (Channel stable, v1.17.0, on Mac OS X 10.15.3 19D76, locale en-IL)
• Flutter version 1.17.0 at /Users/haims/flutter
• Framework revision e6b34c2b5c (2 weeks ago), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/haims/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• ANDROID_HOME = /Users/haims/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4.1, Build version 11E503a
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.1.1
• Dart plugin version 192.8052
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• No issues found!
but when I run the flutter_app example over Android Emulator this exception thrown and struggling so much time with no fix to that problem,
exception output:
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path
building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1946)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:316)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:310)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1639)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:223)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1037)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:965)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1064)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2729)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2641)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1824)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.wrapper.Install$1.call(Install.java:61)
at org.gradle.wrapper.Install$1.call(Install.java:48)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:48)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:397)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:302)
at sun.security.validator.Validator.validate(Validator.java:262)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1621)
... 22 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:392)
... 28 more
Exception: Gradle task assembleDebug failed with exit code 1
I'll be so thankful for who's solve it and be able start coding with dart, cause right now more then a week struggling with trubleshoow with no single code writing
*on iOS simulator the flutter_app run with no problem.
thanks in advance!
Upvotes: 4
Views: 6755
Reputation: 1
Make sure you disconnected any VPN
open your android folder in the project individually in the android studio as a android project by clicking file -> open Like
Wait until it will download necessary files and run the project
Then simultaneously again open the flutter project in new window and run it
Hope it resolve that issue
Upvotes: 0
Reputation: 1185
Facing same issue but solved by adding my org certificate in cacerts file.
Steps:
Note down cacerts file location. It may located at C:\Program File\Android Studio\jre\lib\security\cacerts
Get your org certificate (.cer file) from your network/security team and Note down its path example C:\Desktop\my_org.cer
Check if keytool command work in terminal/cmd or not. If not then locate keytool in C:\Program Files\Android\Android Studio\jre\bin\keytool and set path upto \bin in Environment Variable
Open cmd/terminal as Administrator and run following command
keytool -importcert -file C:\Desktop\my_org.cer -alias aliasname -keystore "C:\Program File\Android Studio\jre\lib\security\cacerts"
Note: aliasname can be any text which you want to use.
It will ask you for password and enter password changeit
It will ask you the certificate being added is trusted or not and enter Y
Once your certificate is added your error will be removed.
Upvotes: 0
Reputation: 153
Flutter uses gradlew to build the project and you have self signed certificate, probably provided by your company caused the issue.
First of all, try create a plain android project and build from your machine simply using gradle. This is to test out if without using gradlew, you can build the project fine.
Copy the cacerts used by the gradle JVM located under [JAVA_HOME]/jre/lib/security
Pass it to the gradlew by adding the following to the gradle.properties in your flutter project:
systemProp.javax.net.ssl.trustStore=[PATH_TO_TRUST_STORE]
systemProp.javax.net.ssl.trustStorePassword=[PASSWORD] (by default changeit)
To add a certificate to the trust store, you can use the keytool command, for example:
keytool -import -alias [ALIAS] -file [CERT_FILE] -keystore [TRUST_STORE]
[UPDATE] As tested out from Flutter 2.10, it is no longer need to define those properties in gradle.properties. But only need to make sure the CA certs are imported to your java keystore.
Upvotes: 1
Reputation: 41
it's interested with gradle-wrapper.properties. Probably cannot download the latest gradle file from distribution url Please check your internet permissions.
try change https to http distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
Upvotes: 4
Reputation: 81
Looking at your error "unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)" there could be one of several issues, that all can be fixed most likely by adding a network_security_config.xml to your project and reference it in your manifest.xml.
If you are connecting to a HTTPS-server that uses a self signed certificate or requires intermediate certificates you need to add the CA certificate to your app and specify it in the XML or you can configure your app to also trust user-installed certificates and install the certificate manually on your device.
The optioons are explained on https://developer.android.com/training/articles/security-config
If you want to trust user installed certificates, add the following xml to your app:
<?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>
In general iOS is less picky about it. Remember to add the xml to the Android sub project, not the Flutter project!
Upvotes: 0