――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
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.
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
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
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.
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
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.
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