【问题标题】:How to solve error "Unable to find valid certification path to requested target while executing command react-native run-android"如何解决错误“执行命令 react-native run-android 时无法找到请求目标的有效认证路径”
【发布时间】:2019-03-21 16:40:17
【问题描述】:

我对 React Native 完全陌生 我使用以下命令在 React Native 中创建了第一个项目:

  1. react-native init 你好
  2. cd 你好
  3. npm 开始
  4. react-native run-android

但在执行 "react-native run-android" 时出现此错误-

Error message screenshot

请帮帮我。

After more efforts this error was resolved but now getting another error

Solutions which I have tried was:
Solution 1:
1. Open your project in Android Studio i.e. android folder of your react native project 
2. Sync your project so that gradle.zip will download properly
3. Then run your project.

Solution 2:
1. Open your React native project
2. Navigate to android folder within it
3. Go to gradle folder inside it 
4. Open gradle-wrapper.properties
5. And modify your distributionUrl from "https" to "http"
6. Run your project

But at the end another error was occurred which was mentioned below.

>react-native run-android
info Starting JS server...
info Building and installing the app on the device (cd android && gradlew.bat ap
p:installDebug)...
Picked up _JAVA_OPTIONS: -Xmx1024M

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'FirstApp'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.21.
     Required by:
         project : > com.android.tools.build:gradle:3.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.bu
ild:builder:3.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.an
alytics-library:shared:26.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.li
nt:lint-gradle-api:26.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.bu
ild:gradle-api:3.3.2
         project : > com.android.tools.build:gradle:3.3.2 > androidx.databinding
:databinding-compiler-common:3.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.bu
ild:builder:3.3.2 > com.android.tools:sdk-common:26.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.bu
ild:builder:3.3.2 > com.android.tools:common:26.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.bu
ild:builder:3.3.2 > com.android.tools.build:manifest-merger:26.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.bu
ild:builder:3.3.2 > com.android.tools.analytics-library:tracker:26.3.2
         project : > com.android.tools.build:gradle:3.3.2 > com.android.tools.bu
ild:builder:3.3.2 > com.android.tools:sdklib:26.3.2 > com.android.tools:reposito
ry:26.3.2
      > Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.21.
         > Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kot
lin/kotlin-stdlib-jdk8/1.3.21/kotlin-stdlib-jdk8-1.3.21.pom'.
            > Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/ko
tlin-stdlib-jdk8/1.3.21/kotlin-stdlib-jdk8-1.3.21.pom'.
               > sun.security.validator.ValidatorException: PKIX path building f
ailed: sun.security.provider.certpath.SunCertPathBuilderException: unable to fin
d valid certification path to requested target
      > Could not resolve org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.21.
         > Could not get resource 'https://dl.google.com/dl/android/maven2/org/j
etbrains/kotlin/kotlin-stdlib-jdk8/1.3.21/kotlin-stdlib-jdk8-1.3.21.pom'.
            > Could not GET 'https://dl.google.com/dl/android/maven2/org/jetbrai
ns/kotlin/kotlin-stdlib-jdk8/1.3.21/kotlin-stdlib-jdk8-1.3.21.pom'.
               > sun.security.validator.ValidatorException: PKIX path building f
ailed: sun.security.provider.certpath.SunCertPathBuilderException: unable to fin
d valid certification path to requested target

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 13s
error 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/getting-started.html
error Command failed: gradlew.bat app:installDebug

我正在我的手机中执行我的项目我已经使用命令“adb devices”检查了我的设备是否正确连接。显示了我的设备名称。

所以我不明白接下来要做什么。


I was trying to solve this error and got a solution which i have implemented 
1. Open your react native project in android studio
2. File -> Settings -> Remote Jar Repositories -> Click on Add Button 
3. Add maven Repository URL given below:
 https://mvnrepository.com/artifact/com.android.tools/sdklib
4. Sync your project 
Many error was gone. 

只想帮助解决以下提到的这些错误:

* What went wrong:
A problem occurred configuring root project 'FirstApp'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not download bcpkix-jdk15on.jar (org.bouncycastle:bcpkix-jdk15on:1.56
)
      > Could not get resource 'https://jcenter.bintray.com/org/bouncycastle/bcp
kix-jdk15on/1.56/bcpkix-jdk15on-1.56.jar'.
         > Could not HEAD 'https://jcenter.bintray.com/org/bouncycastle/bcpkix-j
dk15on/1.56/bcpkix-jdk15on-1.56.jar'.
            > sun.security.validator.ValidatorException: PKIX path building fail
ed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find v
alid certification path to requested target

提前致谢!

【问题讨论】:

  • 如果您不包含屏幕截图,而是将错误消息作为文本包含在内,将会很有帮助。
  • 您是否使用代理或网络调试工具(如 charles 或 fiddler)?如果是这样,请禁用它或确保代理服务器具有有效的证书。

标签: android react-native maven android-studio visual-studio-code


【解决方案1】:

经过一番努力,我得到了对我有用的解决方案。

解决方案:

Step 1:

Open (Project Level) gradle file and add repositories given below:

repositories {
        google()
        mavenCentral()
        jcenter { url "https://jcenter.bintray.com/"}
    }

    allprojects {
    repositories {
        google()
        mavenCentral()
        maven {
            url "https://maven.google.com"
        }
        jcenter { url "https://jcenter.bintray.com/"}
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed 
     from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

Step 2: change directory to android i.e. cd android
        Example: Here, my project name was FirstApp so the path was 
        C:\Users\HOME\Desktop\FirstApp
        and then change directory: cd android 
        So that the path become look like this :  C:\Users\HOME\Desktop\FirstApp\android

Step 3: Refresh dependencies i.e. sync your gradle with the following command
        gradlew build --refresh-dependencies

Step 4: cd..

Step 5: Execute your react native project 
        react-native run-android

Hope, it will work to others also :)

【讨论】:

  • ./gradlew build --refresh-dependencies
猜你喜欢
  • 2019-02-20
  • 1970-01-01
  • 2021-12-04
  • 2017-10-26
  • 2014-12-29
  • 1970-01-01
  • 1970-01-01
  • 2015-02-13
  • 2019-10-15
相关资源
最近更新 更多