Skip to content

Commit

Permalink
buildScript: F-Droid use NDK served by fdroiddata def (fixes #1034) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Catfriend1 authored Nov 16, 2023
1 parent 2ee4de2 commit d8e007d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion App_build_and_release.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ REM Script Consts.
SET CLEANUP_BEFORE_BUILD=1
REM
REM Runtime Variables.
IF EXIST "%LocalAppData%\Android\Sdk" SET "ANDROID_SDK_ROOT=%LocalAppData%\Android\Sdk"
IF NOT DEFINED ANDROID_SDK_ROOT SET "ANDROID_SDK_ROOT=%SCRIPT_PATH%..\syncthing-android-prereq"
SET SKIP_RELEASE_BUILD=0
IF NOT DEFINED ANDROID_PUBLISHER_CREDENTIALS echo [WARN] ANDROID_PUBLISHER_CREDENTIALS env var not set. We will skip the signed release build. & SET SKIP_RELEASE_BUILD=1
Expand All @@ -29,7 +30,7 @@ echo [INFO] Checking prerequisites ...
REM
where java 2>&1 >NUL: || (echo [ERROR] Java is missing. Check env. & goto :eof)
REM
IF NOT EXIST %ANDROID_SDK_ROOT%\tools\bin\sdkmanager.bat (echo [WARN] Android SDK manager is missing. Trying to run 'python install_minimum_android_sdk_prerequisites.py' ... & call python install_minimum_android_sdk_prerequisites.py)
IF NOT EXIST "%ANDROID_SDK_ROOT%\.knownPackages" (echo [WARN] Android SDK missing. Trying to run 'python install_minimum_android_sdk_prerequisites.py' ... & call python install_minimum_android_sdk_prerequisites.py)
REM
echo [INFO] Checking if SyncthingNative was built before starting this script ...
SET LIBCOUNT=
Expand Down
3 changes: 2 additions & 1 deletion SyncthingNative_update_and_build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SET DESIRED_SUBMODULE_VERSION=v1.26.1
SET GRADLEW_PARAMS=-q
REM
REM Runtime Variables.
IF EXIST "%LocalAppData%\Android\Sdk" SET "ANDROID_SDK_ROOT=%LocalAppData%\Android\Sdk"
IF NOT DEFINED ANDROID_SDK_ROOT SET "ANDROID_SDK_ROOT=%SCRIPT_PATH%..\syncthing-android-prereq"
IF NOT DEFINED JAVA_HOME SET JAVA_HOME=%ProgramFiles%\Android\Android Studio\jbr
REM
Expand All @@ -27,7 +28,7 @@ REM
where /q java
IF NOT "%ERRORLEVEL%" == "0" SET PATH=%PATH%;%JAVA_HOME%\bin
where /q java
IF NOT "%ERRORLEVEL%" == "0" echo [ERROR] java.exe not found on PATH env var. Download 'https://www.oracle.com/java/technologies/downloads/#java11-windows' and run the installer & pause & goto :checkPrerequisites
IF NOT "%ERRORLEVEL%" == "0" echo [ERROR] java.exe not found on PATH env var. Download 'https://www.oracle.com/java/technologies/downloads/#java17' and run the installer & pause & goto :checkPrerequisites
REM
where /q python
IF NOT "%ERRORLEVEL%" == "0" echo [ERROR] python.exe not found on PATH env var. Download 'https://www.python.org/ftp/python/3.9.6/python-3.9.6-amd64.exe' and run 'python-3.9.6-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0' & pause & goto :checkPrerequisites
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
buildscript {
ext {
// Cannot be called "ndkVersion" as that leads to naming collision
ndkVersionShared = '25.1.8937393'
ndkVersionShared = '26.1.10909125'
}
repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion install_minimum_android_sdk_prerequisites.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def install_sdk_tools():
if sys.platform == 'win32':
subprocess.check_call([sdk_manager_bin, '--update'])
powershell_bin = which('powershell')
subprocess.check_call([powershell_bin, 'for($i=0;$i -lt 32;$i++) { $response += \"y`n\"}; $response | sdkmanager --licenses'], stdout=subprocess.DEVNULL)
subprocess.check_call([powershell_bin, 'for($i=0;$i -lt ' + ANDROID_SDK_VERSION + ';$i++) { $response += \"y`n\"}; $response | sdkmanager --licenses'], stdout=subprocess.DEVNULL)
subprocess.check_call([sdk_manager_bin, 'platforms;android-' + ANDROID_SDK_VERSION])
subprocess.check_call([sdk_manager_bin, 'build-tools;' + ANDROID_SDK_VERSION + '.0.0'])

Expand Down
12 changes: 12 additions & 0 deletions setenv.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@echo off
REM
REM Runtime Variables.
IF NOT DEFINED JAVA_HOME SET JAVA_HOME=%ProgramFiles%\Android\Android Studio\jbr
IF EXIST "%LocalAppData%\Android\Sdk" SET "ANDROID_SDK_ROOT=%LocalAppData%\Android\Sdk"
REM
where /q java
IF NOT "%ERRORLEVEL%" == "0" SET PATH=%PATH%;%JAVA_HOME%\bin
where /q java
IF NOT "%ERRORLEVEL%" == "0" echo [ERROR] java.exe not found on PATH env var. Download 'https://www.oracle.com/java/technologies/downloads/#java17' and run the installer & pause & goto :checkPrerequisites
REM
goto :eof
20 changes: 14 additions & 6 deletions syncthing/build-syncthing.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ def write_file(fullfn, text):
hFile.write(text + '\n')


def get_ndk_ready():
if os.environ.get('ANDROID_NDK_HOME', ''):
return
if not (os.environ.get('NDK_VERSION', '') and os.environ.get('ANDROID_SDK_ROOT', '')):
print('ANDROID_NDK_HOME env var is not defined. Then, NDK_VERSION and ANDROID_SDK_ROOT env vars must be defined.')
install_ndk()
return
os.environ["ANDROID_NDK_HOME"] = os.path.join(os.environ['ANDROID_SDK_ROOT'], 'ndk', os.environ['NDK_VERSION'])
return


def install_ndk():
import os
import zipfile
Expand Down Expand Up @@ -327,13 +338,10 @@ def install_ndk():
fail('Error: go is not available on the PATH.')
print('go_bin=\'' + go_bin + '\'')

# Check if ANDROID_NDK_HOME variable is set.
# Check if "ANDROID_NDK_HOME" env var is set. If not, try to discover and set it.
get_ndk_ready()
if not os.environ.get('ANDROID_NDK_HOME', ''):
print('Warning: ANDROID_NDK_HOME environment variable not defined.')
install_ndk();
# Retry: Check if ANDROID_NDK_HOME variable is set.
if not os.environ.get('ANDROID_NDK_HOME', ''):
fail('Error: ANDROID_NDK_HOME environment variable not defined')
fail('Error: ANDROID_NDK_HOME environment variable not defined')
print('ANDROID_NDK_HOME=\'' + os.environ.get('ANDROID_NDK_HOME', '') + '\'')

# Make sure all tags are available for git describe
Expand Down
1 change: 1 addition & 0 deletions syncthing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
}

task buildNative(type: PythonTask) {
environment "NDK_VERSION", "$ndkVersionShared"
inputs.dir("$projectDir/src/")
outputs.dir("$projectDir/../app/src/main/jniLibs/")
command = "-u ./build-syncthing.py"
Expand Down

0 comments on commit d8e007d

Please sign in to comment.