英文:
react-native starting app errors on Android Studio
问题
Title: Gradle构建错误:找不到实现类'com.facebook.react.ReactPlugin'
Question:
在使用Gradle构建我的React Native项目时,我遇到了一个错误。错误消息如下:
找不到插件'com.facebook.react'中指定的'com.facebook.react.ReactPlugin'实现类,位于jar:file:/Users/venkateshdasari/.gradle/caches/jars-9/410fa8799cd716bf29225aa40627be5f/react-native-gradle-plugin.jar!/META-INF/gradle-plugins/com.facebook.react.properties。
此外,错误还提到我的build.gradle
文件中未指定compileSdkVersion
。
我尝试清除Gradle缓存,删除错误中提到的特定缓存文件,并在Android Studio中无效化缓存,但问题仍然存在。
以下是我的项目设置的相关细节:
- React Native版本:[你的React Native版本]
- Gradle版本:[你的Gradle版本]
- 其他相关依赖项:[列出任何相关依赖项]
我将感激任何关于如何解决这个问题的指导或建议。
[ React Native版本7.3.1 ]
和[你的Gradle版本新]
,请使用实际版本替换这些值。还请提供有关项目配置和依赖项的任何其他相关信息。
英文:
Title: Gradle build error: Could not find implementation class 'com.facebook.react.ReactPlugin'
Question:
I'm encountering an error while building my React Native project with Gradle. The error message states:
Could not find implementation class 'com.facebook.react.ReactPlugin' for plugin 'com.facebook.react' specified in jar:file:/Users/venkateshdasari/.gradle/caches/jars-9/410fa8799cd716bf29225aa40627be5f/react-native-gradle-plugin.jar!/META-INF/gradle-plugins/com.facebook.react.properties.
Additionally, the error mentions that the compileSdkVersion
is not specified in my build.gradle
file.
I have tried clearing the Gradle cache, deleting the specific cache files mentioned in the error, and invalidating caches in Android Studio, but the issue still persists.
Here are the relevant details of my project setup:
- React Native version: [your React Native version]
- Gradle version: [your Gradle version]
- Other relevant dependencies: [list any relevant dependencies]
I would appreciate any guidance or suggestions on how to resolve this issue.
[ React Native version 7.3.1 ]
and [your Gradle version new ]
with the actual versions you're using. Also, include any additional relevant information about your project configuration and dependencies.
I tried to create an app in Android Studio but it is not working throwing this error always:
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find implementation class 'com.facebook.react.ReactPlugin' for plugin 'com.facebook.react' specified in jar:file:/Users/venkateshdasari/.gradle/caches/jars-9/410fa8799cd716bf29225aa40627be5f/react-native-gradle-plugin.jar!/META-INF/gradle-plugins/com.facebook.react.properties.
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle
* 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 1s
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 app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* Where:
Build file '/Users/venkateshdasari/FirstProject/android/app/build.gradle' line: 2
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find implementation class 'com.facebook.react.ReactPlugin' for plugin 'com.facebook.react' specified in jar:file:/Users/venkateshdasari/.gradle/caches/jars-9/410fa8799cd716bf29225aa40627be5f/react-native-gradle-plugin.jar!/META-INF/gradle-plugins/com.facebook.react.properties.
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle
* 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
答案1
得分: 1
I'll provide the translation for the code and instructions you've provided:
- 检查你的
android/build.gradle
文件:
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31 // 确保这一行存在
targetSdkVersion = 31
}
}
在你的 android/app/build.gradle
文件中:
android {
compileSdkVersion rootProject.ext.compileSdkVersion // 如果不存在,必须添加这一行
}
-
执行以下步骤:
- 删除根目录下的
node_module
文件夹和package-lock.json
文件。 - 进入 android 文件夹并删除
.gradle
文件夹。 - 打开 Android Studio,选择
Build
,然后选择Clean Project
。 - 选择
File
,然后选择Invalidate Caches
,勾选 clear system files and local history,这将重新启动 Android Studio。
- 删除根目录下的
-
打开终端,在你的根项目中运行以下命令:
npm i --save
cd android
./gradlew clean
cd ..
npx react-native start --reset-cache
npx react-native run-android
请确保按照以上步骤操作。如果需要更多帮助,请随时提问。
英文:
Your Question is not very clear.
but still, from what I understood, you can try doing this step by step.
- Check your
android/build.gradle
file:
<!-- begin snippet: js hide: false console: false babel: false -->
<!-- language: lang-js -->
buildscript {
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31 // make sure this line is present
targetSdkVersion = 31
}
}
<!-- end snippet -->
In your `android/app/build.gradle`:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
android {
compileSdkVersion rootProject.ext.compileSdkVersion // This line must be added if it is not there
}
<!-- end snippet -->
- Do the following:
> Delete node_module
folder and package-lock.json
file
> from your root directory.
>
> Go to android folder and delete .gradle
folder.
>
> Go to Android Studio ===> Build
===> Clean Project
>
> select File
===> Invalidate Caches
===> check clear system files and local history
this will restart the android studio
> 3. Go to terminal
> in your Root project, enter command : npm i --save
>
> after that, cd android; ./gradlew clean; cd ..
//this will clean gradle files
>
> then run, npx react-native start --reset-cache
>
> after that, run npx react-native run-android
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论