React Native:如何修改目标SDK版本以满足Google Play上架要求
Hey there, let's get that Google Play warning sorted out quickly. The fix is straightforward—you just need to update your Android project's SDK version configurations. Here's how to do it step by step:
Step 1: Update the app-level build.gradle file
Navigate to your React Native project's android/app/build.gradle file (this is the app-specific build file, not the one in the root android folder). Look for the android block and adjust these key values:
android { compileSdkVersion 26 // You can also use a newer stable version like 33 for better future compliance defaultConfig { applicationId "com.your.app.package" minSdkVersion 21 // Keep this if it fits your user base, or adjust as needed targetSdkVersion 26 // This is the critical value Google is requiring versionCode 1 versionName "1.0" } // ... rest of your existing configuration }
Note: Using a newer SDK version (like 33, the latest stable at the time of writing) is totally fine—Google accepts any version equal to or higher than the required minimum of 26.
Step 2: Address Android 8.0 (API 26) Compatibility Changes
Since you're targeting API 26, there are a few platform changes you might need to tweak for your app:
- Notification Channels: If your app uses notifications, you must create notification channels for Android 8.0+. Add this logic in your
MainApplication.javaor a dedicated notification helper class. - Runtime Permissions: Permissions like CAMERA, LOCATION, or STORAGE now require runtime requests instead of just install-time grants. Make sure your app handles permission prompts properly if you use these.
- Background Execution Limits: Android 8.0 restricted background service access. If your app relies on background services, consider switching to foreground services or using JobScheduler instead.
Step 3: Rebuild and Validate Your App
After making the changes, rebuild your app to catch any compilation errors:
- For debug builds: Run
react-native run-android - For release builds: Run
./gradlew assembleReleasefrom the project'sandroiddirectory
Test your app thoroughly on an Android 8.0+ device to ensure all features work as expected. Once everything checks out, upload the updated APK/AAB to Google Play, and that warning should vanish.
内容的提问来源于stack exchange,提问作者Sadhu




