Repository navigation
Expand file tree
/
Copy pathsetup-android-sdk.sh
More file actions
executable file
·103 lines (87 loc) · 2.98 KB
/
Copy pathsetup-android-sdk.sh
File metadata and controls
executable file
·103 lines (87 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
set -e # Exit on any error
echo "🔧 Setting up Android SDK..."
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Install Android SDK using brew (macOS)
if ! command_exists sdkmanager; then
echo "📦 Installing Android SDK command line tools..."
if command_exists brew; then
brew install --cask android-commandlinetools
else
echo "❌ Error: Homebrew not found. Please install Homebrew first."
exit 1
fi
else
echo "✅ Android SDK command line tools already installed"
fi
# Set up Android SDK environment variables
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools
echo "📁 Android SDK Home: $ANDROID_HOME"
# Create SDK directory if it doesn't exist
mkdir -p $ANDROID_HOME
# Accept licenses
echo "📄 Accepting Android SDK licenses..."
yes | sdkmanager --licenses 2>/dev/null || echo "✅ License acceptance completed"
# Install required SDK components
echo "📦 Installing Android SDK components..."
SDK_COMPONENTS=(
"platform-tools"
"platforms;android-34"
"platforms;android-33"
"build-tools;34.0.0"
"build-tools;33.0.2"
"cmdline-tools;latest"
)
for component in "${SDK_COMPONENTS[@]}"; do
echo "Installing $component..."
sdkmanager "$component" || echo "⚠️ Failed to install $component, continuing..."
done
# Create local.properties file
echo "📝 Creating local.properties file..."
cat > local.properties << EOF
## This file is automatically generated by setup-android-sdk.sh
# Do not modify this file manually in the repository.
# This file should *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the Android SDK. This is used by Gradle.
sdk.dir=$ANDROID_HOME
EOF
# Verify local.properties was created
if [ -f "local.properties" ]; then
echo "✅ local.properties created successfully"
echo "Contents:"
cat local.properties
else
echo "❌ Failed to create local.properties"
exit 1
fi
# Export environment variables for the current shell session
echo ""
echo "🌍 Setting up environment variables..."
echo "export ANDROID_HOME=$ANDROID_HOME"
echo "export ANDROID_SDK_ROOT=$ANDROID_HOME"
echo "export PATH=\$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools"
# Verify SDK installation
echo ""
echo "🔍 Verifying Android SDK installation..."
if command_exists adb; then
echo "✅ ADB: $(adb --version | head -1)"
else
echo "⚠️ ADB not found in PATH"
fi
if command_exists sdkmanager; then
echo "✅ SDK Manager: Available"
echo "📦 Installed packages:"
sdkmanager --list_installed | grep -E "(platforms|build-tools|platform-tools)" | head -10
else
echo "❌ SDK Manager not found"
fi
echo ""
echo "✅ Android SDK setup completed successfully!"
echo "🎯 You can now run Gradle builds that require Android SDK"