Android Studio报错:无法获取SoftwareComponentInternal的'release'属性求解决
解决Gradle构建错误:Could not get unknown property 'release' for SoftwareComponentInternal
错误场景
在React Native + Expo项目中构建Android应用时,触发expo-camera模块的Gradle配置错误,且已尝试常规解决方案无效。
错误详情
Build file '/Users/hayat/Documents/chungchunon-RN-frontend/node_modules/expo-camera/android/build.gradle' line: 48 A problem occurred evaluating project ':expo'. > A problem occurred configuring project ':expo-camera'. > Could not get unknown property 'release' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer. * Try: > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. * Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating project ':expo'. at
解决方案
调整Gradle版本:
打开项目根目录下的gradle/wrapper/gradle-wrapper.properties,检查distributionUrl对应的Gradle版本。若使用旧版Gradle(如6.x及以下),升级到7.x或更高版本(需与项目其他模块兼容),保存后重新同步Gradle。修复expo-camera的build.gradle配置:
定位到node_modules/expo-camera/android/build.gradle第48行,将原代码中引用components.release的部分,替换为components.findByName("release")。若涉及Maven发布配置,也可改为使用android.libraryVariants.find { it.name == "release" }来获取变体。清理缓存并重建:
依次执行以下命令清理缓存并重新构建:./gradlew clean rm -rf node_modules && npm install ./gradlew assembleDebug升级expo-camera模块:
执行命令升级到最新稳定版,新版本通常已修复Gradle兼容问题:npm install expo-camera@latest
内容的提问来源于stack exchange,提问作者Hyejung
相关产品推荐
相关产品推荐

