Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the App #5

Open
rodillo69 opened this issue Jan 21, 2021 · 14 comments
Open

Get the App #5

rodillo69 opened this issue Jan 21, 2021 · 14 comments

Comments

@rodillo69
Copy link

Hi! where to find the td5 tester.apk? because i was trying to import the project to Android Studio to be able to package it and make the .apk file, but it says that there are some missing files.?¿?¿?

@originalheff
Copy link

what files are missing ? You have the source downloaded ?

@Lucanio4
Copy link

I downloaded the source.
Downloaded and installed Android Studio.
Can't even build the project.....

@originalheff
Copy link

what error are you getting ? i compiled a version last month without any issues.

@Aloike
Copy link

Aloike commented Oct 29, 2021

Hi @Lucanio4 , Thank you for the detailed bug report. 🙃

@originalheff, I tried to build the app (master branch, heads/master-0-gcc79c5e) into a container from scratch, and I had some errors related to Lint. I struggled to make Lint work (dunno why, it wasn't able to find the Android API). Anyway, my quick and dirty solution was to disable the "abort on error" option. Here is the patch:

diff --git a/app/build.gradle b/app/build.gradle
index d843ae4..7d4890f 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -17,6 +17,9 @@ android {
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
     }
+    lintOptions {
+        abortOnError false
+    }
     productFlavors {
     }
 }

To test it into a container (on a Linux host), I created a docker directory at the root of the git repository that looks like this:

[root of the Git clone]
├── app/
├── build/
├── docker/
│   ├── 110-docker_image_build.sh
│   ├── 210-run.sh
│   ├── Dockerfile
│   ├── rsrc/
│   │   └── entrypoint.sh
│   └── variables.sh
├── docs/
├── gradle/
└── (other project files)

The two main Bash scripts 110-docker_image_build.sh and 210-run.sh respectively create the docker image from the Dockerfile configuration and run a container from the generated image. A complementary file variables.sh defines a few variables common to both scripts.

The Dockerfile starts from a Ubuntu image and runs some commands to install system dependencies (+ some tools) then the Android SDK . It also adds the entrypoint.sh script. This one will just call the gradlew build command in the project's directory with some options.

This is clearly dirty made, just to have an idea of what's happening in a controlled environment.

The files:

110-docker_image_build.sh
#!/bin/bash

set -e


source variables.sh


# Build the image
docker build \
	--build-arg GRADLE_VERSION=${DOCKER_ANDROIDENV_GRADLE_VERSION} \
	--build-arg ANDROID_API_LEVEL=${DOCKER_ANDROIDENV_ANDROID_API_LEVEL} \
	--build-arg ANDROID_BUILD_TOOLS_LEVEL=${DOCKER_ANDROIDENV_ANDROID_BUILD_TOOLS_LEVEL} \
	--tag ${DOCKER_ANDROIDENV_IMAGENAME} \
	.


exit $?

210-run.sh
#!/bin/bash

# set -e


source variables.sh


PROJECT_DIR_TOPLEVEL=../

# Enter the top level of your project directory
# pushd ${PROJECT_DIR_TOPLEVEL}

PROJECT_DIR_TMP=`mktemp --directory /tmp/docker-android-build_XXX`

echo "########################################"
echo "#    PROJECT_DIR_TMP='${PROJECT_DIR_TMP}'"
echo "########################################"

cp -r "${PROJECT_DIR_TOPLEVEL}" "${PROJECT_DIR_TMP}"

DIR_CACHE=/tmp/${DOCKER_IMAGE_NAME}/cache
mkdir -p "${DIR_CACHE}"

DIR_CACHE_ANDROID=${DIR_CACHE}/android
DIR_CACHE_GRADLE=${DIR_CACHE}/gradle


# Run the container
docker run \
	--privileged \
	-it \
	--rm \
	--env GRADLEW_OPTIONS="${DOCKER_ANDROIDENV_GRADLE_OPTIONS[@]}" \
	-v ${PROJECT_DIR_TMP}:/workspace/project \
	${DOCKER_ANDROIDENV_IMAGENAME} #\
	# -v ${DIR_CACHE_ANDROID}:/root/.android \
	# -v ${DIR_CACHE_GRADLE}:/root/.gradle/ \
	# -v $PWD:/workspace/project \
	# bash -c ". /workspace/emulator_start.sh && gradlew build -p /workspace/project"

exit_code=$?

# If no error occured, remove the temporary directory (otherwise keep it for debug)
if [[ "${exit_code}" -eq "0" ]]
then
        echo "Deleting '${PROJECT_DIR_TMP}'..."
	rm -rf "${PROJECT_DIR_TMP}"
fi

exit ${exit_code}

variables.sh
#!/bin/sh

DOCKER_IMAGE_NAME_PREFIX=android-env

DOCKER_ANDROIDENV_GRADLE_VERSION=3.3
DOCKER_ANDROIDENV_GRADLE_OPTIONS+=('--info')

# DOCKER_ANDROIDENV_ANDROID_API_LEVEL=28
DOCKER_ANDROIDENV_ANDROID_API_LEVEL=25

# DOCKER_ANDROIDENV_ANDROID_BUILD_TOOLS_LEVEL=28.0.3
DOCKER_ANDROIDENV_ANDROID_BUILD_TOOLS_LEVEL=26.0.2
DOCKER_ANDROIDENV_IMAGENAME=${DOCKER_IMAGE_NAME_PREFIX}_gradle-${DOCKER_ANDROIDENV_GRADLE_VERSION}_android-${DOCKER_ANDROIDENV_ANDROID_BUILD_TOOLS_LEVEL}

Dockerfile
##  @see    https://betterprogramming.pub/build-a-lightweight-docker-container-for-android-testing-2aa6bdaea422

FROM ubuntu:latest



SHELL ["/bin/bash", "-c"]


# ##############################################################################
#   Install system packages
# ##############################################################################

# https://serverfault.com/a/1016972 : To make the `tzdata` package install.
ARG DEBIAN_FRONTEND="noninteractive"
# ENV TZ="Europe/London"


#   APT dependencies
RUN     apt update \
    &&  apt install -y \
            git \
            libasound2 \
            libc6 \
            libglu1 \
            libnss3 \
            libpulse-dev \
            libstdc++6 \
            libx11-6 \
            libx11-xcb1 \
            libxcb1 \
            libxcomposite1 \
            libxcursor1 \
            libxi6 \
            libxtst6 \
            openjdk-8-jdk \
            unzip \
            vim \
            wget


# ##############################################################################
#   Install SDK packages
# ##############################################################################

#   Gradle
ARG GRADLE_VERSION=6.9.1

RUN     wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-bin.zip -P /tmp \
    &&  unzip -d /opt/gradle /tmp/gradle-${GRADLE_VERSION}-bin.zip \
    &&  mkdir /opt/gradlew \
    &&  /opt/gradle/gradle-${GRADLE_VERSION}/bin/gradle wrapper --gradle-version ${GRADLE_VERSION} --distribution-type all -p /opt/gradlew  \
    &&  /opt/gradle/gradle-${GRADLE_VERSION}/bin/gradle wrapper -p /opt/gradlew

ENV GRADLE_HOME=/opt/gradle/gradle-$GRADLE_VERSION


#   Android SDK
ARG ANDROID_API_LEVEL=28
ARG ANDROID_BUILD_TOOLS_LEVEL=28.0.3

RUN     wget 'https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip' -P /tmp \
    &&  unzip -d /opt/android /tmp/sdk-tools-linux-4333796.zip \
    &&  yes Y | /opt/android/tools/bin/sdkmanager --install "platform-tools" "system-images;android-${ANDROID_API_LEVEL};google_apis;x86" "platforms;android-${ANDROID_API_LEVEL}" "build-tools;${ANDROID_BUILD_TOOLS_LEVEL}" "emulator" \
    &&  yes Y | /opt/android/tools/bin/sdkmanager --licenses \
    &&  echo "no" | /opt/android/tools/bin/avdmanager --verbose create avd --force --name "test" --device "pixel" --package "system-images;android-${ANDROID_API_LEVEL};google_apis;x86" --tag "google_apis" --abi "x86"

ENV ANDROID_HOME=/opt/android/

ENV PATH "$PATH:$GRADLE_HOME/bin:/opt/gradlew:$ANDROID_HOME/emulator:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools"
ENV LD_LIBRARY_PATH "$ANDROID_HOME/emulator/lib64:$ANDROID_HOME/emulator/lib64/qt/lib"



# ##############################################################################
#   Set the entry point
# ##############################################################################

ENV     DIR_WORKSPACE=/workspace
ENV     DIR_PROJECT=${DIR_WORKSPACE}/project

# Set the working directory
RUN     mkdir -p ${DIR_WORKSPACE}
WORKDIR ${DIR_WORKSPACE}

# Add entry point
COPY    rsrc/entrypoint.sh  ${DIR_WORKSPACE}
RUN     chmod +x ${DIR_WORKSPACE}/entrypoint.sh
ENTRYPOINT [ "/workspace/entrypoint.sh" ]

entrypoint.sh
#!/bin/bash

set -e


# ------------------------------------------------------------------------------
# Build the project
# ------------------------------------------------------------------------------
echo "########################################"
echo "#    Build the project"
echo "########################################"

gradlew build \
	-p ${DIR_PROJECT} \
	--stacktrace \
	${GRADLEW_OPTIONS}
	# --warning-mode all      #< to show the individual deprecation warnings.
	# --scan  \   #< to get full insights.


exit $?

To run it, just go into the docker directory and call the scripts.

cd docker/

# Build the image.
# It will download and install system dependencies and Android SDK on a Ubuntu base image.
bash 110-docker_image_build.sh

# Build the project.
# It will:
# + copy the sources into a temporary directory,
# + mount the temporary project dir into the container
# + Attempt to build the project using `gradlew`
bash 210-run.sh

# A message should telle whether  the build was successful or not.
# On success, the temporary directory will be deleted (otherwise will be kept for debug).

Please note that it will use a lot of disk space (5-6 GB), and will take quite some time depending on your host resources and internet connection bandwidth.

@Lucanio4
Copy link

Lucanio4 commented Oct 29, 2021 via email

@originalheff
Copy link

originalheff commented Oct 29, 2021 via email

@Lucanio4
Copy link

Lucanio4 commented Oct 29, 2021 via email

@Aloike
Copy link

Aloike commented Oct 29, 2021

@originalheff It definitely is related to the container/env, but I'm not familiar enough with Lint 😅 Anyway, it built successfully when disabling Lint, so it should be reasonably possible to build in an environment other than yours. 👍

On my Linux host, with Android Studio I get some errors related to the compile 'com.android.support:appcompat-v7:25.3.1' line from the file app/build.gradle. I ran into this last year when I spent some time on https://github.com/Td5OpenDiag/Td5OpenDiag-android.

@Lucanio4 :

  • It will work on your model. As long as it's a Td5, it will be fine. Some values might not be available, though.
  • To change from USB to bluetooth, you probably will have to rewrite most of the back-end.
  • My Android Studio "has lived", so I definitely don't know what I've locally done (hence my attempt at building in a container from scratch).

What's your environment ?

I don't have much more time right now to dig into it, but I'd be interested in better understanding what's happening and how to fix it (at least on Linux).

@Lucanio4
Copy link

Lucanio4 commented Oct 29, 2021 via email

@Lucanio4
Copy link

Lucanio4 commented Oct 29, 2021 via email

@Lucanio4
Copy link

Lucanio4 commented Oct 30, 2021 via email

@Lucanio4
Copy link

Hi @Aloike
Were you able to create the APK file?
Regards

@Aloike
Copy link

Aloike commented Mar 29, 2022

Hi @Lucanio4 ,
Sorry for the late reply, I've struggled a little bit to find some time to work on this project.

Yes, I can build the APK file. File attached.

Td5OpenDiag.zip

Please note:

  • You currently need to uninstall any other version of the app before installing the new one ;
  • This apk comes from an "untrusted" source, so you'll probably have to update your mobile device's security settings, or get into developer mode.

I've been able to install it using both ADB (adb -d install app-debug.apk) and by uploading it on the phone through the USB file sharing, then installing it from the phone.

I can build it through my Android Studio install, but I wanted to provide a solution that could work on any platform, and define a reference environment/commands for building/testing the app, with an emphasis on repeatability to gently move towards continuous integration.
So I'm currently setting up a Docker image with all the required Android dependencies. This will let anyone that wants to build the app to do so in a reference environment.
I'll provide this update in the new repository: https://github.com/Td5OpenDiag/Td5OpenDiag-android
The repo above is just a fork from this one, with a few more people involved (including Hairyone).

G'day!

Aloike added a commit to Td5OpenDiag/Td5OpenDiag-android that referenced this issue Mar 29, 2022
Related to hairyone/TD5Tester#5.

Merge branch 'hairyone_TD5Tester_issue-0005-get_the_app' into dev-master
@Aloike
Copy link

Aloike commented Mar 29, 2022

Merged here: https://github.com/Td5OpenDiag/Td5OpenDiag-android/tree/dev-master

The Dockerfile provides all commands required to setup an Ubuntu system from scratch to build Android apps on it.

Some complementary scripts are available under the scripts directory. They should provide enough automation (at least on Linux) to build the app in a docker container and to deploy the app on a mobile device.

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants