<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Javad Arjmandi</title>
    <description>The latest articles on Forem by Javad Arjmandi (@javadlv).</description>
    <link>https://forem.com/javadlv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F51480%2Fe3b66786-7af7-48a7-a0fe-1c4ccb0d804e.jpeg</url>
      <title>Forem: Javad Arjmandi</title>
      <link>https://forem.com/javadlv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/javadlv"/>
    <language>en</language>
    <item>
      <title>Gitlab-CI for Android 2021 update</title>
      <dc:creator>Javad Arjmandi</dc:creator>
      <pubDate>Sun, 25 Apr 2021 05:13:11 +0000</pubDate>
      <link>https://forem.com/javadlv/gitlab-ci-for-android-2021-update-2hhl</link>
      <guid>https://forem.com/javadlv/gitlab-ci-for-android-2021-update-2hhl</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR at the bottom
&lt;/h2&gt;

&lt;p&gt;I spent a few hours trying to set up Gitlab CI for our new project, only to be faced with a few errors when updating the version of SDK tools. Turns out the official documentation for Gitlab CI for android is outdated and still thinks it's 2018. So after doing a few trial and error and reading different StackOverflow threads, I tried updating the Gitlab CI documentation. Here's the &lt;strong&gt;outdated&lt;/strong&gt; version from 2018:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image: openjdk:8-jdk

variables:
  ANDROID_COMPILE_SDK: "28"
  ANDROID_BUILD_TOOLS: "28.0.2"
  ANDROID_SDK_TOOLS:   "4333796"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
  - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
  - unzip -d android-sdk-linux android-sdk.zip
  - echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" &amp;gt;/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" &amp;gt;/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" &amp;gt;/dev/null
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
  - chmod +x ./gradlew
  # temporarily disable checking for EPIPE error and use yes to accept all licenses
  - set +o pipefail
  - yes | android-sdk-linux/tools/bin/sdkmanager --licenses
  - set -o pipefail

stages:
  - build
  - test

lintDebug:
  stage: build
  script:
    - ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint

assembleDebug:
  stage: build
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
    - app/build/outputs/

debugTests:
  stage: test
  script:
    - ./gradlew -Pci --console=plain :app:testDebug

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  So what's changed?
&lt;/h3&gt;

&lt;p&gt;First off, &lt;code&gt;ANDROID_BUILD_TOOLS&lt;/code&gt; and &lt;code&gt;ANDROID_COMPILE_SDK&lt;/code&gt; should be updated to "30.0.3" and "30" respectively until the new version is released.&lt;br&gt;
The tricky part however is that &lt;code&gt;sdk-tools-linux&lt;/code&gt; is deprecated so the number from 2018 is as high as it gets you and it should be replaced with &lt;code&gt;commandlinetools&lt;/code&gt;. So on our before_script, we gotta change the URL to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then change the &lt;code&gt;ANDROID_SDK_TOOLS&lt;/code&gt; to &lt;code&gt;6858069_latest&lt;/code&gt; until a new version is out. you can find the number for future versions &lt;a href="https://developer.android.com/studio#downloads" rel="noopener noreferrer"&gt;here&lt;/a&gt; and navigating to &lt;em&gt;Command line tools only&lt;/em&gt; section.&lt;/p&gt;

&lt;p&gt;What comes next is that since the folder hierarchy for the new &lt;code&gt;commandlinetools&lt;/code&gt; is different from the old one, we need to add a flag to each &lt;a href="https://developer.android.com/studio/command-line/sdkmanager" rel="noopener noreferrer"&gt;sdkmanager&lt;/a&gt; command, and also change every path from &lt;code&gt;android-sdk-linux/tools/bin&lt;/code&gt; to &lt;code&gt;android-sdk-linux/cmdline-tools/bin&lt;/code&gt; so it should be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=. "platforms;android-${ANDROID_COMPILE_SDK}" &amp;gt;/dev/null
- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=. "platform-tools" &amp;gt;/dev/null
- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=. "build-tools;${ANDROID_BUILD_TOOLS}" &amp;gt;/dev/null
...
 - yes | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=. --licenses
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is another deprecation regarding &lt;a href="https://developer.android.com/studio/command-line/variables" rel="noopener noreferrer"&gt;Environmental Variables&lt;/a&gt; hence we should change &lt;code&gt;ANDROID_HOME&lt;/code&gt; to &lt;code&gt;ANDROID_SDK_ROOT&lt;/code&gt; &lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;the updated version would be this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;image: openjdk:8-jdk


variables:
ANDROID_COMPILE_SDK: "30"
ANDROID_BUILD_TOOLS: "30.0.3"
ANDROID_SDK_TOOLS: "6858069_latest"


before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
- wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}.zip
- unzip -d android-sdk-linux android-sdk.zip
- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=. "platforms;android-${ANDROID_COMPILE_SDK}" &amp;gt;/dev/null
- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=. "platform-tools" &amp;gt;/dev/null
- echo y | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=. "build-tools;${ANDROID_BUILD_TOOLS}" &amp;gt;/dev/null
- export ANDROID_SDK_ROOT=$PWD
- export PATH=$PATH:$PWD/platform-tools/
- chmod +x ./gradlew
# temporarily disable checking for EPIPE error and use yes to accept all licenses
- set +o pipefail
- yes | android-sdk-linux/cmdline-tools/bin/sdkmanager --sdk_root=. --licenses
- set -o pipefail


stages:
- build
- test


lintDebug:
stage: build
script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint


assembleDebug:
stage: build
script:
- ./gradlew assembleDebug
artifacts:
paths:
- app/build/outputs/


debugTests:
stage: test
script:
- ./gradlew -Pci --console=plain :app:testDebug
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>android</category>
      <category>ci</category>
      <category>gitlab</category>
      <category>sdk</category>
    </item>
  </channel>
</rss>
