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

Ubuntu环境下执行sudo ionic cordova build android命令失败求助

Troubleshooting Ionic Cordova Android Build Failure on Ubuntu

Hey there, let's work through this build issue step by step—since you're new to Ubuntu and Ionic/Cordova, we'll start with the most common pitfalls first.

1. Fix Permission Issues Caused by sudo

First off, using sudo to run ionic cordova commands messes up file ownership in your project directory, which often leads to weird errors like unhandled promise rejections. Let's fix the permissions first:

sudo chown -R $USER:$USER /home/tel/Desktop/AnimalTrackerApp/UserApplication

Never use sudo for Ionic/Cordova commands again unless explicitly told to (which is almost never).

2. Verify Android SDK Components

Your log shows ANDROID_HOME=/usr/lib/android-sdk, but Ubuntu's default Android SDK installation often misses critical components. Let's check and install what's needed:

  • First, make sure you have permission to modify the SDK directory (so you don't need sudo for future installs):
    sudo chown -R $USER:$USER /usr/lib/android-sdk
    
  • List all available/installed components:
    sdkmanager --list
    
  • Install the core components (replace versions with what your project targets—check platforms/android/app/build.gradle for targetSdkVersion):
    sdkmanager "platform-tools" "platforms;android-33" "build-tools;33.0.2"
    
    Note: If you get a "command not found" error for sdkmanager, add the SDK tools path to your environment variables (see next step).

3. Fix Environment Variable Configuration

Ubuntu doesn't always set up the Android SDK paths correctly. Open your shell config file (either ~/.bashrc for Bash or ~/.zshrc for Zsh) in a text editor:

nano ~/.bashrc

Add these lines at the end:

export ANDROID_HOME=/usr/lib/android-sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/build-tools/33.0.2

Save and exit (Ctrl+O, Enter, Ctrl+X), then apply the changes:

source ~/.bashrc

4. Check Gradle Setup

Cordova relies on Gradle to build Android projects, and Ubuntu's default Gradle version might be outdated or missing. Install a compatible version:

sudo apt install gradle

Then, clean the Android project's Gradle cache to avoid conflicts:

cd /home/tel/Desktop/AnimalTrackerApp/UserApplication/platforms/android
gradle clean
cd ../..

5. Validate build.json

Your log mentions reading build.json—if this file has incorrect signing credentials (like wrong keystore paths or passwords), it can cause build failures. If you don't need signed builds yet, temporarily rename or delete build.json to test if that's the issue.

After going through these steps, try running the build again without sudo:

ionic cordova build android

内容的提问来源于stack exchange,提问作者Gowtham Raj

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 07:57:46