react-native集成蓝牙打印的错误-4

> 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 无法完全解决问题,您可以手动替换库代码。

步骤
  1. 打开文件:
/node_modules/react-native-bluetooth-escpos-printer/android/src/main/java/cn/jystudio/bluetooth/RNBluetoothManagerModule.java
  1. 替换以下 import:
import android.support.v4.app.ActivityCompat; 
import android.support.v4.content.ContextCompat;

改为:

import androidx.core.app.ActivityCompat; 
import androidx.core.content.ContextCompat;
  1. 保存文件。

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
```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值