Android studio 运行出现Error running app: This version of Android Studio is incompatible with the Gradle

本文介绍了解决Android Studio中因Gradle插件版本不兼容导致的错误运行应用程序的问题。通过禁用即时运行或更新IDE及Gradle插件至最新版本来解决此问题。

运行项目的时候出现:Error running app: This version of Android Studio is incompatible with the Gradle Plugin used. Try disabling Instant Run (or updating either the IDE or the Gradle plugin to the latest version)

翻译一下:错误运行应用程序:这个版本的Android工作室与Gradle插件不兼容使用。尝试禁用即时运行(或更新IDE或Gradle插件的最新版本)

意思很明白了,就是Gradle不兼容,虽然看到这个,都知道是版本不兼容,当不知道哪里下手去做修改,今天我刚好遇到这个这个问题,跟大家一起分享怎么做处理:

第一步:如下图:

这里写图片描述

第二步:
这里写图片描述

第三步:clean项目之后,运行项目
这里写图片描述

D:\AwesomeProject>npm run android > AwesomeProject@0.0.1 android > react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 1707 file(s) to forward-jetify. Using 12 workers... info JS server already running. info Installing the app... > Configure project :react-native-reanimated AAR for react-native-reanimated has been found D:\AwesomeProject\node_modules\react-native-reanimated\android\react-native-reanimated-68-jsc.aar > Task :app:mapDebugSourceSetPaths FAILED Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings 98 actionable tasks: 92 executed, 6 up-to-date Warning: This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:mapDebugSourceSetPaths'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Failed to transform jpush-5.1.2.aar to match attributes {artifactType=android-res}. > Execution failed for JetifyTransform: D:\AwesomeProject\android\app\libs\jiguang\jpush-5.1.2.aar. > Transform's input file does not exist: D:\AwesomeProject\android\app\libs\jiguang\jpush-5.1.2.aar. (See https://issuetracker.google.com/issues/158753935) > Failed to transform jcore-2.1.0.aar to match attributes {artifactType=android-res}. > Execution failed for JetifyTransform: D:\AwesomeProject\android\app\libs\jiguang\jcore-2.1.0.aar. > Transform's input file does not exist: D:\AwesomeProject\android\app\libs\jiguang\jcore-2.1.0.aar. (See https://issuetracker.google.com/issues/158753935) * 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 1m 4s 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 Warning: This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:mapDebugSourceSetPaths'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Failed to transform jpush-5.1.2.aar to match attributes {artifactType=android-res}. > Execution failed for JetifyTransform: D:\AwesomeProject\android\app\libs\jiguang\jpush-5.1.2.aar. > Transform's input file does not exist: D:\AwesomeProject\android\app\libs\jiguang\jpush-5.1.2.aar. (See https://issuetracker.google.com/issues/158753935) > Failed to transform jcore-2.1.0.aar to match attributes {artifactType=android-res}. > Execution failed for JetifyTransform: D:\AwesomeProject\android\app\libs\jiguang\jcore-2.1.0.aar. > Transform's input file does not exist: D:\AwesomeProject\android\app\libs\jiguang\jcore-2.1.0.aar. (See https://issuetracker.google.com/issues/158753935) * 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 1m 4s at makeError (D:\AwesomeProject\node_modules\execa\index.js:174:9) at D:\AwesomeProject\node_modules\execa\index.js:278:16 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async runOnAllDevices (D:\AwesomeProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5) at async Command.handleAction (D:\AwesomeProject\node_modules\@react-native-community\cli\build\index.js:192:9) info Run CLI with --verbose flag for more details.
最新发布
08-09
打开文件: android/build.gradle 在 allprojects.repositories 中添加 jitpack.io: groovy allprojects { repositories { maven { url 'https://www.jitpack.io' } // 添加这一行 我已经添加了 maven { url 'https://www.jitpack.io' } 这一行然后运行还是有以下报错 D:\AwesomeProject>npm run android > AwesomeProject@0.0.1 android > react-native run-android info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag. Jetifier found 1866 file(s) to forward-jetify. Using 12 workers... info JS server already running. info Installing the app... Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details > Configure project :react-native-reanimated AAR for react-native-reanimated has been found D:\AwesomeProject\node_modules\react-native-reanimated\android\react-native-reanimated-68-jsc.aar Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings 6 actionable tasks: 6 up-to-date Warning: This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times. FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ':react-native-video-processing:compileDebugAidl'. > Could not resolve all task dependencies for configuration ':react-native-video-processing:debugCompileClasspath'. > Could not find com.yqritc:android-scalablevideoview:1.0.4. Required by: project :react-native-video-processing * 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 1m 11s 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 Warning: This version only understands SDK XML versions up to 3 but an SDK XML file of version 4 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times. FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ':react-native-video-processing:compileDebugAidl'. > Could not resolve all task dependencies for configuration ':react-native-video-processing:debugCompileClasspath'. > Could not find com.yqritc:android-scalablevideoview:1.0.4. Required by: project :react-native-video-processing * 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 1m 11s at makeError (D:\AwesomeProject\node_modules\execa\index.js:174:9) at D:\AwesomeProject\node_modules\execa\index.js:278:16 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async runOnAllDevices (D:\AwesomeProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:109:5) at async Command.handleAction (D:\AwesomeProject\node_modules\@react-native-community\cli\build\index.js:192:9) info Run CLI with --verbose flag for more details.这为什么不行?
08-08
### Gradle 2.14.1 与 Android Studio 2022.3 不兼容的解决方案 Gradle 2.14.1 是一个较旧的版本,而 Android Studio 2022.3 基于较新的 Gradle 插件版本(通常为 7.x 或更高),因此两者之间存在兼容性问题。为了解决 Gradle 2.14.1 与 Android Studio 2022.3 不兼容的问题,可以通过以下方法进行修复。 #### 1. 升级 Gradle 插件版本 Gradle 2.14.1 对应的 Android Gradle 插件版本较低(通常为 2.x)。Android Studio 2022.3 需要使用 Android Gradle 插件 7.x 或更高版本。需要在 `build.gradle` 文件中升级插件版本[^1]。 ```gradle // 项目级 build.gradle 文件 buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.4.2' // 升级到 7.x 版本 } } ``` #### 2. 升级 Gradle Wrapper 版本 Gradle 2.14.1 不支持 Android Gradle 插件 7.x,因此需要升级 Gradle Wrapper 到兼容版本。通常,Gradle Wrapper 版本应与 Android Gradle 插件版本保持兼容。例如,Gradle 7.x 插件通常需要 Gradle 7.x 或更高版本。 ```properties # gradle/wrapper/gradle-wrapper.properties 文件 distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip ``` #### 3. 使用 `annotationProcessor` 替代 `android-apt` 如果项目中使用了 `android-apt` 插件,需要将其替换为 `annotationProcessor`。Gradle 2.x 中的 `android-apt` 已被弃用,而 `annotationProcessor` 是 Gradle 3.x 及以上版本的标准配置。 ```gradle dependencies { annotationProcessor 'com.example:library-processor:1.0.0' } ``` #### 4. 检查 Gradle 和插件的兼容性 确保 Gradle 版本和 Android Gradle 插件版本兼容。可以参考官方文档中的兼容性矩阵,选择合适的组合。例如: - Gradle 7.2 与 Android Gradle 插件 7.2.x 兼容 - Gradle 7.4 与 Android Gradle 插件 7.4.x 兼容 #### 5. 清理并重建项目 在完成上述更改后,建议清理并重建项目以解决潜在的缓存问题。 ```bash ./gradlew clean ./gradlew build ``` #### 6. 使用 Android Studio 内置工具升级 Android Studio 提供了内置的升级向导,可以帮助用户自动升级 GradleAndroid Gradle 插件版本。可以通过以下步骤触发: - 打开 Android Studio - 点击菜单栏中的 **Help > Check for Updates** - 如果有可用更新,按照提示升级 Android Studio 和相关插件 ### 示例:完整的 Gradle 升级步骤 ```gradle // 项目级 build.gradle 文件 buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.4.2' } } ``` ```properties # gradle/wrapper/gradle-wrapper.properties 文件 distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip ``` ```gradle // 模块级 build.gradle 文件 dependencies { annotationProcessor 'com.example:library-processor:1.0.0' } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值