使用Maven编译Android项目时DexGuard插件报Invalid SDK(API22不可用)错误求助
Let’s troubleshoot this issue step by step—even if you’re certain your Android SDK is installed, there are a few common gotchas that can trigger this error with the DexGuard Maven plugin:
1. Double-check that SDK Platform 22 is actually installed
It’s easy to assume the platform is present, but let’s verify for sure:
- Open the Android SDK Manager (via Android Studio or the command-line
sdkmanagertool) - Locate "Android 5.1.1 (API 22)" and confirm the SDK Platform option is checked and fully installed
- For command-line verification, run:
You should see# Linux/macOS $ANDROID_HOME/tools/bin/sdkmanager --list | grep "android-22" # Windows (Command Prompt) %ANDROID_HOME%\tools\bin\sdkmanager --list | findstr "android-22"platforms;android-22listed as an installed package.
2. Explicitly set the SDK path in your DexGuard plugin configuration
The plugin might not automatically detect your ANDROID_HOME environment variable. Add the <path> element inside the <sdk> block to point directly to your SDK root directory:
<plugin> <groupId>com.guardsquare.dexguard.maven</groupId> <artifactId>dexguard-maven-plugin</artifactId> <configuration> <sdk> <path>${env.ANDROID_HOME}</path> <!-- Add this line --> <platform>22</platform> </sdk> <resourceDirectory>${project.parent.basedir}/mb-face-android-tablet-ui/res</resourceDirectory> <androidManifestFile>${project.parent.basedir}/mb-face-android-tablet-ui/AndroidManifest.xml</androidManifestFile> <dexguardConfig>${project.parent.basedir}/mb-face-android-tablet-ui/dexguard-project.txt</dexguardConfig> </configuration> </plugin>
Note: If you’re using a newer Android SDK, replace ${env.ANDROID_HOME} with ${env.ANDROID_SDK_ROOT}.
3. Validate your environment variables
Ensure the ANDROID_HOME (or ANDROID_SDK_ROOT) variable is correctly set and accessible to your Maven process:
- On Linux/macOS: Run
echo $ANDROID_HOMEand confirm it points to the folder containing yourplatformsdirectory - On Windows: Run
echo %ANDROID_HOME%in Command Prompt (orecho $env:ANDROID_HOMEin PowerShell) - Avoid spaces or special characters in the SDK path, as these can cause parsing issues.
4. Clean Maven’s cache and rebuild
Old build artifacts or cached configurations can sometimes cause false errors. Run this command to clean and rebuild with fresh dependencies:
mvn clean install -U
The -U flag forces Maven to update snapshots and dependencies, ensuring it picks up your corrected SDK configuration.
5. Check DexGuard plugin version compatibility
DexGuard 8.1.00 is a relatively old version—verify if it has known compatibility issues with API Level 22 or modern SDK directory structures. If possible, try upgrading to a newer version of the DexGuard Maven plugin while keeping your target platform set to 22.
内容的提问来源于stack exchange,提问作者A92

