Android Studio 错误连接 - 反应原生?
Posted
技术标签:
【中文标题】Android Studio 错误连接 - 反应原生?【英文标题】:Android Studio error connection - react native? 【发布时间】:2021-10-25 09:34:09 【问题描述】:我有应用程序并想在 M1 中构建(也许它们有问题) 所以运行后 npx react-native run-android
我收到了这个错误
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'orderApp'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:4.1.2.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:4.1.2.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.2/gradle-4.1.2.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.2/gradle-4.1.2.pom'.
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not resolve com.android.tools.build:gradle:4.1.2.
> Could not get resource 'https://maven.google.com/com/android/tools/build/gradle/4.1.2/gradle-4.1.2.pom'.
> Could not GET 'https://maven.google.com/com/android/tools/build/gradle/4.1.2/gradle-4.1.2.pom'.
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not resolve com.google.gms:google-services:4.3.0.
Required by:
project :
> Could not resolve com.google.gms:google-services:4.3.0.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.0/google-services-4.3.0.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/google/gms/google-services/4.3.0/google-services-4.3.0.pom'.
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
> Could not resolve com.google.gms:google-services:4.3.0.
> Could not get resource 'https://maven.google.com/com/google/gms/google-services/4.3.0/google-services-4.3.0.pom'.
> Could not GET 'https://maven.google.com/com/google/gms/google-services/4.3.0/google-services-4.3.0.pom'.
> PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我的互联网连接很好!
Build.gradle 文件'根文件'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
ext
buildToolsVersion = "30.0.0"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
supportLibVersion = "28.0.0"
repositories
google()
jcenter()
maven url "https://maven.google.com"
mavenCentral()
dependencies
classpath('com.android.tools.build:gradle:4.1.2')
classpath('com.google.gms:google-services:4.3.0')
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
allprojects
repositories
mavenLocal()
maven
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
maven
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
google()
jcenter()
maven url 'https://www.jitpack.io'
maven url "https://maven.google.com"
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
app/build.gradle
buildscript
repositories
gradlePluginPortal()
dependencies
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
import com.android.build.OutputFile
project.ext.react = [
enableHermes: true, // clean and rebuild if changing
]
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);
android
// ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
defaultConfig
applicationId "com.toot.pos"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 2
versionName "1.0"
multiDexEnabled true
splits
abi
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
signingConfigs
debug
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
release
if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE'))
storeFile file(MYAPP_UPLOAD_STORE_FILE)
storePassword MYAPP_UPLOAD_STORE_PASSWORD
keyAlias MYAPP_UPLOAD_KEY_ALIAS
keyPassword MYAPP_UPLOAD_KEY_PASSWORD
buildTypes
debug
signingConfig signingConfigs.debug
release
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
// applicationVariants are e.g. debug, release
applicationVariants.all variant ->
variant.outputs.each output ->
// For each separate APK per architecture, set a unique version code as described here:
// https://developer.android.com/studio/build/configure-apk-splits.html
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) // null for the universal-debug, universal-release variants
output.versionCodeOverride =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
dependencies
implementation 'com.google.firebase:firebase-messaging:20.0.0'
implementation project(':react-native-pusher-push-notifications')
implementation 'com.pusher:push-notifications-android:1.4.4'
implementation fileTree(dir: "libs", include: ["*.jar"])
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation(project(':react-native-maps'))
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
implementation 'com.google.android.gms:play-services-base:17.2.1'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
debugImplementation("com.facebook.flipper:flipper:$FLIPPER_VERSION")
exclude group:'com.facebook.fbjni'
debugImplementation("com.facebook.flipper:flipper-network-plugin:$FLIPPER_VERSION")
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:$FLIPPER_VERSION")
exclude group:'com.facebook.flipper'
if (enableHermes)
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
else
implementation jscFlavor
task copyDownloadableDepsToLibs(type: Copy)
from configurations.compile
into 'libs'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Android Studio 网络设置
【问题讨论】:
你能在 Terminal.app 中curl https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.2/gradle-4.1.2.pom
吗?
我得到了一些xml代码,我猜是@serv-inc
也许***.com/questions/60720241/… 有帮助?
遗憾的是没有 :( @serv-inc
1.你试过更新gradle吗
【参考方案1】:
找出你的第一个错误
无法解析配置“:classpath”的所有工件。 无法解析 com.android.tools.build:gradle:4.1.2。
你可以下载
https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.1.2/gradle-4.1.2.pom
表示代理可能有问题。
顺便说一句,你可以删除你已经使用的maven url "https://maven.google.com"
google()
1。主目录
请检查主目录中的~/.gradle/gradle.properties
2。项目目录
gradle.properties
来自项目目录
【讨论】:
以上是关于Android Studio 错误连接 - 反应原生?的主要内容,如果未能解决你的问题,请参考以下文章
原Sql Server 2008---安装时卸载Visual Studio
React Native,Android Studio,JDBC,MySql - 拒绝访问用户'root'@'ipaddress'