You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Maven编译Android项目时DexGuard插件报Invalid SDK(API22不可用)错误求助

Fixing "Invalid SDK: Platform/API level 22 not available" with DexGuard Maven Plugin

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 sdkmanager tool)
  • Locate "Android 5.1.1 (API 22)" and confirm the SDK Platform option is checked and fully installed
  • For command-line verification, run:
    # Linux/macOS
    $ANDROID_HOME/tools/bin/sdkmanager --list | grep "android-22"
    
    # Windows (Command Prompt)
    %ANDROID_HOME%\tools\bin\sdkmanager --list | findstr "android-22"
    
    You should see platforms;android-22 listed 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_HOME and confirm it points to the folder containing your platforms directory
  • On Windows: Run echo %ANDROID_HOME% in Command Prompt (or echo $env:ANDROID_HOME in 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:21:02