Skip to content

Getting started with the code

Matthew Horan edited this page May 25, 2021 · 21 revisions

It's easy to start working on Weechat-Android. Please check with us on IRC before starting a substantial rewrite, though!

Writing code

First, fork this repo and install Android Studio. Once Android Studio is installed, open it and choose “Check out project from Version Control”, and paste the url of your fork there (something like https://github.com/<you>/weechat-android.git). Once gradle sync will be complete, you should be able to run the application on your device. You might also have to enable USB debugging on it.

Once you have a running build, you can start changing the code. It's useful to make a new git branch for your changes, like “feature-make-cookies”. Once you have your commits on your branch, you can send a pull request. We don't have any particular requirements for the code, just make sure it's more or less in line with the other code.

Useful links:

Cats

There's a dubious module cats that does the logging. In dev/release builds, it's mostly stripped away by ProGuard. You can use it like this:

  • Annotate a method with @Cat or @CatD to log it
  • Use @Cat(exit=true) to also log the execution time and the return value on the same line
  • Use @Cat(linger=true) to delay logging until the next log call, and print it on the same line. Use kitty.tracel() to append, and kitty.trace() to append and print.
  • Use kitty.trace("foo=%s", foo) to log foo. Exception information will be printed, if any.
  • Make kitty using final private @Root Kitty kitty = Kitty.make(). A @Root kitty will be used by @Cat, otherwise it will be made automatically. Use Kitty.make("Foo") to make a kitty with a different name, by default the class name is used. Kitties can be static. Do kitty.kid("Bar") to have a kitty with the tag Foo/Bar. Do kitty.prefix("prefix") to set a prefix that is printed on every line from that kitty.
  • Use res/raw/cats.txt to disable tags.

Making dev/release builds

Dev and release builds are necessary to see if the will work in a non-debug environment. In this builds, some code doesn't run, and some of it is stripped away by ProGuard. You will need to sign the app to make dev/release builds. Please see the instructions on how to do it in gradle.properties in the root folder.

Building via command line

Clone the repo and try building using Gradle:

git clone https://github.com/ubergeek42/weechat-android.git
cd weechat-android
./gradlew assembleDev

You will get this error if Java is not installed:

ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Or this error if Android SDK is not installed:

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 '.../weechat-android/local.properties'.

Install Android SDK, which should include Java, and try again:

sudo apt update && sudo apt install android-sdk
export ANDROID_SDK_ROOT=/usr/lib/android-sdk
./gradlew assembleDev

You will get an error such as the following:

Failed to install the following Android SDK packages as some licences have not been accepted.
     build-tools;29.0.2 Android SDK Build-Tools 29.0.2
     platforms;android-29 Android SDK Platform 29
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.

Install sdkmanager and the components as required. Get the latest tools on android.com:

wget https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
unzip commandlinetools-linux-6858069_latest.zip
sudo cmdline-tools/bin/sdkmanager --sdk_root=$ANDROID_SDK_ROOT "build-tools;29.0.2" "platforms;android-29"

If you try building again, the build will fail as Gradle needs a key to sign the apk:

Keystore file not set for signing config dev

You can create the key like this:

export STORE=my-keystore.jks
export ALIAS=weechat-android-dev
export STOREPASS=password
export KEYPASS=password
keytool -genkey -v -keystore $STORE -alias $ALIAS -keyalg RSA -keysize 2048 -validity 10000 -storepass $STOREPASS -keypass $KEYPASS

And configure Gradle to use it via properties:

echo devStorefile=`pwd`/$STORE >> ~/.gradle/gradle.properties
echo devStorePassword=$STOREPASS >> ~/.gradle/gradle.properties
echo devKeyAlias=$ALIAS >> ~/.gradle/gradle.properties
echo devKeyPassword=$KEYPASS >> ~/.gradle/gradle.properties

Or environment variables:

export ORG_GRADLE_PROJECT_devStorefile=`pwd`/$STORE
export ORG_GRADLE_PROJECT_devStorePassword=$STOREPASS
export ORG_GRADLE_PROJECT_devKeyAlias=$ALIAS
export ORG_GRADLE_PROJECT_devKeyPassword=$KEYPASS

Now you are ready to build the apk!

./gradlew assembleDev
ll app/build/outputs/apk/dev/app-dev.apk
-rwxrwxrwx 1 user user 3451292 Jan 1 00:00 app/build/outputs/apk/dev/app-dev.apk

You can also make a debug build using ./gradle assembleDebug and a release build using ./gradle assembleRelease, both unsigned.

Releasing new versions

To make a new release, including on F-Droid that requires a new version code and a tag:

  • Update version code and name in build.gradle.kts:
    versionCode = 1_04_00
    versionName = "1.4"
  • Add changes to a file named after version code at metadata/en-US/changelogs/10400.txt
  • Add the same changes to the Readme.md
  • If changing screenshots, optimize them first (win):
    for %i in (*.png) do pngout "%i" /k0 /force
  • Make a release
    git tag -a v1.4 -m "v1.4"
    git push --follow-tags

Translating

Please see us on the IRC channel regarding translations.

Any problems?

Our IRC channel is small but not dead. You are welcome on #weechat-android on irc.libera.chat.