> Task :react-native-bluetooth-escpos-printer:compileDebugJavaWithJavac FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
123 actionable tasks: 113 executed, 10 up-to-date
info 💡 Tip: Make sure that you have set up your development environment correctly, by running npx react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor
/your_project/node_modules/react-native-bluetooth-escpos-printer/android/src/main/java/cn/jystudio/bluetooth/RNBluetoothManagerModule.java:13: error: cannot find symbol
import android.support.v4.app.ActivityCompat;
^
symbol: class ActivityCompat
location: package android.support.v4.app
/your_project/node_modules/react-native-bluetooth-escpos-printer/android/src/main/java/cn/jystudio/bluetooth/RNBluetoothManagerModule.java:14: error: package android.support.v4.content does not exist
import android.support.v4.content.ContextCompat;
^
/your_project/node_modules/react-native-bluetooth-escpos-printer/android/src/main/java/cn/jystudio/bluetooth/RNBluetoothManagerModule.java:175: error: cannot find symbol
int permissionChecked = ContextCompat.checkSelfPermission(reactContext, android.Manifest.permission.ACCESS_COARSE_LOCATION);
^
symbol: variable ContextCompat
location: class RNBluetoothManagerModule
/your_project/node_modules/react-native-bluetooth-escpos-printer/android/src/main/java/cn/jystudio/bluetooth/RNBluetoothManagerModule.java:178: error: cannot find symbol
ActivityCompat.requestPermissions(reactContext.getCurrentActivity(),
^
symbol: variable ActivityCompat
location: class RNBluetoothManagerModule
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /your_project/node_modules/react-native-bluetooth-escpos-printer/android/src/main/java/cn/jystudio/bluetooth/tsc/TscCommand.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':react-native-bluetooth-escpos-printer:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --info option to get more log output.
> Run with --scan to get full insights.
解决方法:
替换 android.support 为 AndroidX(推荐)
如果 Jetifier 无法完全解决问题,您可以手动替换库代码。
步骤
- 打开文件:
/node_modules/react-native-bluetooth-escpos-printer/android/src/main/java/cn/jystudio/bluetooth/RNBluetoothManagerModule.java
- 替换以下 import:
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
改为:
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
- 保存文件。
3. 确保项目使用 AndroidX
确保项目已经完全迁移到 AndroidX。检查以下内容:
文件 android/gradle.properties
确认以下配置:
android.useAndroidX=true android.enableJetifier=true
升级 Gradle 插件
确保 Android Gradle 插件版本足够高(3.4.0+ 支持 AndroidX)。检查 android/build.gradle
:
classpath("com.android.tools.build:gradle:7.0.0")
升级后可能需要更新 gradle-wrapper.properties
,例如:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
```