任务 ':vision-camera-code-scanner:checkDebugAndroidTestAarMetadata' 执行失败

Execution failed for task ':vision-camera-code-scanner:checkDebugAndroidTestAarMetadata'

所以我已经这样做了一段时间了,我最近尝试在我的 React Native 项目中将 Detox 测试添加到 android。

我遵循了官方排毒教程和这个 https://varunon9.medium.com/e2e-testing-of-react-native-app-android-using-detox-a-step-by-step-guide-bfb520c1a9ac 但是当我尝试构建项目时 detox build -c android.emu.debug 我不断收到此异常:

FAILURE: Build failed with an exception.

Execution failed for task ':vision-camera-code-scanner:checkDebugAndroidTestAarMetadata'. A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction The minCompileSdk (31) specified in a dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties) is greater than this module's compileSdkVersion (android-30). Dependency: androidx.camera:camera-extensions:1.1.0-beta02. AAR metadata file: ./directory-location/aar-metadata.properties.

我一直在网上找,我只找到了这两页

https://github.com/mrousavy/react-native-vision-camera/issues/934

https://groups.google.com/a/android.com/g/camerax-developers/c/Gc4yAR2l9I0

但这并没有帮助,因为我的 compileSdkVersion 和我的 targetSdkVersion 已经是 31...

如果你能帮助我,我将不胜感激,tnx。

我遇到了同样的问题,在你的android/build.gradle中添加:

buildscript {
    ext {
        ...
        VisionCameraCodeScanner_targetSdkVersion = 31
        VisionCameraCodeScanner_compileSdkVersion = 31
    }
    ...
}

这只是将 compileSdkVersiontargetSdkVersion 版本设置为 31,从而解决了我的问题。 (确保在之后清理你的构建文件夹)