react-native : Native Modules, name prefix "RCT"works for android too

I tried to export wechat sdk as a native module.
I copied some codes here:
public class WeChatModule extends ReactContextBaseJavaModule implements IWXAPIEventHandler {
  private String appId; 
  public WeChatModule(ReactApplicationContext context) { 
    super(context); 
  @Override     public String getName() { 
    return "RCTWeChat"; 
} 
I used "RCTWeChat" as the module name, I did not know the "RCT" prefix meanings.

ReactContextBaseJavaModule requires that a method called getName is implemented. The purpose of this method is to return the string name of the NativeModule which represents this class in JavaScript.

Then I encountered error in my react-native JS codes.
import {NativeModules} from 'react-native'; const { RCTWeChat } = NativeModules; 
WeChat or NativeModules.RCTWeChat always undefined.

Cause

RCT is a prefix used in react native, it will be removed when exported to JS.
React Native uses RCT as a prefix. In order to avoid name collisions, we recommend using a three-letter prefix other than RCT in your own classes.

Solution

The correct JS codes:
const { WeChat } = NativeModules;

react-native run-android : No connected devices!

  • What went wrong:
    Execution failed for task ':app:installDebug'.

com.android.builder.testing.api.DeviceException: No connected devices!

Cause

ADB driver is not ready

Solution

Install correct driver
adb

Search the heart and Examine the mind

我—耶和华是鉴察人心、试验人肺腑的,要照各人所行的和他作事的结果报应他。 (耶利米书 17:10 和合本)
"I the Lord search the heart and examine the mind, to reward each person according to their conduct, according to what their deeds deserve." (Jeremiah 17:10 NIV)


Photo by Max Bender / Unsplash

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

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...