diff --git a/.gitignore b/.gitignore index cbcd7e536f..768a089f49 100644 --- a/.gitignore +++ b/.gitignore @@ -32,12 +32,15 @@ project.xcworkspace .gradle *.iml **/android/.project +**/android/.settings/org.eclipse.buildship.core.prefs +local.properties # Atom .tags* # VS Code .vscode/ipch/ +.vscode/settings.json # node.js # diff --git a/Makefile b/Makefile index 302ed13a3d..2706ef7726 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,6 @@ nix-update-npm: export TARGET_OS := none nix-update-npm: ##@nix Update node2nix expressions based on current package.json nix/desktop/realm-node/generate-nix.sh -nix-update-gradle: export TARGET_OS := android nix-update-gradle: ##@nix Update maven nix expressions based on current gradle setup nix/mobile/android/maven-and-npm-deps/maven/generate-nix.sh @@ -113,12 +112,14 @@ release: release-android release-ios ##@build build release for Android and iOS release-android: export TARGET_OS ?= android release-android: export BUILD_ENV ?= prod release-android: export BUILD_TYPE ?= nightly +release-android: export BUILD_NUMBER ?= 9999 release-android: export NDK_ABI_FILTERS ?= armeabi-v7a;arm64-v8a;x86 release-android: export STORE_FILE ?= ~/.gradle/status-im.keystore release-android: ##@build build release for Android nix/build.sh targets.mobile.$(TARGET_OS).release \ --arg env '{NDK_ABI_FILTERS="$(NDK_ABI_FILTERS)";}' \ --argstr build-type $(BUILD_TYPE) \ + --argstr build-number $(BUILD_NUMBER) \ --argstr keystore-file $(STORE_FILE) \ --option extra-sandbox-paths $(STORE_FILE) diff --git a/nix/clean.sh b/nix/clean.sh index 4e5073a583..ec659942b5 100755 --- a/nix/clean.sh +++ b/nix/clean.sh @@ -53,7 +53,7 @@ for path in ${drvPaths}; do toDelete+=("${drv}" "${src}") done -# remove dupicates +# remove duplicates cleanToDelete=$(echo "${toDelete[@]}" | sort | uniq) echo "Deleting..." diff --git a/nix/mobile/android/default.nix b/nix/mobile/android/default.nix index 23caab6a83..0e5ec5275e 100644 --- a/nix/mobile/android/default.nix +++ b/nix/mobile/android/default.nix @@ -1,4 +1,4 @@ -{ config, stdenv, stdenvNoCC, target-os, callPackage, mkShell, +{ config, stdenv, stdenvNoCC, target-os ? "android", callPackage, mkShell, mkFilter, androidenv, fetchurl, openjdk, nodejs, bash, maven, zlib, status-go, localMavenRepoBuilder, projectNodePackage, jsbundle }: diff --git a/nix/mobile/android/maven-and-npm-deps/default.nix b/nix/mobile/android/maven-and-npm-deps/default.nix index 53ef352847..f04722b701 100644 --- a/nix/mobile/android/maven-and-npm-deps/default.nix +++ b/nix/mobile/android/maven-and-npm-deps/default.nix @@ -25,7 +25,7 @@ let deps = let # Place build target directories in NIX_BUILD_TOP (normally represents /build) - projectDir = "$NIX_BUILD_TOP/project"; + projectBuildDir = "$NIX_BUILD_TOP/project"; mavenRepoDir = "$NIX_BUILD_TOP/.m2/repository"; reactNativeMavenPackageDir = "${mavenRepoDir}/com/facebook/react/react-native"; # This is directory where the react-native Maven package will be generated in reactNativeDepsDir = "$NIX_BUILD_TOP/deps"; # Use local writable deps, otherwise (probably due to some interaction between Nix sandboxing and Java) gradle will fail copying directly from the nix store @@ -57,10 +57,10 @@ let runHook preUnpack # Copy project directory - mkdir -p ${projectDir} - cp -a $src/. ${projectDir} - chmod u+w ${projectDir} - cd ${projectDir} + mkdir -p ${projectBuildDir} + cp -a $src/. ${projectBuildDir} + chmod u+w ${projectBuildDir} + cd ${projectBuildDir} # Copy RN maven dependencies and make them writable, otherwise Gradle copy fails (since the top-level directory is read-only, Java isn't smart enough to copy the child files/folders into that target directory) mkdir -p ${mavenRepoDir} @@ -73,21 +73,21 @@ let done # Copy node_modules from Nix store - rm -rf ${projectDir}/node_modules - mkdir -p ${projectDir}/node_modules - cp -a ${projectNodePackage}/node_modules/. ${projectDir}/node_modules/ + rm -rf ${projectBuildDir}/node_modules + mkdir -p ${projectBuildDir}/node_modules + cp -a ${projectNodePackage}/node_modules/. ${projectBuildDir}/node_modules/ # Adjust permissions - chmod -R u+w ${projectDir} + chmod -R u+w ${projectBuildDir} - cp -R ${projectDir}/status-modules/ ${projectDir}/node_modules/status-modules/ - cp -R ${projectDir}/translations/ ${projectDir}/node_modules/status-modules/translations/ + cp -R ${projectBuildDir}/status-modules/ ${projectBuildDir}/node_modules/status-modules/ + cp -R ${projectBuildDir}/translations/ ${projectBuildDir}/node_modules/status-modules/translations/ # Set up symlinks to mobile enviroment in project root - ${createMobileFilesSymlinks projectDir} + ${createMobileFilesSymlinks projectBuildDir} # Create a dummy VERSION, since we don't want this expression to be invalidated just because the version changed - echo '0.0.1' > ${projectDir}/VERSION + echo '0.0.1' > ${projectBuildDir}/VERSION runHook postUnpack ''; @@ -97,7 +97,7 @@ let prevSet=$- set -e - patchShebangs ${projectDir} + patchShebangs ${projectBuildDir} function patchMavenSource() { set +e @@ -125,28 +125,34 @@ let # Patch maven and google central repositories with our own local directories. This prevents the builder from downloading Maven artifacts patchMavenSources 'android/build.gradle' '${mavenLocalRepo}' - for f in `find ${projectDir}/node_modules/ -name build.gradle`; do + for f in `find ${projectBuildDir}/node_modules/ -name build.gradle`; do patchMavenSources $f '${mavenLocalRepo}' done # Patch prepareJSC so that it doesn't try to download from registry - substituteInPlace ${projectDir}/node_modules/react-native/ReactAndroid/build.gradle \ + substituteInPlace ${projectBuildDir}/node_modules/react-native/ReactAndroid/build.gradle \ --replace 'prepareJSC(dependsOn: downloadJSC)' 'prepareJSC(dependsOn: createNativeDepsDirectories)' \ --replace 'def jscTar = tarTree(downloadJSC.dest)' "def jscTar = tarTree(new File(\"${react-native-deps}/deps/${jsc-filename}.tar.gz\"))" # Do not add a BuildId to the generated libraries, for reproducibility - substituteInPlace ${projectDir}/node_modules/react-native/ReactAndroid/src/main/jni/Application.mk \ - --replace '-Wl,--build-id' '-Wl,--build-id=none' + substituteInPlace ${projectBuildDir}/node_modules/react-native/ReactAndroid/src/main/jni/Application.mk \ + --replace \ + '-Wl,--build-id' \ + '-Wl,--build-id=none' # Disable Gradle daemon and caching, since that causes rebuilds (and subsequently errors) anyway due to cache being considered stale - substituteInPlace ${projectDir}/android/gradle.properties \ - --replace 'org.gradle.jvmargs=-Xmx8704M' 'org.gradle.jvmargs=-Xmx8704M + substituteInPlace ${projectBuildDir}/android/gradle.properties \ + --replace \ + 'org.gradle.jvmargs=-Xmx8704M' \ + 'org.gradle.jvmargs=-Xmx8704M org.gradle.daemon=false org.gradle.caching=false' # Patch the path to nodejs in project.ext.react - substituteInPlace ${projectDir}/android/app/build.gradle \ - --replace 'nodeExecutableAndArgs: ["node"' 'nodeExecutableAndArgs: ["${nodejs}/bin/node"' + substituteInPlace ${projectBuildDir}/android/app/build.gradle \ + --replace \ + 'nodeExecutableAndArgs: ["node"' \ + 'nodeExecutableAndArgs: ["${nodejs}/bin/node"' set $prevSet @@ -157,9 +163,9 @@ let status-go.shellHook + '' export HOME=$NIX_BUILD_TOP export REACT_NATIVE_DEPENDENCIES="${reactNativeDepsDir}" - export STATUS_REACT_HOME="${projectDir}" + export STATUS_REACT_HOME="${projectBuildDir}" - pushd ${projectDir}/android + pushd ${projectBuildDir}/android # NOTE: This generates the react-native-android binaries under node_modules/react-native/android LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib.makeLibraryPath [ zlib ]} \ gradle -Dmaven.repo.local=${mavenRepoDir} --offline -S react-native-android:installArchives || exit @@ -168,24 +174,26 @@ let doCheck = true; checkPhase = '' runHook preCheck - test -d ${projectDir}/node_modules/react-native/ReactAndroid/build/intermediates/javac/release/compileReleaseJavaWithJavac/classes/com/facebook || \ + test -d ${projectBuildDir}/node_modules/react-native/ReactAndroid/build/intermediates/javac/release/compileReleaseJavaWithJavac/classes/com/facebook || \ exit 1 - test -d ${projectDir}/node_modules/react-native/ReactAndroid/build/react-ndk/exported || \ + test -d ${projectBuildDir}/node_modules/react-native/ReactAndroid/build/react-ndk/exported || \ exit 2 runHook postCheck ''; installPhase = '' rm -rf $out - mkdir -p $out/project $out/.m2/repository + mkdir -p $out/{project,.m2/repository} # TODO: maybe node_modules/react-native/ReactAndroid/build/{tmp,generated} can be discarded? cp -R ${mavenRepoDir} $out/.m2/ - cp -R ${projectDir}/android/ ${projectDir}/node_modules/ $out/project + cp -R ${projectBuildDir}/{android,node_modules}/ $out/project ''; fixupPhase = '' # Patch prepareJSC so that it doesn't subsequently try to build NDK libs substituteInPlace $out/project/node_modules/react-native/ReactAndroid/build.gradle \ - --replace 'packageReactNdkLibs(dependsOn: buildReactNdkLib, ' 'packageReactNdkLibs(' + --replace \ + 'packageReactNdkLibs(dependsOn: buildReactNdkLib, ' \ + 'packageReactNdkLibs(' ''; # The ELF types are incompatible with the host platform, so let's not even try diff --git a/nix/mobile/android/targets/release-android.nix b/nix/mobile/android/targets/release-android.nix index 7b4e4e1fe2..0e5d8a77da 100644 --- a/nix/mobile/android/targets/release-android.nix +++ b/nix/mobile/android/targets/release-android.nix @@ -3,8 +3,8 @@ androidEnvShellHook, mavenAndNpmDeps, nodejs, openjdk, jsbundle, status-go, zlib }: -{ build-number ? "9999", - build-type ? "nightly", # Build type (e.g. nightly, release, e2e). Default is to use .env.nightly file +{ build-number, + build-type, # Build type (e.g. nightly, release, e2e). Default is to use .env.nightly file gradle-opts ? "", keystore-file ? "", # Path to the .keystore file used to sign the package secrets-file ? "", # Path to the file containing secret environment variables @@ -83,9 +83,9 @@ in stdenv.mkDerivation { set -e substituteInPlace android/gradlew \ - --replace 'exec gradle' "exec gradle -S -Dmaven.repo.local='${localMavenRepo}' --offline ${gradle-opts}" - substituteInPlace android/gradle.properties \ - --replace 'versionCode=9999' 'versionCode=${build-number}' + --replace \ + 'exec gradle' \ + "exec gradle -Dmaven.repo.local='${localMavenRepo}' --offline ${gradle-opts}" # OPTIONAL: There's no need to forward debug ports for a release build, just disable it substituteInPlace node_modules/realm/android/build.gradle \ @@ -113,7 +113,7 @@ in stdenv.mkDerivation { ${concatStrings (catAttrs "shellHook" [ mavenAndNpmDeps status-go ])} pushd android - ${adhocEnvVars} gradle assemble${capitalizedBuildType} -S -Dmaven.repo.local='${localMavenRepo}' --offline ${gradle-opts} || exit + ${adhocEnvVars} ./gradlew -PversionCode=${build-number} assemble${capitalizedBuildType} || exit popd > /dev/null ${unsetEnvVars} diff --git a/nix/shell.sh b/nix/shell.sh index 6aa4e9c132..2016ef802f 100755 --- a/nix/shell.sh +++ b/nix/shell.sh @@ -47,7 +47,7 @@ fi if [[ "$TARGET_OS" =~ (linux|windows|darwin|macos) ]]; then # This is a dirty workaround because 'yarn install' is an impure operation, # so we need to call it from an impure shell. - # Hopefull we'll be able to fix this later on with something like yarn2nix + # Hopefully we'll be able to fix this later on with something like yarn2nix nix-shell ${shellArgs[@]} --run "scripts/prepare-for-desktop-platform.sh" || exit fi diff --git a/scripts/release-android.sh b/scripts/release-android.sh deleted file mode 100755 index 7435059260..0000000000 --- a/scripts/release-android.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash - -set -Eeo pipefail - -GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel) -CURRENT_DIR="$( cd "$( dirname "$0" )" && pwd )" -. "$CURRENT_DIR/lib/setup/path-support.sh" -source_lib "properties.sh" -source_lib "platform.sh" - -STORE_FILE=$(property_gradle 'STATUS_RELEASE_STORE_FILE') -STORE_FILE="${STORE_FILE/#\~/$HOME}" - -function cleanup() { - trap - EXIT ERR INT QUIT - - if [ -n "$nixResultPath" ]; then - echo "Deleting derivations from Nix store..." - . ~/.nix-profile/etc/profile.d/nix.sh - releaseDrv=$(nix-instantiate --quiet $nixOpts) - if [ -n "$releaseDrv" ]; then - local releaseSrcPath=$(nix-store -q --binding src $releaseDrv) - local releaseOutPath=$(nix-store -q --outputs $releaseDrv) - local releaseRefs=( $(nix-store -q --references $releaseDrv) ) - local prodBuildDrv=$(printf -- '%s\n' "${releaseRefs[@]}" | grep -e "jsbundle-android.drv") - local prodBuildSrcPath=$(nix-store -q --binding src $prodBuildDrv) - local prodBuildOutPath=$(nix-store -q --outputs $prodBuildDrv) - nix-store --delete $prodBuildDrv $prodBuildSrcPath $prodBuildOutPath $releaseDrv $releaseSrcPath $releaseOutPath 2> /dev/null - fi - fi -} - -trap "cleanup" EXIT ERR INT QUIT - -[ -z "$BUILD_TYPE" ] && BUILD_TYPE='nightly' - -exportedEnv=() -if [ -n "$NDK_ABI_FILTERS" ]; then - exportedEnv+=( "NDK_ABI_FILTERS=''${NDK_ABI_FILTERS}'';" ) # NOTE: Do not include spaces in the Nix attribute set, otherwise it'll create issues with automatic bash quoting -fi -exportedEnvFlag='' -if [ ${#exportedEnv[@]} -ne 0 ]; then - exportedEnvFlag="--arg env {${exportedEnv[@]}}" -fi -nixOpts="--option extra-sandbox-paths ${STORE_FILE} \ - --argstr target-os ${TARGET_OS} \ - --argstr build-type ${BUILD_TYPE} \ - --argstr keystore-file ${STORE_FILE} \ - --show-trace \ - ${exportedEnvFlag} \ - -A targets.mobile.${TARGET_OS}.release" - -# Run the build -outType='release' -if [ "$BUILD_TYPE" != "release" ] && [ "$BUILD_TYPE" != "nightly" ]; then - outType="pr" -fi - -nixResultPath=$(. ~/.nix-profile/etc/profile.d/nix.sh && nix-build --pure --fallback --no-out-link $nixOpts) -if [ -n "$${nixResultPath}" ]; then - targetPath="android/app/build/outputs/apk/${outType}/app-${outType}.apk" - cpFlags='-v' - is_linux && cpFlags='-fv --no-preserve=mode' - mkdir -p android/app/build/outputs/apk/${outType} && \ - cp ${cpFlags} "${nixResultPath}/app.apk" "${targetPath}" && \ - chmod u+w ${targetPath} -fi