2022-08-09 18:49:59 +00:00
|
|
|
{ stdenv, pkgs, deps, lib
|
2022-05-26 09:11:34 +00:00
|
|
|
, androidPkgs, patchMavenSources, jsbundle, status-go }:
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2020-04-26 12:40:06 +00:00
|
|
|
{
|
2020-06-03 19:47:01 +00:00
|
|
|
# Value for BUILD_ENV checked by Clojure code at compile time
|
|
|
|
buildEnv ? "prod",
|
|
|
|
# Path to the file containing secret environment variables
|
|
|
|
secretsFile ? "",
|
2023-06-27 11:45:21 +00:00
|
|
|
# Build type (influences which .env file gets used for feature flags)
|
|
|
|
buildType ? lib.getEnvWithDefault "BUILD_TYPE" "release",
|
|
|
|
# Used for versionCode
|
2024-02-15 08:18:11 +00:00
|
|
|
versionCode ? lib.getEnvWithDefault "ORG_GRADLE_PROJECT_versionCode" 9999,
|
2023-06-27 11:45:21 +00:00
|
|
|
# Included in APK Manifest for easier identification.
|
2024-02-15 08:18:11 +00:00
|
|
|
commitHash ? lib.getEnvWithDefault "ORG_GRADLE_PROJECT_commitHash" "unknown",
|
|
|
|
# Disabled for debug builds to avoid 'maximum call stack exceeded' errors.
|
|
|
|
# https://github.com/status-im/status-mobile/issues/18493
|
|
|
|
hermesEnabled ? lib.getEnvWithDefault "ORG_GRADLE_PROJECT_hermesEnabled" "true",
|
|
|
|
buildUrl ? lib.getEnvWithDefault "ORG_GRADLE_PROJECT_buildUrl" null,
|
2023-06-27 11:45:21 +00:00
|
|
|
statusGoSrcOverride ? lib.getEnvWithDefault "STATUS_GO_SRC_OVERRIDE" null,
|
2024-08-05 11:48:35 +00:00
|
|
|
reactMetroPort ? lib.getEnvWithDefault "RCT_METRO_PORT" 8081,
|
2023-06-27 11:45:21 +00:00
|
|
|
# If APKs should be split based on architectures
|
2024-07-26 18:32:44 +00:00
|
|
|
androidAbiSplit ? lib.getEnvWithDefault "ANDROID_ABI_SPLIT" "true",
|
2023-06-27 11:45:21 +00:00
|
|
|
# Android architectures to build for
|
|
|
|
# Used to detect end-to-end builds
|
2024-07-26 18:32:44 +00:00
|
|
|
androidAbiInclude ? lib.getEnvWithDefault "ANDROID_ABI_INCLUDE" "arm64-v8a",
|
2024-09-05 09:01:03 +00:00
|
|
|
universalApk ? lib.getEnvWithDefault "ORG_GRADLE_PROJECT_universalApk" "false"
|
2019-06-04 16:50:29 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2023-06-27 11:45:21 +00:00
|
|
|
inherit (lib) toLower optionalString stringLength makeLibraryPath elem;
|
2024-03-23 09:42:05 +00:00
|
|
|
notDebug = (buildType != "debug");
|
2020-04-26 12:40:06 +00:00
|
|
|
|
2022-10-19 14:59:55 +00:00
|
|
|
# Pass secretsFile for POKT_TOKEN to jsbundle build
|
2024-03-23 09:42:05 +00:00
|
|
|
builtJsBundle = lib.optionals notDebug jsbundle { inherit secretsFile; };
|
2020-10-05 12:53:20 +00:00
|
|
|
|
2023-08-17 11:51:37 +00:00
|
|
|
# Map ANDROID_ABI_INCLUDE to status-go targets
|
|
|
|
androidAbiIncludeSplit = lib.splitString ";" androidAbiInclude;
|
|
|
|
|
2020-04-23 18:19:12 +00:00
|
|
|
|
2022-08-09 18:49:59 +00:00
|
|
|
envFileName =
|
2023-12-21 13:36:16 +00:00
|
|
|
if (elem androidAbiInclude ["x86" "x86_64" "x86;x86_64"]) then ".env.e2e"
|
|
|
|
else if (elem buildType ["release" "nightly"]) then ".env.${buildType}"
|
|
|
|
else if (elem buildType ["pr" "manual"]) then ".env.jenkins"
|
2020-04-26 12:40:06 +00:00
|
|
|
else ".env";
|
|
|
|
|
2024-02-14 14:28:45 +00:00
|
|
|
gradleBuildType =
|
|
|
|
if buildType == "pr" then "Pr"
|
|
|
|
else if buildType == "debug" then "Debug"
|
|
|
|
else "Release";
|
2020-04-26 12:40:06 +00:00
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
apksPath = "./android/app/build/outputs/apk/${toLower gradleBuildType}";
|
2019-06-04 16:50:29 +00:00
|
|
|
|
2022-05-26 09:11:34 +00:00
|
|
|
baseName = "${buildType}-android";
|
2020-04-26 12:40:06 +00:00
|
|
|
in stdenv.mkDerivation rec {
|
2022-07-17 12:37:46 +00:00
|
|
|
name = "status-mobile-build-${baseName}";
|
2022-05-26 09:11:34 +00:00
|
|
|
|
2020-05-07 10:21:39 +00:00
|
|
|
src = let path = ./../../..;
|
2020-04-26 12:40:06 +00:00
|
|
|
# We use builtins.path so that we can name the resulting derivation
|
|
|
|
in builtins.path {
|
|
|
|
inherit path;
|
2022-07-17 12:37:46 +00:00
|
|
|
name = "status-mobile-source-${baseName}";
|
2020-04-26 12:40:06 +00:00
|
|
|
# Keep this filter as restrictive as possible in order to avoid unnecessary rebuilds and limit closure size
|
|
|
|
filter = lib.mkFilter {
|
|
|
|
root = path;
|
|
|
|
include = [
|
2022-11-24 21:05:58 +00:00
|
|
|
"package.json" "yarn.lock" "metro.config.js" "babel.config.js"
|
2023-05-16 16:42:56 +00:00
|
|
|
"resources/.*" "translations/.*" "src/js/.*" "index.js"
|
2020-05-07 10:21:39 +00:00
|
|
|
"modules/react-native-status/android.*" "android/.*"
|
2022-08-09 18:49:59 +00:00
|
|
|
envFileName "VERSION" "status-go-version.json" "react-native.config.js"
|
2020-04-26 12:40:06 +00:00
|
|
|
];
|
2019-06-04 16:50:29 +00:00
|
|
|
};
|
2020-04-26 12:40:06 +00:00
|
|
|
};
|
|
|
|
|
2020-05-18 10:15:49 +00:00
|
|
|
buildInputs = with pkgs; [ nodejs openjdk ];
|
|
|
|
nativeBuildInputs = with pkgs; [ bash gradle unzip ]
|
2022-08-09 18:49:59 +00:00
|
|
|
++ lib.optionals stdenv.isDarwin [ file gnumake ];
|
|
|
|
|
|
|
|
# Disable metro watching for file changes. (#13783)
|
|
|
|
CI = true;
|
2020-04-26 12:40:06 +00:00
|
|
|
|
|
|
|
# Used by Clojure at compile time to include JS modules
|
|
|
|
BUILD_ENV = buildEnv;
|
|
|
|
|
2023-06-27 11:45:21 +00:00
|
|
|
STATUS_GO_SRC_OVERRIDE = statusGoSrcOverride;
|
|
|
|
ANDROID_ABI_SPLIT = androidAbiSplit;
|
2020-07-08 14:08:51 +00:00
|
|
|
ANDROID_ABI_INCLUDE = androidAbiInclude;
|
2024-02-01 15:26:18 +00:00
|
|
|
# Disabled for debug builds to avoid 'maximum call stack exceeded' errors.
|
|
|
|
# https://github.com/status-im/status-mobile/issues/18493
|
2024-02-15 08:18:11 +00:00
|
|
|
ORG_GRADLE_PROJECT_versionCode = versionCode;
|
|
|
|
ORG_GRADLE_PROJECT_commitHash = commitHash;
|
|
|
|
ORG_GRADLE_PROJECT_buildUrl = buildUrl;
|
|
|
|
ORG_GRADLE_PROJECT_hermesEnabled = hermesEnabled;
|
2024-09-05 09:01:03 +00:00
|
|
|
ORG_GRADLE_PROJECT_universalApk = universalApk;
|
2020-04-26 12:40:06 +00:00
|
|
|
|
2022-08-31 23:30:35 +00:00
|
|
|
# Fix for ERR_OSSL_EVP_UNSUPPORTED error.
|
|
|
|
NODE_OPTIONS = "--openssl-legacy-provider";
|
|
|
|
|
2020-05-06 13:33:54 +00:00
|
|
|
phases = [
|
2023-08-17 11:51:37 +00:00
|
|
|
"shellHook" "unpackPhase" "secretsPhase" "buildPhase" "checkPhase" "installPhase"
|
2020-05-06 13:33:54 +00:00
|
|
|
];
|
2019-08-06 16:16:51 +00:00
|
|
|
|
2023-08-17 11:51:37 +00:00
|
|
|
# We use shellHook as a single place to setup env vars for both build derivation and shell
|
|
|
|
shellHook = ''
|
|
|
|
# Used by the Android Gradle build script in android/build.gradle
|
|
|
|
export STATUS_GO_ANDROID_LIBDIR=${ status-go { abis = androidAbiIncludeSplit; } }
|
|
|
|
|
|
|
|
# Android SDK/NDK for use by Gradle
|
|
|
|
export ANDROID_SDK_ROOT="${androidPkgs.sdk}"
|
|
|
|
export ANDROID_NDK_ROOT="${androidPkgs.ndk}"
|
|
|
|
|
|
|
|
export STATUS_NIX_MAVEN_REPO="${deps.gradle}"
|
|
|
|
'';
|
|
|
|
|
2020-05-06 13:33:54 +00:00
|
|
|
unpackPhase = ''
|
2020-05-07 10:21:39 +00:00
|
|
|
cp -ar $src/. ./
|
|
|
|
chmod u+w -R ./
|
2019-08-06 16:16:51 +00:00
|
|
|
runHook postUnpack
|
|
|
|
'';
|
2020-06-05 09:23:22 +00:00
|
|
|
postUnpack = ''
|
2019-06-04 16:50:29 +00:00
|
|
|
# Ensure we have the right .env file
|
2020-07-08 14:08:51 +00:00
|
|
|
cp -bf ./${envFileName} ./.env
|
2020-05-07 10:21:39 +00:00
|
|
|
|
2022-08-09 18:49:59 +00:00
|
|
|
# Export all vars from .env file
|
|
|
|
export $(cut -d= -f1 .env)
|
2020-11-02 08:43:54 +00:00
|
|
|
|
2024-03-23 09:42:05 +00:00
|
|
|
${lib.optionalString notDebug ''
|
2023-05-16 16:42:56 +00:00
|
|
|
# Symlink React Native entrypoint.
|
|
|
|
cp -Lr ${builtJsBundle} ./result
|
2024-03-23 09:42:05 +00:00
|
|
|
''}
|
2019-06-04 16:50:29 +00:00
|
|
|
|
|
|
|
# Copy android/ directory
|
2020-05-07 10:21:39 +00:00
|
|
|
mkdir -p ./android/build
|
|
|
|
chmod -R +w ./android
|
|
|
|
|
|
|
|
# Copy node_modules/ directory. The -L is CRUCIAL!
|
|
|
|
# Otherwise Metro failes to find modules due to symlinks.
|
2020-05-18 10:15:49 +00:00
|
|
|
cp -aL ${deps.nodejs-patched}/node_modules/ ./
|
2020-05-07 10:21:39 +00:00
|
|
|
chmod +w -R ./node_modules
|
|
|
|
|
|
|
|
# Patch build.gradle to use local repo
|
2020-05-19 18:15:41 +00:00
|
|
|
${patchMavenSources} ./android/build.gradle
|
2019-06-04 16:50:29 +00:00
|
|
|
'';
|
2020-06-05 09:23:22 +00:00
|
|
|
|
2022-04-22 08:20:01 +00:00
|
|
|
# Secrets file is passed to sandbox using extra-sandbox-paths.
|
2020-06-03 19:47:01 +00:00
|
|
|
secretsPhase = if (secretsFile != "") then ''
|
2020-05-06 13:33:54 +00:00
|
|
|
source "${secretsFile}"
|
2022-04-22 08:20:01 +00:00
|
|
|
'' else ''
|
|
|
|
echo 'WARNING: No secrets provided!' >&2
|
2020-06-05 09:23:22 +00:00
|
|
|
'';
|
2022-04-22 08:20:01 +00:00
|
|
|
|
2020-04-26 12:40:06 +00:00
|
|
|
buildPhase = let
|
|
|
|
adhocEnvVars = optionalString stdenv.isLinux
|
2020-05-18 10:15:49 +00:00
|
|
|
"LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${makeLibraryPath [ pkgs.zlib ]}";
|
2023-06-27 11:45:21 +00:00
|
|
|
gradleCommand = ''
|
|
|
|
${pkgs.gradle}/bin/gradle \
|
2020-08-06 12:23:18 +00:00
|
|
|
--console=plain \
|
2023-06-14 01:47:41 +00:00
|
|
|
--offline \
|
|
|
|
--no-daemon \
|
|
|
|
--no-scan \
|
|
|
|
--no-watch-fs \
|
|
|
|
--no-build-cache \
|
2024-03-23 09:42:05 +00:00
|
|
|
--parallel \
|
2020-05-07 10:21:39 +00:00
|
|
|
-Dmaven.repo.local='${deps.gradle}' \
|
2024-08-05 11:48:35 +00:00
|
|
|
-PreactNativeDevServerPort=${toString reactMetroPort} \
|
2023-06-27 11:45:21 +00:00
|
|
|
assemble${gradleBuildType}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
assert ANDROID_ABI_SPLIT != null && ANDROID_ABI_SPLIT != "";
|
|
|
|
assert stringLength ANDROID_ABI_INCLUDE > 0;
|
|
|
|
''
|
|
|
|
# Fixes issue with failing to load libnative-platform.so
|
|
|
|
export GRADLE_USER_HOME=$(mktemp -d)
|
|
|
|
export ANDROID_SDK_HOME=$(mktemp -d)
|
|
|
|
|
|
|
|
echo "Adhoc ENV: ${adhocEnvVars}"
|
|
|
|
echo "Running: ${gradleCommand}"
|
|
|
|
|
|
|
|
pushd ./android
|
|
|
|
${adhocEnvVars} ${gradleCommand}
|
2019-06-04 16:50:29 +00:00
|
|
|
popd > /dev/null
|
|
|
|
'';
|
2024-02-14 14:28:45 +00:00
|
|
|
|
|
|
|
doCheck = buildType != "debug";
|
|
|
|
checkPhase = ''
|
2020-05-18 10:15:49 +00:00
|
|
|
ls ${apksPath}/*.apk \
|
|
|
|
| xargs -n1 ${pkgs.unzip}/bin/unzip -qql \
|
2023-06-14 01:47:41 +00:00
|
|
|
| grep 'index.android.bundle'
|
2019-08-06 16:16:51 +00:00
|
|
|
'';
|
2024-02-14 14:28:45 +00:00
|
|
|
|
2019-06-04 16:50:29 +00:00
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2019-09-13 17:16:13 +00:00
|
|
|
cp ${apksPath}/*.apk $out/
|
2019-06-04 16:50:29 +00:00
|
|
|
'';
|
|
|
|
}
|