执行expo start时app.json字段验证错误,求解决方案
执行expo start时触发以下配置验证错误:
Error: Problems validating fields in app.json.
• 不应存在额外属性'adaptiveIcon'。
• 不应存在额外属性'permissions'。
• 不应存在额外属性'versionCode'。
• 字段:android - 不应存在额外属性'googleMobileAdsAppId'。
• 字段:android.config - 不应存在额外属性'googleServicesFile'。
修复步骤
针对每个错误点,调整app.json的配置位置或方式:
移动 adaptiveIcon 到Android配置块
adaptiveIcon是Android专属配置,必须放在expo.android对象内部,不能在根级expo对象下。调整 versionCode 到Android配置块
Android的versionCode属于平台专属版本号,需要移到expo.android对象中,根级仅保留通用的version字段。替换根级 permissions 字段
Expo SDK 41+已废弃根级permissions,Android权限需移到expo.android.permissions数组中;iOS权限已通过infoPlist配置说明,无需额外添加。配置 googleMobileAdsAppId 到AdMob插件
将googleMobileAdsAppId整合到expo-ads-admob插件配置中,而非直接放在android对象下。调整 googleServicesFile 配置方式
Firebase的googleServicesFile需通过@react-native-firebase/app对应的Expo插件声明,移除android.config下的该字段。
修改后的完整app.json示例
{ "expo": { "name": "xx", "slug": "xx", "version": "1.0.0", "scheme": "xx", "plugins": [ [ "expo-document-picker", { "appleTeamId": "NHHHUJTTT", "iCloudContainerEnvironment": "Production" } ], [ "expo-notifications", { "icon": "./assets/icon96x96.png", "color": "#5675", "mode": "production" } ], [ "expo-ads-admob", { "userTrackingPermission": "wants to track you to collect IDFA to deliver personalised ads.", "androidAppId": "ca-app-pub-######~2444070320" } ], [ "expo-tracking-transparency", { "userTrackingPermission": "wants to track you to collect IDFA to deliver personalised ads." } ], [ "@react-native-firebase/app", { "googleServicesFile": "./google-services.json" } ] ], "orientation": "portrait", "icon": "./assets/icon.png", "splash": { "image": "./assets/splash.png", "backgroundColor": "#F723", "resizeMode": "cover" }, "notification": { "icon": "./assets/icon96x96.png", "color": "#F2320", "iosDisplayInForeground": true, "androidMode": "default" }, "updates": { "fallbackToCacheTimeout": 0 }, "assetBundlePatterns": [ "**/*" ], "ios": { "usesAppleSignIn": true, "supportsTablet": true, "bundleIdentifier": "com.XXxX", "buildNumber": "1", "usesIcloudStorage": true, "infoPlist": { "NSCameraUsageDescription": "Your App Name uses the camera to capture and upload user profile image and Listing Image to the server.", "NSPhotoLibraryUsageDescription": "Your App Name needs access to the photo library to select and upload user profile image and Listing Image to the server.", "NSPhotoLibraryAddUsageDescription": "Your App Name needs access to the photo library to select and upload user profile image and Listing Image to the server.", "NSLocationWhenInUseUsageDescription": "Your App Name usages device location on listing information, Listing search Data and User information.", "NSLocationAlwaysAndWhenInUseUsageDescription": "Your App Name usages device location on listing information, Listing search Data and User information.", "NSLocationAlwaysUsageDescription": "Your App Name uses device location on listing information, Listing search Data and User information.", "NSMicrophoneUsageDescription": "Your App Name uses your microphone while taking video of your product for uploading in listing information.", "CFBundleAllowMixedLocalizations": true, "UIBackgroundModes": [ "remote-notification" ], "NSUserTrackingUsageDescription": " wants to track you to collect IDFA to deliver personalised ads.", "SKAdNetworkItems": [ { "SKAdNetworkIdentifier": "cstr6suwn9.skadnetwork" } ] }, "config": { "googleMapsApiKey": "mjo8@#$%^&*(NYH87HNYB87B87" } }, "web": { "favicon": "./assets/favicon.png" }, "android": { "package": "com.adfars", "versionCode": 17, "adaptiveIcon": { "foregroundImage": "./assets/adaptive-icon.png", "backgroundColor": "#fff" }, "permissions": [ "CAMERA", "CAMERA_ROLL", "MEDIA_LIBRARY", "READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE", "RECORD_AUDIO", "READ_PHONE_STATE", "READ_CONTACTS", "LOCATION", "ACCESS_COARSE_LOCATION", "ACCESS_FINE_LOCATION", "RECEIVE_BOOT_COMPLETED" ], "config": { "googleMaps": { "apiKey": "mjo8H878ON7o7YN78NY####NYB87B87" } } }, "extra": { "eas": { "projectId": "########-48e8-9250-b8fe859b188b" } } }, "facebookScheme": "fb87867657656546545", "facebookAppId": "87867657656546545", "facebookDisplayName": "Your facebook app name", "scheme": "com.xxxx" }
补充说明
- 若使用Firebase,需先安装依赖:
npx expo install @react-native-firebase/app - 若不采用EAS Build,也可通过原生配置方式集成google-services.json,但插件方式更适配Expo项目的一致性要求。
内容的提问来源于stack exchange,提问作者ShafiJan

