首页 > 解决方案 > 在 Ubuntu 20.04 中安装没有 Android Studio 的 android sdk

问题描述

以下是我如何安装我的 android sdk 以在我的 Android 手机上运行 React Native:考虑到 Java 和 adb 已经安装:

sudo apt update && sudo apt install android-sdk

这将添加环境变量:

echo 'export ANDROID_HOME="/usr/lib/android-sdk"
export ANDROID_SDK_ROOT="/usr/lib/android-sdk"
PATH=$PATH:$ANDROID_HOME/tools
PATH=$PATH:$ANDROID_HOME/platform-tools
' >> ~/.bashrc

我们现在需要安装缺少的 sdkManager:

source ~/.bashrc
# Download the archive
wget https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip
unzip commandlinetools-linux-6609375_latest.zip -d cmdline-tools
# Make the sdk directory writable
sudo chmod -R a+rw $ANDROID_HOME
# Merge bin with bin and tools with tools
mv cmdline-tools/tools/bin/* $ANDROID_HOME/tools/bin/
rm -rf cmdline-tools/tools/bin
mv cmdline-tools/tools/* $ANDROID_HOME/tools/
rm -rf cmdline-tools
# Accept the licences
yes | $ANDROID_HOME/tools/bin/sdkmanager --sdk_root=${ANDROID_HOME} --licenses

现在,这是我在运行时得到的react-native run-android

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:installDebug'.

> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/xxx/android/local.properties'.

好的,我可以在 local.properties 中设置 sdk.dir 并且这很有效,但我不想在我必须处理的每个项目中都这样做。为什么ANDROID_SDK_ROOT被忽视?

标签: androidlinuxandroid-studioandroid-sdk-2.3

解决方案


推荐阅读