Search code examples
androidflutterdockerdockerfileandroid-sdk-tools

Failing to install dependencies with sdkmanager inside a Dockerfile


I'm trying to package the dependencies to build an Android application inside a Docker container. As part of the dependencies installation, I'm using sdkmanager to install some dependencies. When specifying a list of packages to install, it requires to put their names in double quotes. Since also Docker's RUN in exec form requires to put double quotes around its arguments, I'm using double double-quotes and escaping the inner ones like this:

RUN ["./android-sdk/cmdline-tools/bin/sdkmanager", "--sdk_root=/root/android-sdk", "--install", "\"build-tools;33.0.2\"", "\"platform-tools\"", "\"ndk;21.4.7075529\"", "\"cmake;3.6.4111459\""]

However, when I try to build my image I get the following error:

Step 12/20 : RUN ["./android-sdk/cmdline-tools/bin/sdkmanager", "--sdk_root=/root/android-sdk", "--install", "\"build-tools;33.0.2\"", "\"platform-tools\"", "\"ndk;21.4.7075529\"", "\"cmake;3.6.4111459\""]
 ---> Running in 269b0033b9af
Warning: Failed to find package '"build-tools;33.0.2"'                          
The command './android-sdk/cmdline-tools/bin/sdkmanager --sdk_root=/root/android-sdk --install "build-tools;33.0.2" "platform-tools" "ndk;21.4.7075529" "cmake;3.6.4111459"' returned a non-zero code: 1

If I instead don't put the double double-quotes, I don't get any errors, but I think it's not installing all the dependencies as later Flutter complains about not finding the Android SDK in the root I specified, and indeed I can't find there e.g. the platform-tools directory. What am I doing wrong? Do you know a better way to install Android SDK inside a container? You can find the full Dockerfile here. Thank you for your help.

Update: trying to manually install dependencies witb sdkmanager inside the container, I found out that to install them you first need to manually accept a license agreement and then after installing them flutter still doesn't recognize my installation. Maybe it is too difficult to install the Android SDK inside a container and I should just use this Docker image that runs an sdk from your host or just build the app on my host.


Solution

  • In the end, I solved by basing my image on this one and using the "normal" syntax for run like this:

    RUN sdkmanager --install "build-tools;33.0.2" "cmdline-tools;latest" "ndk;21.4.7075529" "platform-tools" "cmake;3.6.4111459"