cmeng-git / atalk-android

xmpp/jabber client for android
Apache License 2.0
155 stars 56 forks source link

F-Droid can't build #170

Closed licaon-kter closed 2 years ago

licaon-kter commented 3 years ago

You've hard coded the build tools paths :(

https://f-droid.org/wiki/index.php?title=org.atalk.android/lastbuild_1144&oldid=283988

I've tried to fix the recipe, but it's not done yet

  - versionName: 2.4.4
    versionCode: 1144
    commit: 2.4.4
    subdir: aTalk/
    patch:
      - build.patch
    gradle:
      - fdroid
    srclibs:
      - fmj@r122
      - jitsi-zrtp4j@7cbd8101108191089aad871002567c2a0eb2b512
    rm:
      - aTalk/lib/src_reference/
      - aTalk/jni/ffmpeg/android/
      - aTalk/jni/openssl/android/
      - aTalk/jni/vpx/android/
    prebuild:
      - sed -i -e "/clean.dependsOn 'ndkClean'/d" -e 's:/opt/android/android-sdk/ndk/20.0.5594570:$$NDK$$:'
        -e 's/20.0.5594570/20.1.5948944/' build.gradle
      - sed -i -e 's/STANDALONE_TOOLCHAINS=1;/STANDALONE_TOOLCHAINS=0;/' jni/static_library_built/ffmpeg-x264/_settings.sh
    scanignore:
      - aTalk/build.gradle
    scandelete:
      - aTalk/jni/static_library_built/libvpx/sources/*.gz
      - aTalk/third_party/m2/org/igniterealtime/smack/*/*/*.jar
    build:
      - export PATH=$$NDK$$/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH
      - pushd $$fmj$$
      - ant
      - popd
      - pushd $$jitsi-zrtp4j$$
      - ant jar
      - popd
      - mkdir -p lib/bundles
      - mv $$fmj$$/build/jars/fmj.jar lib/bundles/fmj-1.0-SNAPSHOT.jar
      - mv $$jitsi-zrtp4j$$/dist/zrtp4j-light.jar lib/bundles/zrtp4j-light-4.1.0-jitsi-1-SNAPSHOT.jar
      - pushd jni/static_library_built/ffmpeg-x264/
      - ./init_update_libs.sh
      - ./ffmpeg-atalk_build.sh
      - popd
      - mv jni/static_library_built/ffmpeg-x264/android/ jni/ffmpeg/
      - pushd jni/static_library_built/libvpx/
      - ./init_libvpx.sh
      - ./build-libvpx4android.sh
      - popd
      - mv jni/static_library_built/libvpx/output/android/ jni/vpx/
      - pushd jni/static_library_built/openssl/
      - ./init_libopenssl.sh
      - ./build-openssl4android.sh
      - popd
      - mv jni/static_library_built/openssl/output/android/ jni/openssl/
    ndk: r20b

build.patch

--- a/aTalk/jni/static_library_built/ffmpeg-x264/_settings.sh
+++ b/aTalk/jni/static_library_built/ffmpeg-x264/_settings.sh
@@ -30,9 +30,6 @@
 ANDROID_API=21
 NDK_ABI_VERSION=4.9

-# set STANDALONE_TOOLCHAINS to 0: SDK toolchains OR 1: standalone toolchains
-STANDALONE_TOOLCHAINS=1;
-
 # Built with command i.e. ./ffmpeg-android_build.sh or following with parameter [ABIS(x)]
 # Create custom ABIS or uncomment to build all supported abi for ffmpeg.
 # Do not change naming convention of the ABIS; see:
@@ -41,10 +38,6 @@
 ABIS=("armeabi-v7a" "arm64-v8a" "x86" "x86_64")

 BASEDIR=`pwd`
-# need to define earlier for standalone toolchains option
-# if [[ STANDALONE_TOOLCHAINS == 1 ]]; then
-#   TOOLCHAIN_PREFIX=${BASEDIR}/toolchain-android
-# fi

 #===========================================
 # Do not proceed further on first call without the required 2 parameters
@@ -130,37 +123,16 @@
   ;;
 esac

-if [[ ${STANDALONE_TOOLCHAINS} == 1 ]]; then
-  TOOLCHAIN_PREFIX=${BASEDIR}/toolchain-android
-  NDK_SYSROOT=${TOOLCHAIN_PREFIX}/sysroot
-  CC_=clang
-  CXX_=clang++
-
-  if [[ ! -e ${TOOLCHAIN_PREFIX}/${NDK_ABIARCH} ]]; then
-    rm -rf ${TOOLCHAIN_PREFIX}
-
-    # Create standalone toolchains for the specified architecture - use .py instead of the old .sh
-  # However for ndk--r19b => Instead use:
-  #    $ ${NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++ src.cpp
-  # cmeng: must ensure AS JNI uses the same STL library or "system" if specified
-    [[ -d ${TOOLCHAIN_PREFIX} ]] || python ${NDK}/build/tools/make_standalone_toolchain.py \
-      --arch ${NDK_ARCH} \
-      --api ${ANDROID_API} \
-      --stl libc++ \
-      --install-dir=${TOOLCHAIN_PREFIX}
-  fi
-else
-  TOOLCHAIN_PREFIX=${ANDROID_NDK}/toolchains/${NDK_ABIARCH}-${NDK_ABI_VERSION}/prebuilt/linux-x86_64
-  NDK_SYSROOT=${ANDROID_NDK}/platforms/android-${ANDROID_API}/arch-${NDK_ARCH}
-  CC_=gcc
-  CXX_=g++
-fi
+CC_=clang
+CXX_=clang++
+TOOLCHAIN_PREFIX=${ANDROID_NDK}/toolchains/${NDK_ABIARCH}-${NDK_ABI_VERSION}/prebuilt/linux-x86_64
+NDK_SYSROOT=${ANDROID_NDK}/platforms/android-${ANDROID_API}/arch-${NDK_ARCH}

 # Define the install directory of the libs and include files etc
 # lame needs absolute path
 PREFIX=${BASEDIR}/android/$1

-# Add the standalone toolchain to the search path.
+# Add the [5~standalone toolchain to the search path.
 export PATH=${TOOLCHAIN_PREFIX}/bin:$PATH
 export CROSS_PREFIX=${TOOLCHAIN_PREFIX}/bin/${NDK_ABIARCH}-
 export CFLAGS="${CFLAGS}"
cmeng-git commented 3 years ago

Previously the aTalk build.gradle, the ndk-tool path is specified in local.properties file i.e. ndk.dir=/opt/android/android-sdk/ndk/20.0.5594570; then this is referred to by using def ndkDir = android.ndkDirectory

However in the latest android studio, it gives the following warning when it was specified in local.properties. Android recommended method requires the use of "externalNativeBuild{}", but it is having problem as reported in: [163379002 Gradle externalNativeBuild script has problem in recognizing last include statement in Android.mk file] (https://issuetracker.google.com/issues/163379002). So the only option aTalk has right now is to specify and hard coded the ndkDir in the build.gradle. Not sure if anybody can provide an alternate solution without hard coded the path in build.gradle.

externalNativeBuild {
    ndkBuild {
        path file('jni/Android.mk')
    }
}

Warning from android studio build process:

NDK was located by using ndk.dir property. This method is deprecated and will be removed in a future release. Please delete ndk.dir from local.properties and set android.ndkVersion to [20.0.5594570] in all native modules in the project. https://developer.android.com/r/studio-ui/ndk-dir

cmeng-git commented 3 years ago

Please use v2.4.5 for Fdroid build. I have removed the hard coded path in the build.gradle.

licaon-kter commented 3 years ago

Nope https://f-droid.org/wiki/index.php?title=org.atalk.android/lastbuild_1145&oldid=284305

cmeng-git commented 3 years ago

Prior to aTalk v2.4.4 build, aTalk build.gradle uses the ndk.dir specified in the local properties; i.e. ndk.dir=/opt/android/android-sdk/ndk-bundle

==== local.properties =====
ndk.dir=/opt/android/android-sdk/ndk-bundle
sdk.dir=/opt/android/android-sdk

Actually the ndk-bundle directory always contains the android latest ndk released version as android studio is being upgraded. Recently AS has deprecated the support for ndk.dir; it now requires the ndk version to be specified in aTalk build.gradle and use the externalNativeBuild method instead as shown below:

    // aTalk is only compatible to ndkVersion '20.0.5594570' max version
    ndkVersion '20.0.5594570'

    externalNativeBuild {
        ndkBuild {
            path file("jni/Android.mk")
        }
    }

All the android ndk release versions are saved in the respective directories, relative to sdk.dir=/opt/android/android-sdk as shown below. Fdroid build scripts need to be modified i.e. remove the ndk.dir in the local.properties to use the new aTalk build.gradle.

image

I see that fdroid build continues to use the local.properties method. If fdroid build process allowed and not in conflict with aTalk build.gradle, then you must download the correct ndk version and update the ndk.dir to: i.e. ndk.dir=/opt/android/android-sdk/ndk/20.0.5594570 so the version is the same as the one specified in the aTalk build.gradle.

2020-12-23 07:30:49,128 INFO: Updating local.properties file at build/org.atalk.android/local.properties 2020-12-23 07:30:49,128 INFO: Creating local.properties file at build/org.atalk.android/aTalk/local.properties 2020-12-23 07:30:49,128 INFO: Updating local.properties file at build/org.atalk.android/aTalk/local.properties

NDK from ndk.dir at /home/vagrant/android-ndk/r15c had version [15.2.4203891] which disagrees with android.ndkVersion [20.0.5594570]

Note: you cannot use this ndk version specified in build.gradle to build all the other native .so libraries used in aTalk, it is not compatible with the respective native library source.

cmeng-git commented 3 years ago

Sorry, is Fdroid team still having problem with aTalk 2.4.5 build, even with the hard-coded path removed. Kindly revert to me if you need further assistance.

licaon-kter commented 3 years ago

As the recipe changes show it needs more modifications, and I didn't get around to test them.

cmeng-git commented 3 years ago

Please let me known me if the team still needs help.

I think the solution may just be copying all the files in android ndk directory for version 20.0.5594570, to the directory of the ndk.dir specified in the local.properties file. So the ndk version matches build.gradle version specified when gradle build the apk.

cmeng-git commented 3 years ago

Please advice if Fdroid team still facing problem with the aTalk build. The latest aTalk release is v2.6.1.

linsui commented 3 years ago

I tried to build 2.6.1 but failed. See https://gitlab.com/linsui/fdroiddata/-/jobs/1351970271. x264 armv7 is built but armv8 failed. Could you please take a look? Thanks!

cmeng-git commented 3 years ago

The 4 jni libraries i.e. ffmpeg, x264, openssl, and libvpx, use in aTalk actually need to undergo 2 build processes. a. Building the respective module static libraries i.e. .a using external scripts and configure file b. During Android Studio apk build, all the pre-built (a) static libraries are then built into shared libraries i.e. .so for use in aTalk.

Except for openssl, all the other 3 static libraries configure scripts support build via standalone ndk only; So far ANDROID_NDK=/opt/android/android-ndk-r18b has been verified working for all the 3 *.a static libraries built.

For the error log, found that fdroid is trying to use android pre-built ndk, i.e. /opt/android-sdk/ndk/20.0.5594570 for x264. This seems to be cause of the problem. You may refer to aTalk shell scripts for the building of ffmpeg-x264 static libraries.


Use NDK=/opt/android-sdk/ndk/20.0.5594570

Use ANDROID_API=21

Install directory: PREFIX=/builds/linsui/fdroiddata/build/org.atalk.android/aTalk/jni/static_library_built/ffmpeg-x264/../../ffmpeg/android/arm64-v8a


linsui commented 3 years ago

Thanks! https://gitlab.com/fdroid/fdroiddata/-/merge_requests/9279