Error : java.lang.NoSuchMethodError: No virtual method getTxPower() - while trying to get the transmission power

Error : java.lang.NoSuchMethodError: No virtual method getTxPower() - while trying to get the transmission power

我制作了一个 android 应用程序来使用 BLE 方法计算设备之间的距离,但它显示方法 getTxPower() 的错误。错误是 java.lang.NoSuchMethodError: No virtual method getTxPower()I in class Landroid/bluetooth/le/ScanResult; or its super classes (declaration of 'android.bluetooth.le.ScanResult' appears in /system/framework/framework.jar)

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "27.0.3"

    defaultConfig {
        applicationId "com.example.beacondistance"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }


}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

getTxPower() 仅在 API 级别 26 中添加。尝试在较低的 API 级别设备上调用该方法将导致此错误。在调用此方法之前检查 Build.VERSION.SDK_INT 中的运行时 API 级别。