Build a Kotlin app using OpenJDK's Docker container

Background

――I'm doing Android development with Kotlin, but it's getting troublesome to build with Android Studio every time. --Since I'm using gitlab, let's use gitlabci (I don't think it's necessary this time because the runner was already set in another project) --First, let's try to build from the container manually

Docker installation

It's a development Mac I got recently, so I didn't have Docker yet orz I won't write anything here, so I'll omit it.

Until container startup

This time I will use openjdk8 The reason is that this is the default used in git labci's Android template YAML, and it saves you the trouble of installing JAVA packages (though I think it is used).

First pull as usual Version specification is required

docker pull openjdk:8-jdk

And start the container

docker run -it openjdk:8-jdk

Required package installation

If you do the above, I think that it will be automatically put in the container, so I will install the package

apt-get --quiet update --yes
apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1

export ANDROID_COMPILE_SDK=28
export ANDROID_BUILD_TOOLS=29.0.3
export ANDROID_SDK_TOOLS=6514223
export ANDROID_HOME="/android-home"

install -d $ANDROID_HOME
wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip

pushd $ANDROID_HOME
unzip -d cmdline-tools cmdline-tools.zip
popd
export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/

sdkmanager --version

yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses || true
sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-${ANDROID_COMPILE_SDK}"
sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;${ANDROID_BUILD_TOOLS}"

chmod +x ./gradlew

I think it's okay to check if there are any errors on the console and check the environment variables with printenv just in case.

git clone Bring the source code to build into the container This is just a clone, so omit it

Build execution

The build itself is easy, just hit the Gradle command

./gradlew assemble

If you want to use variants and flavor, please change the command I referred to here.

However, if this is left as it is, an error will occur and it will not work. I stumbled here, so I would like to introduce two points.

Create local.properties

The following error occurred when building

「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」

It looks like an error like "The SDK location is not written in local properties"

I searched for local properties as I was told but couldn't find them

When I was using Android Studio, I wasn't aware of it because it was created by myself (probably), but it seems that I have to create local properties and describe the location of the SDK.

I didn't put vim in the first place, so it's from there ^^;

apt-get install vim

Go to the top folder of the app

vi local.properties

The contents are like this

## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Wed Jan 07 15:34:05 JST 2015
sdk.dir=/android-home

Now I hit the build command again, but this time I get another error

Memory upper limit released

The next error is 「Could not connect to kotlin daemon. Using fallback strategy.」 Contents

When I looked it up, it seems that the memory went up to the upper limit and Daemon died.

Click the whale mark on the status bar of your Mac and change the settings from the docker app to increase the maximum memory. For details on how to do this, I referred to here.

Build successful! !!

Finally the letters "BUILD SUCCESSFUL"!

I'm worried that I wasn't asked for the signature when building, so I'll add that later. I thought it was because of Debug, but when building with Android Studio, I can not say anything because both Release and Debug need to be signed.

I didn't create a docker file this time The reason is that it is listed in gitlabci.yaml

next time

--Automatic build when committing from git labci --Build with variants and flavor

I wish I could make a hit

that's all Thank you for your relationship

Recommended Posts

Build a Kotlin app using OpenJDK's Docker container
Quick build maven project using maven docker container
Build a container for Docker x Laravel phpMyAdmin
Build a docker container for a python simple web server
[Docker] Build an Apache container on EC2 using dockerfile
Try to build a Java development environment using Docker
[2021] Build a Docker + Vagrant environment for using React / TypeScript
multi-project docker build using jib
Build a container that automatically formats Docker x Laravel code
Try Hello World using plain Java on a Docker container
Build a Node.js environment with Docker
Run React on a Docker container
Run PureScript on a Docker container
How to build CloudStack using Docker
Build WebRTC Janus with Docker container
[App development 0.5] [Node.js express Docker] Build an environment for Node.js Express MongoDB using Docker
Build a browser test environment using Capybara in the Docker development environment
Create a web environment quickly using Docker
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Build a WAS execution environment from Docker
Build an authentication proxy server using Docker
Build a Wordpress development environment with Docker
I made a rock-paper-scissors app with kotlin
Docker container build fails to install php-radis
Template: Build a Ruby / Rails development environment with a Docker container (Ubuntu version)
Build by specifying docker as a file
I made a bulletin board using Docker 1
Template: Build a Ruby / Rails development environment with a Docker container (Mac version)
Build a simple Docker + Django development environment
[App development 1] [Node.js express Docker] Build an environment for Node.js Express MongoDB (mongoose) using Docker [December 2020]
Up to the point of launching a Docker container built using RedHat Quarkus
Test, build, and push your Docker image to GitHub Container Registry using GitHub Actions
Build a development environment for Docker + Rails6 + Postgresql
Build a test flow on CircleCI using Jib
How to get a heapdump from a Docker container
Building a CICD pipeline using Docker (personal memorandum)
Build a WordPress development environment quickly with Docker
Write to a file using ShiftJIS-Read a file (Kotlin / JVM)
Build a streaming server on your iOS app
I made a Docker container to run Maven
Send emails using Docker container on Raspberry Pi 3
Build a simple Docker Compose + Django development environment
I tried running Ansible on a Docker container
Build a development environment for Docker, java, vscode
Try using another Servlet container Jetty with Docker
Docker Container pull has a rate limit enforced
Ssh connect using SSHJ from a Java 6 app
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
Build a local development environment for Open Distro for Elasticsearch with multiple nodes using Docker
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
Small Docker container
Quick build maven project using maven docker container
Build a Kotlin app using OpenJDK's Docker container
Send emails using Docker container on Raspberry Pi 3
Try using another Servlet container Jetty with Docker
Small Docker container
Run the Android emulator on Docker using Android Emulator Container Scripts
[Docker] Build an Apache container on EC2 using dockerfile
Create a portfolio app using Java and Spring Boot
Create a docker image that runs a simple Java app
[Road _node.js_1-1] Road to build Node.js Express MySQL environment using Docker
A simple CRUD app made with Nuxt / Laravel (Docker)
How to build Docker + Springboot app (for basic learning)
Practice making a simple chat app with Docker + Sinatra
Easily build Redmine on Windows using WSL2 and Docker
Easily build a Vue.js environment with Docker + Vue CLI
Create a Chat app with WebSocket (Tyrus) + libGDX + Kotlin