[英]Getting error while running `react-native run-android`
Whle running my react native code react-native run-android
getting below error.在运行我的本机代码
react-native run-android
出现错误。 It was working proper.它工作正常。 But after taking fresh pull from git and
npm ci
and after I am running then getting this error.但是在从 git 和
npm ci
提取新的 pull 之后,在我运行之后然后得到这个错误。
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (30) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-29).
Dependency: androidx.core:core:1.7.0-alpha01.
AAR metadata file: C:\Users\gauraab\.gradle\caches\transforms-2\files-2.1\9e02d64f5889006a671d0a7165c73e72\core-1.7.0-alpha01\META-INF\com\android\build\gradle\aar-metadata.properties.
As some has mentioned, the problem is that the RN build automatically "upgraded" to androidx.core:core:1.7.0-alpha01, which depends on SDK version 30.正如一些人提到的,问题是 RN 构建会自动“升级”到 androidx.core:core:1.7.0-alpha01,这取决于 SDK 版本 30。
The fix is simply to specify android core version via androidXCore in build.gradle修复只是通过 build.gradle 中的 androidXCore 指定 android 核心版本
buildscript {
ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 23
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
kotlin_version = "1.5.0"
androidXCore = "1.5.0"
}
Figuring this out was painful.弄清楚这一点很痛苦。 I grepped for gradle files that would automatically upgrade packages like so
我搜索了 gradle 文件,这些文件会像这样自动升级包
find . -name '*.gradle' -exec grep -H "\.+" {} \;
and found in node_modules/@react-native-community/netinfo/android/build.gradle
the following snippet并在
node_modules/@react-native-community/netinfo/android/build.gradle
找到以下代码段
def androidXCore = getExtOrInitialValue('androidXCore', null)
if (supportLibVersion && androidXVersion == null && androidXCore == null) {
implementation "com.android.support:appcompat-v7:$supportLibVersion"
} else {
def defaultAndroidXVersion = "1.+"
if (androidXCore == null) {
androidXCore = androidXVersion == null ? defaultAndroidXVersion : androidXVersion
}
implementation "androidx.core:core:$androidXCore"
}
}
I got same issue.我有同样的问题。 Just today.
就是今天。 When I try to run locally, I got the exact same error.
当我尝试在本地运行时,我得到了完全相同的错误。 To get it run again, I update the field
compileSdkVersion
and targetSdkVersion
in file android > build.gradle from 29 to 30. Then, it can run again.为了让它再次运行,我将文件 android > build.gradle 中的
compileSdkVersion
和targetSdkVersion
字段从 29 更新到 30。然后,它可以再次运行。 If this answer fits with you, you can go with this way.如果这个答案适合您,您可以采用这种方式。 But, personally, I'm lookin for solution without to change the value
compileSdkVersion
and targetSdkVersion
但是,就我个人而言,我正在寻找不改变
compileSdkVersion
和targetSdkVersion
值的解决方案
Update: just change the compileSdkVersion
更新:只需更改
compileSdkVersion
Apparently they just broke this today.显然他们今天刚刚打破了这个。
You can fix it by adding the following line to your app level build.gradle file (above the android { }
block as a sibling):您可以通过将以下行添加到您的应用程序级 build.gradle 文件(作为兄弟的
android { }
块上方)来修复它:
configurations.all {
resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
}
Finally, the Gradle build was successfully completed.最后,Gradle 构建成功完成。 Ref.
参考https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
Here is a screenshot of what I have done and it's run perfectly.这是我所做的事情的屏幕截图,它运行完美。 change these lines from
将这些行从
compileSdkVersion = 29
targetSdkVersion = 29
to至
compileSdkVersion = 30
targetSdkVersion = 30
and also change this line from并将这一行从
implementation 'androidx.appcompat:appcompat:1.+'
to implementation 'androidx.appcompat:appcompat:1.3.0'实施'androidx.appcompat:程序兼容性:1.3.0'
The issue was just what I guessed.这个问题正是我的猜测。 So, some updates to a minor version/patch version of an android dependency caused all this today.
因此,今天对 android 依赖项的次要版本/补丁版本的一些更新导致了这一切。
To solve this, for the dependencies in your build.gradle
file, if you have specified it to take the latest minor/patch version every time you build it, make it take an exact stable version.为了解决这个问题,对于
build.gradle
文件中的依赖build.gradle
,如果您已将其指定为每次构建时采用最新的次要/补丁版本,请使其采用完全稳定的版本。
For example, my appcompact dependecy was,例如,我的 appcompact 依赖是,
implementation "androidx.appcompat:appcompat:1.+
This means that it can update to 1.2.x or 1.3.x etc.. as and when such version updates get published.这意味着它可以更新到 1.2.x 或 1.3.x 等。当此类版本更新发布时。 I changed this to depend on an exact stable version like below,
我将其更改为依赖于如下所示的确切稳定版本,
implementation "androidx.appcompat:appcompat:1.3.0"
Hopefully, this solves the issue for everyone.希望这可以解决每个人的问题。
For me the issue is caused by react-native-netinfo
's old version 4.0.0
which was configured to automatically pick up the latest published package of androidx.core
... So in that case it did I realized androidx.core.core-1.7.0-alpha01
had been published right as the issue started occurring.对我来说,这个问题是由
react-native-netinfo
的旧version 4.0.0
,它被配置为自动获取最新发布的androidx.core
包......所以在这种情况下,我意识到了androidx.core.core-1.7.0-alpha01
已在问题开始发生时发布。
So to fix that I updated my react-native-netinfo
package from 4.0.0
to 6.0.0
and this issue was resolved for me.所以为了解决这个问题,我将我的
react-native-netinfo
包从4.0.0
到6.0.0
,这个问题已经为我解决了。
I just change compileSdkVersion=29 to compileSdkVersion=30 and my issue solved .我只是将 compileSdkVersion=29 更改为 compileSdkVersion=30 并且我的问题解决了。 Its working
它的工作
Observing the same core library dependency is causing Gradle build issues for all.观察到相同的核心库依赖会导致所有的 Gradle 构建问题。
Also, clean project
or Invalidate Caches/Restart...
options wouldn't help here.此外,
clean project
或Invalidate Caches/Restart...
选项在这里也无济于事。
Affecting dependency:
'androidx.core:core-ktx:1.7.0-alpha01'
影响依赖:
'androidx.core:core-ktx:1.7.0-alpha01'
This dependency which was causing issue, for that I have made it stable in build.gradle
file, then added a new line to solve dependency conflicts:这个导致问题的依赖项,为此我在
build.gradle
文件中使它稳定,然后添加了一个新行来解决依赖项冲突:
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.6.0'
}
}
Simple work around with complie version使用 complie 版本的简单解决方法
compileSdkVersion=29
to compileSdkVersion=30
and sync.compileSdkVersion=29
更改为compileSdkVersion=30
并同步。 If you not willing to change the complie version,then如果您不愿意更改编译版本,那么
configurations.all {
resolutionStrategy {
force 'androidx.core:core-ktx:1.6.0'
}
}
add the above code in build.gradle
inside android
and apply this加在上面的代码
build.gradle
内android
和应用此
implementation 'androidx.core:core-ktx:1.7.0-alpha01'
Try to add this on your top build.gradle
at the bottom of buildscript
.试着在你的顶部添加此
build.gradle
在底部buildscript
。 This will force anything to a specific version.这将强制任何特定版本。
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'androidx.core'
&& !details.requested.name.contains('androidx') ) {
details.useVersion "1.5.0"
}
if (details.requested.group == 'androidx.core-ktx'
&& !details.requested.name.contains('androidx') ) {
details.useVersion "1.5.0"
}
}
}
}
Updating version numbers to match those shown in the official template build.gradle file worked for me: https://github.com/facebook/react-native/blob/master/template/android/build.gradle更新版本号以匹配官方模板 build.gradle 文件中显示的版本号对我有用: https : //github.com/facebook/react-native/blob/master/template/android/build.gradle
buildToolsVersion = "30.0.2"
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "21.4.7075529"
您可以在此处找到有关此问题的信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.