aprsdroid icon indicating copy to clipboard operation
aprsdroid copied to clipboard

Updating APRSdroid build system to modern toolchain

Open penguin359 opened this issue 5 years ago • 11 comments

I am interesting in helping contribute to APRSdroid, but have always been held back by trying to get a working toolchain for it. I've finally take a serious effort to getting it working and this here is to help document that and discuss updating it's various pieces. First of all, everything in the Wiki still appears to be correct and valid, but important details are missing.

https://github.com/ge0rg/aprsdroid/wiki/Developer

The first issue is that this requires the old, deprecated Apache Ant build system that was dropped as a part of the move to Android Studio. It took some searching, but I found this with links to the last version of ADT released by Google:

https://stackoverflow.com/a/27682695/681359

I would like to see this migrated to the new Gradle build system, but that may be a non-trivial change due to the use of a non-first-class language. I have not investigated yet. Next, this is targeting Android API level 19 which requires that to be downloaded. As this is getting quite old, it will be nice to bump this as well, but this is a relatively minor consideration. Next, it requires grabbing ProGuard and Scala. It's links to the SourceForge page for ProGuard, but the newest releases have been moved to Github now. It also mentions requiring Scala 2.8.2 as the last version tested. I tried the latest 2.13.3, but that complained about missing build files. Using 2.8.2 from their archives seemed to work, however.

https://scala-lang.org/files/archive/scala-2.8.2.final.tgz https://github.com/Guardsquare/proguard/archive/proguard6.2.2.zip

Next, it requires a separate clone of PacketDroid, however, this seems like a good case to use Git submodules. That might be a simpler way to handle that and it will link to a specific commit of that repo so it should always be a build-able combination. The wiki also mentions creating symlinks, but those already seem to be in-place from Git so are unnecessary. I did not have any issues using the latest NDK 21d. Next up, it appears that Java 1.7 is required for build. Using Java 1.8, I was getting build errors against AnnotatedElement and CharSequence. When pulling the latest copy of Java 1.7.0u80 from the archives, I found it was incompatible with my installed copy of Apache Ant. I found that Ant 1.10.8 does not compile against Java 1.7 so I had to pull the older 1.9.15 to get a version of Apache Ant I could compile and use with Java 1.7.

https://downloads.apache.org/ant/source/apache-ant-1.9.15-src.tar.bz2

With all of this and the instructions from the Wiki, I have been able to get it down to two build errors. One was in sendPacket(APRSPacket, String) of AprsService and the other was in stop() of TcpUploader. To get past the build errors, I have just commented out the body of those functions while I disect the errors. With those commented out, I finally got ant debug to pump out an APK for me.

Oh, and I was getting build errors for string resources in values-{kab,lij,nan}. As far as I know, it should always have two letter country names there, but I haven't looked into it in detail. Deleting those folders got past the errors for the mean time.

The two big issues I would like to see fixed is support for the current Gradle build system recommended by Google and support for Java 1.8 which should help future developers in getting a build environment set up. I'd like to do a fresh install also and update the Wiki with the current build procedures to help anyone else get up and running with the current state of affairs.

penguin359 avatar Aug 28 '20 09:08 penguin359

Hi,

it's great to see new activity in the project. I'm currently working on the https://github.com/ge0rg/aprsdroid/tree/google-maps-v2 branch, which is already fully migrated to gradle. The documentation on the wiki is really outdated, feel free to update it according to the updates in https://github.com/ge0rg/aprsdroid/issues/225#issuecomment-473575016 and https://github.com/ge0rg/aprsdroid/issues/225#issuecomment-673954816.

Please check if it fixes all (or at least most) of your issues, and sorry for this being rather non-obvious.

I'll soon move the master branch to the google-maps-v2 state, however I didn't consider it polished enough yet ;)

ge0rg avatar Aug 28 '20 10:08 ge0rg

OK, maybe I'm on a bad branch then, but just in case it makes any difference, I did a little more tracking of those last build errors. It seems to resolve around this line:

implicit val ec = scala.concurrent.ExecutionContext.global

Because ExecutionContext was not added until Scala 2.10 from what I can tell on their website. However, using Scale 2.10 or newer produces some kind of build system error. On 2.10.7, I get this:

taskdef A class needed by class scala.tools.ant.FastScalac cannot be found: scala/reflect/internal/settings/AbsSettings

I'll checkout that other branch though.

penguin359 avatar Aug 28 '20 10:08 penguin359

I've just hard-reset the master branch to the latest code, it comes with some more improvements, but the NDK build still needs to be run manually:

ndk-build -B V=1 NDK_LOG=1 APP_ABI=all -C .

ge0rg avatar Aug 28 '20 19:08 ge0rg

OK, and, by the way, what versions of each component are you running? That ExecutionContext error looks like you've upgraded Scala to at least 2.10 in order to use it. Might as well save myself some time if you have that handy.

penguin359 avatar Aug 28 '20 20:08 penguin359

Also, what language would you like completely fresh code written in? Scala? Or would you prefer to using Kotlin for completely fresh sections of code?

Once thing I would like to add is some testing modules that can either run logic like packet decode on the development host indenendent of Android or full end-to-end instrumentation testing on Android with appropriate mocks.

penguin359 avatar Aug 28 '20 22:08 penguin359

I'm using Gradle 5.6.2 for the build. The other versions, like Scala 2.11.12, should all be referenced from build.gradle.

I'll gladly accept new code either in Scala or in Kotlin, which I haven't looked into yet, but it can't be that different ;)

If you want to create test cases for packet decoding, you might also have a look at https://github.com/ab0oo/javAPRSlib which I'm using to parse and to generate packets. There you should stick to Java though.

ge0rg avatar Aug 29 '20 17:08 ge0rg

I wish I would have seen that message earlier. It's been far more frustrating to get this new branch to compile correctly than it should be. I'll be publishing a detailed set of build instructions shortly. I initially tried using Gradle 4 which is the latest version that comes with Ubuntu. They seem to be a little behind the times. However, that failed so I grabbed a more up-to-date Gradle 6.6.1 from the website only to discover different build errors, but it was not very obvious that those were caused by an incompatible Gradle version. Eventually, I determined that that was the culprit and dropped back to the bare minimum of 5.4.1 until I eventually settled on 5.6.1 as being the most compatible. Seems pretty close to what you are using.

I also had to disable the triplet.play plugin in the Gradle build file because it kept trying to access something without proper credentials getting a 401 not authorized error and failing even a basic build. However, Travis CI seems to be happy with those lines still enabled so I'll leave it for now until I figure out how to fix it properly.

The error I got for not having my ANDROID_HOME defined properly was completely non-intuitive. And then having the build fail because the licenses had not been accepted yet, etc, etc, etc. I also am getting lint errors so I have that turned off and the srcDir lines for Scala were causing issues as per the comment in the build.gradle file. However, I did not read it carefully and commented out the whole chunk causing build errors about missing resources.

It's been a long day, but I should have repeatable build instructions now for building from a completely scratch system. I also have working Travis CI integration now. I'll be sending in a pull request in shortly.

https://travis-ci.org/github/penguin359/aprsdroid/builds/722416098

penguin359 avatar Aug 30 '20 04:08 penguin359

The error you get for not having $ANDROID_SDK_ROOT set correctly:

A problem was found with the configuration of task ':lint'.

No value has been specified for property 'lintClassPath'.

Very intuitive...

penguin359 avatar Aug 30 '20 04:08 penguin359

Now that I have a repeatable build, I was able to wipe it out and build without reproducing the error with Gradle Play Publisher. There must have been something cached in a funny state. I can build completely without any changes from the travis-ci branch. OK, now to get on to the fun stuff!

penguin359 avatar Aug 30 '20 06:08 penguin359

Just for documentation purposes, here's my zero to sixty build script for APRSdroid. It should work on a completely fresh Linux system. I've made a few updates to the Wiki, but it still has some errors and is a little incomplete. I still need to look into how ProGuard works with the current build system. Also, this script depends upon an unsubmitted pull request to get the Google Maps API key to work, but will still build without working Google Maps.

#!/bin/sh
  
set -e

cmdline_tool_file="commandlinetools-linux-6609375_latest.zip"

export ANDROID_SDK_ROOT="$(pwd)/android"
mkdir -p "${ANDROID_SDK_ROOT}"
wget "https://dl.google.com/android/repository/${cmdline_tool_file}"
unzip "${cmdline_tool_file}" -d "${ANDROID_SDK_ROOT}/cmdline-tools"
rm -f "${cmdline_tool_file}"
export PATH="${ANDROID_SDK_ROOT}/cmdline-tools/tools/bin:${PATH}"
mkdir "${ANDROID_SDK_ROOT}/licenses"
echo 24333f8a63b6825ea9c5514f83c2829b004d1fee > "${ANDROID_SDK_ROOT}/licenses/android-sdk-license"
echo 84831b9409646a918e30573bab4c9c91346d8abd > "${ANDROID_SDK_ROOT}/licenses/android-sdk-preview-license"
#git clone [email protected]:ge0rg/aprsdroid.git
git clone -b travis-ci [email protected]:penguin359/aprsdroid.git
cd aprsdroid
git submodule update --init --recursive
echo "mapsApiKey=Ab..." > local.properties
./gradlew build connectedCheck
./gradlew installDebug

With that, the original issue is resolved. I would like to discuss some changes to the source code structure or build system to support unit testing and instrumentation, but that might be better on a new issue.

penguin359 avatar Aug 30 '20 18:08 penguin359

Has anyone successfully compile the app with the current code? There's so little detail about anything, and it seems overly complex and outdated. Looking to compile with some changes and to play around.

na7q avatar Nov 25 '23 19:11 na7q