0

very new to that kind of development I'm just supposed to add little features to the project that is a couple years old, so all developers quit and there is no doc to build the project / recommended version of the libs.

So I went and did a Dockerfile to automate the build of the project seeing the headache that it was to build on Windows (btw the windows build is good but now my manager want me to do a repeatable installation)

My dockerfile is :

# base image
FROM ubuntu:20.04 


# install wget tar and apt-add-repository
RUN apt-get update && apt-get -y install wget tar unzip openjdk-8-jdk

# install node js version 10.19.0 for linux, should be downloaded in local?
RUN wget https://nodejs.org/dist/v10.19.0/node-v10.19.0-linux-x64.tar.gz 
RUN tar -C /usr/local --strip-components 1 -xzf node-v10.19.0-linux-x64.tar.gz 

#install gradle 4.10.3
RUN wget https://services.gradle.org/distributions/gradle-4.10.3-bin.zip -P /tmp
RUN unzip -d /opt/gradle /tmp/gradle-4.10.3-bin.zip

# install android command line
RUN wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip
# create a directory else it doesn't work see https://stackoverflow.com/a/56175645/14137672
RUN mkdir -p /sdk && mv commandlinetools-linux-7583922_latest.zip /sdk && cd /sdk && unzip commandlinetools-linux-7583922_latest.zip
WORKDIR "/sdk/cmdline-tools"

# specific to commandlinetools-linux-7583922 the unzipped folder is not correct, it needs to be under latest folder, so /cmdline-tools/latest/...
# see https://stackoverflow.com/a/67413427/14137672 for more informations about this
RUN mkdir .latest && mv * .latest && mv .latest latest

ENV PATH="/sdk/cmdline-tools/latest/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin/:/sdk/cmdline-tools/latest:/opt/gradle/gradle-4.10.3/bin:${PATH}"
ENV ANDROID_SDK_ROOT=/sdk/cmdline-tools/latest/bin
ENV GRADLE_HOME=/opt/gradle/gradle-4.10.3

WORKDIR "/sdk/cmdline-tools/latest/bin"
RUN chmod +770 /sdk/cmdline-tools/latest/bin/sdkmanager
RUN /sdk/cmdline-tools/latest/bin/sdkmanager "platform-tools" "platforms;android-19" "platforms;android-20" "platforms;android-21" "platforms;android-22" "platforms;android-23" "platforms;android-24" "platforms;android-25" "system-images;android-28;default;x86"
RUN /sdk/cmdline-tools/latest/bin/sdkmanager "platforms;android-26" "platforms;android-27" "platforms;android-28" "platforms;android-29" "platforms;android-30" "platforms;android-31" "platforms;android-Sv2" "skiaparser;1" "system-images;android-29;google_apis;x86"
RUN /sdk/cmdline-tools/latest/bin/sdkmanager "build-tools;31.0.0" "build-tools;30.0.2" "build-tools;29.0.3" "build-tools;29.0.2" "build-tools;29.0.1" "build-tools;29.0.0" "build-tools;28.0.3" "build-tools;20.0.0" "build-tools;19.1.0" "system-images;android-31;default;x86_64"
RUN /sdk/cmdline-tools/latest/bin/sdkmanager "cmdline-tools;5.0" "cmdline-tools;4.0" "ndk;23.1.7779620" "emulator" "extras;google;market_apk_expansion" "extras;google;instantapps" "extras;google;market_licensing" "extras;google;google_play_services"
RUN /sdk/cmdline-tools/latest/bin/sdkmanager "system-images;android-19;default;x86" "system-images;android-21;default;x86" "system-images;android-22;default;x86" "system-images;android-23;default;x86" "system-images;android-24;default;x86" "system-images;android-25;default;x86" "system-images;android-26;default;x86" "system-images;android-27;default;x86"

COPY . /usr/local/myapp
WORKDIR "/usr/local/myapp"

# should not be commited 
RUN rm -rf node_modules/

# install project dependancies
RUN npm install 
RUN npm install -g ionic@5.4.16
RUN npm install -g cordova@10.0.0
RUN cordova telemetry off

# no native because we don't have android fully installed
#RUN ionic cordova run android --no-native-run --no-telemetry

So the idea is that I'm not installing the whole Android Studio I just need the platforms;android-X and that's the simplest way I found to install them.

Now I'm facing the error :

No installed build tools found. Install the Android build tools version 19.1.0 or higher.

But from my understanding I already have installed it using sdkmanager ...

On my Windows I had the whole installation so I had :

ANDROID_HOME = C:\Users\me\AppData\Local\Android\Sdk\build-tools
ANDROID_SDK_ROOT = C:\Program Files (x86)\Android\android-sdk

And in my Windows path :

C:\Program Files (x86)\Android\android-sdk\platform-tools
C:\Users\me\AppData\Local\Android\Sdk\tools
C:\Users\me\AppData\Local\Android\Sdk\tools\bin

So finally my question is how do I set the path and env variables in my docker as I don't have the full installation of Android Studio ?

If you have Docker changes / advices I will happily take them I'm far from a Docker expert.

Edit :

Just found out that disabling native-run was a false problem and i just needed to install the library with npm

RUN npm install -g native-run@1.5.0
Mat
  • 1
  • 1
  • Just to note this isn't just a "add your directory to the path" because this is a partial installation and there isn't Android Studio installed and there is no graphical environment. – Mat Dec 08 '21 at 07:03
  • hi Mat, first you have to understand that if you want to automate a build it is not necessary to install android studio, but if you must have the android sdk installed. second do you want to use docker locally to generate the build? Or do you want the build to be generated in some Continuous Integration instance? answering your question "how do I set the path and env variables in my docker?" ENV PATH="/sdk/cmdline-tools/latest/bin:/usr/lib/jvm/java-8-openjdk-amd64/bin/:/sdk/cmdline-tools/latest:/opt/gradle/gradle-4.10.3/bin:${PATH}" ENV ANDROID_SDK_ROOT=/sdk/cmdline-tools/latest/bin – El David Dec 13 '21 at 20:13
  • Hello, thank you for your answer. It's intended to be used locally, will never be in CI. I don't get why I shouldn't need Android Studio ? – Mat Dec 14 '21 at 10:34
  • If you use it locally, perhaps it is best to run the docker steps on your computer and install Android Studio there. Android Studio uses a lot of space and a graphical interface, it is generally not part of the logic used in the use of docker containers. I hope I've helped ;) – El David Dec 14 '21 at 19:35
  • Very sorry I don't get the _run the docker steps on your computer_ ? I'm on Windows and trying to get out of the installation part for every computer change. And I'm not installing full Android Studio just the command line tool so that should not be that big (maybe 2Go max ?) – Mat Dec 14 '21 at 19:55
  • I see 2 alternatives: 1. use docker and run your project on this container. This option has disadvantages: lack of visual interface and consumes more resources (cpu, ram) so it could be slower, since ubuntu would be running on the host windows operating system in your case 2. replicate the steps of the dockerfile in your local system. This option has the disadvantage: translating and configuring each step of the docker file from one operating system to another is a challenge. good luck – El David Dec 14 '21 at 20:14

0 Answers0