升级CompileSdkVersion至Android-P后无法分发APK,回退旧版本报错求助
Hey there, I’ve run into this exact headache when Android P first launched—let’s work through getting you unstuck.
What’s Causing the Error?
The No resource found that matches the given name (at 'dialogCornerRadius' with value '?android:attr/dialogCornerRadius') error pops up because ?android:attr/dialogCornerRadius is a system attribute introduced in Android P (API 28). Before the new SDK rolled out, your project used an older compile SDK version that didn’t recognize this attribute. Once the SDK updated (or a dependency started using this attribute), the build broke immediately.
Step-by-Step Solutions
Let’s tackle both the build error and the distribution roadblock:
1. Fix the Build Error Properly
Setting compileSdkVersion 'android-P' (or its numeric equivalent 28) tells Gradle to use the Android P SDK for compilation, which resolves the missing resource issue. But if this breaks APK distribution, here’s why and how to fix it:
2. Resolve the Distribution Block
The most common culprit here is a mismatch between your compileSdkVersion and targetSdkVersion, or distribution platforms not supporting API 28 yet. Try this:
- Update your module-level
build.gradleto align versions correctly:android { compileSdkVersion 28 buildToolsVersion "28.0.3" // Use a compatible build tools version defaultConfig { applicationId "com.your.app" minSdkVersion 21 // Keep your existing minimum SDK requirement targetSdkVersion 28 // Or revert to your old target (like 27) if distribution requires it versionCode 1 versionName "1.0" } } - If your distribution platform won’t accept API 28 APKs, keep
compileSdkVersion 28but settargetSdkVersionback to your original version (e.g., 27). This lets you compile against the new SDK (fixing the resource error) while targeting an older API level for distribution. Just be sure to test your app thoroughly for compatibility quirks.
3. Temporary Workaround (If You Can’t Upgrade Compile SDK)
If you absolutely need to stick with the old compile SDK for now, add a fallback value for the missing attribute in your project’s res/values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Define the attribute locally to bypass the missing resource error --> <item name="android:dialogCornerRadius">8dp</item> </style>
This is a short-term fix though—long-term, upgrading to the latest SDK is critical for app security and compatibility.
4. Check Third-Party Dependencies
Sometimes an outdated third-party library is secretly referencing dialogCornerRadius without proper SDK checks. Update all your dependencies to their latest versions (check your build.gradle dependencies block) to see if that fixes both build and distribution issues.
内容的提问来源于stack exchange,提问作者Saleem Ahmad

