react-native run-android : sun.security.provider.cert path.SunCertPathBuilderException : unable to find valid certification path to req uested target

F:\webrowser>react-native run-android
Scanning folders for symlinks in F:\webrowser\node_modules (73ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat install
Debug)...
Downloading https://services.gradle.org/distributions/gradle-4.1-all.zip
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.val
idator.ValidatorException: PKIX path building failed: sun.security.provider.cert
path.SunCertPathBuilderException: unable to find valid certification path to req
uested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302)
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.
java:1514)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.jav
a:216)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1026)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:961)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.
java:1385)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413
)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397
)
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.getInputStream0(HttpURLCo
nnection.java:1564)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Http
sURLConnectionImpl.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:59)
at org.gradle.wrapper.Install$1.call(Install.java:46)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAcc
essManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:46)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:126)
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 vali
d certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:397)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.jav
a:302)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.j
ava:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerIm
pl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustMan
agerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.
java:1496)
... 20 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBu
ilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCert
PathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:392)
... 26 more
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html

Cause

java client try to downloading https resources without valid certification.

Solution

  1. Downloading <a href="http://pwpan.com/fs/4leeng7er4ro9ng0e57/" target="_blank">InstallCert.java</a>
  2. Compile
    javac InstallCert.java
  3. Run InstallCert and get certs from the host.
    my failed resource is
    https://services.gradle.org/distributions/gradle-4.1-all.zip
    the host is services.gradle.org
    java InstallCert services.gradle.org
    If everything works well, you will get a file named jssecacerts.
c:\Users\Administrator\Desktop>java InstallCert services.gradle.org
Loading KeyStore C:\Program Files\Java\jdk1.8.0_152\jre\lib\security\cacerts...
Opening connection to services.gradle.org:443...
Starting SSL handshake...
......
Server sent 3 certificate(s):
1 Subject CN=ssl473435.cloudflaressl.com, OU=PositiveSSL Multi-Domain, OU=Domain Control Validated
Issuer CN=COMODO ECC Domain Validation Secure Server CA 2, O=COMODO CA Limited, L=Salford, ST=Greater Manchester, C=GB
sha1 d4 e8 9d a9 2c 27 22 1f 63 a9 33 d8 ca 98 01 3d 02 6c 59 ea
md5 ba 64 ca 8d 7f ab d8 8e f2 e0 d3 79 79 51 96 30
2 Subject CN=COMODO ECC Domain Validation Secure Server CA 2, O=COMODO CA Limited, L=Salford, ST=Greater Manchester, C=GB
Issuer CN=COMODO ECC Certification Authority, O=COMODO CA Limited, L=Salford, ST=Greater Manchester, C=GB
sha1 75 cf d9 bc 5c ef a1 04 ec c1 08 2d 77 e6 33 92 cc ba 52 91
md5 5e 0e 41 9b 20 ea 57 54 77 f1 1b 52 e2 c8 18 e0
3 Subject CN=COMODO ECC Certification Authority, O=COMODO CA Limited, L=Salford, ST=Greater Manchester, C=GB
Issuer CN=AddTrust External CA Root, OU=AddTrust External TTP Network, O=AddTrust AB, C=SE
sha1 ae 22 3c bf 20 19 1b 40 d7 ff b4 ea 57 01 b6 5f dc 68 a1 ca
md5 c7 90 a5 6c 69 cb af 0b f3 f3 0a 40 d0 a2 ae cc
Enter certificate to add to trusted keystore or 'q' to quit: [1]
1 // enter 1 here
......
Added certificate to keystore 'jssecacerts' using alias 'services.gradle.org-1'
  1. copy jssecacerts to jre security folder
    cp jssecacerts $JAVA_HOME/jre/lib/security/jssecacerts

Issue fiexed

gradle-4.1-all.zip is downloading
downloadinggradle

error: package com.tencent.mm.sdk.openapi does not exist

Task :app:compileReleaseJavaWithJavac
C:\Users\lenger\Desktop\webrowser\android\app\src\main\java\com\wx\react\WeChatModule.java:9: error: package com.tencent.mm.sdk.openapi does not exist
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
^
C:\Users\lenger\Desktop\webrowser\android\app\src\main\java\com\wx\react\WeChatModule.java:11: error: cannot find symbol
public class WeChatModule extends ReactContextBaseJavaModule implements IWXAPIEventHandler {
^
symbol: class IWXAPIEventHandler
2 errors

FAILURE: Build failed with an exception.

solution

com.tencent.mm.sdk ==> com.tencent.mm.opensdk

gradle build : Could not find method compile() for arguments

In build.gradle file add one of the following:
dependencies {
compile 'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+'
}

  • What went wrong:
    A problem occurred evaluating root project 'webrowser'.

Could not find method compile() for arguments [com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Cause

edit wrong android/build.gradle

Solution

edit correct android/app/build.gradle.

install GNU tools via chocolatey for windows

https://chocolatey.org/install
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

choco install -y gnuwin32-coreutils.install choco install  gnuwin32-grep.install -y choco install which -y choco install git -y choco install vim -y 

Capture

C:\Users\lenger>which rm
C:\Program Files (x86)\GnuWin32\bin\rm.exe

C:\Users\lenger>which which
C:\ProgramData\chocolatey\bin\which.exe

C:\Users\lenger>which ls
C:\Program Files (x86)\GnuWin32\bin\ls.exe

C:\Users\lenger>which grep
C:\Program Files (x86)\GnuWin32\bin\grep.exe

C:\Users\lenger>which mv
C:\Program Files (x86)\GnuWin32\bin\mv.exe

C:\Users\lenger>which mkdir
C:\Program Files (x86)\GnuWin32\bin\mkdir.exe

react-native : communicate between react-native JS and WebView component

APIs:

window.postMessage in WebView, post a message to react-native JS.
onMessage callback in react-native JS, receive a message from WebView.
injectjavascript, Function that accepts a string that will be passed to the WebView and executed immediately as JavaScript.
injectedjavascript, Set this to provide JavaScript that will be injected into the web page when the view loads.
onMessage
A function that is invoked when the webview calls window.postMessage. Setting this property will inject a postMessage global into your webview, but will still call pre-existing values of postMessage.
window.postMessage accepts one argument, data, which will be available on the event object, event.nativeEvent.data.

data must be a string.

Sample code

import React, { Component } from 'react';
import {
  Button,
  Platform,
  StyleSheet,
  Text,
  View,
  WebView,
} from 'react-native';

var WEBVIEW_REF = 'webview';

export default class App extends Component<{}> {
  constructor(props) {
    super(props);
    this.onWebViewMessage = this.onWebViewMessage.bind(this);
    this.onShare = this.onShare.bind(this);
  }

  onWebViewMessage(event) {
    console.warn(event.nativeEvent.data);
    let msg;
    try {
      msg = JSON.parse(event.nativeEvent.data);
    } catch (err) {
      console.warn(err);
      return;
    }
    console.log(msg);
  }

  onShare() {
    var fetchAbstractJS = "(" + this.fetchAbstract.toString() + "());";
    console.log(fetchAbstractJS);
    this.refs[WEBVIEW_REF].injectJavaScript(fetchAbstractJS);
  }

  // function called in WebView via injectJavaScript
  fetchAbstract() {
    try {
      var title = document.querySelector('head title').innerText;
      var desc = document.querySelector('p').innerText;
      var imgurl = document.querySelector('p img').src;
      // post Message to react-native JS
      window.postMessage(JSON.stringify({'id' : 'ABSTRACT_FETCHED', 'url' : window.location.href, 'title' : title, 'desc' : desc, 'imgurl' : imgurl}), "*");
    } catch (err) {
      console.warn(err);
      return;
    }
  }

  render() {
    return (
    <View style={{flex:1}}>
      <WebView
        ref={WEBVIEW_REF}
        style={{flex:1}}
        onMessage={this.onWebViewMessage}
        source={{uri: 'https://manna.errong.win/let-s-growing-up-in-jesus/'}}
      />
      <Button
        onPress={this.onShare}
        title="Share"
        color="#841584"
        accessibilityLabel="Social Share"
      />
    </View>
    );
  }
}

react-native log-android

log-android

Refer

https://facebook.github.io/react-native/docs/webview.html#onmessage
https://facebook.github.io/react-native/docs/webview.html#injectjavascript
https://facebook.github.io/react-native/docs/webview.html#injectedjavascript

Let's Growing up in Jesus

看你们学习的工夫,本该作师傅,谁知还得有人将 神圣言小学的开端另教导你们,并且成了那必须吃奶、不能吃干粮的人。 (希伯来书 5:12 和合本)
In fact, though by this time you ought to be teachers, you need someone to teach you the elementary truths of God's word all over again. You need milk, not solid food! (Hebrews 5:12 NIV)
凡只能吃奶的都不熟练仁义的道理,因为他是婴孩; (希伯来书 5:13 和合本)
Anyone who lives on milk, being still an infant, is not acquainted with the teaching about righteousness. (Hebrews 5:13 NIV)
惟独长大成人的才能吃干粮;他们的心窍习练得通达,就能分辨好歹了。 (希伯来书 5:14 和合本)
But solid food is for the mature, who by constant use have trained themselves to distinguish good from evil. (Hebrews 5:14 NIV)


Photo by Milos Prelevic / Unsplash

react-native run-android : Command `run-android` unrecognized

F:\webrowser>react-native run-android
Command run-android unrecognized. Make sure that you have run npm install an
d that you are inside a react-native project.

F:\webrowser>npm install
added 781 packages in 338.768s

fixed: embedded-redis: Unable to run on macOS Sonoma

Issue you might see below error while trying to run embedded-redis for your testing on your macOS after you upgrade to Sonoma. java.la...