Skip to content

Commit

Permalink
chore: task to generate properties at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
siddarthkay committed Jan 31, 2024
1 parent 95039f6 commit 4eff0c9
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 22 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,6 @@ run-re-frisk: ##@run Start re-frisk server

# TODO: Migrate this to a Nix recipe, much the same way as nix/mobile/android/targets/release-android.nix
run-android: export TARGET := android
# INFO: We disable hermes for local builds by default to prevent crashes with exceeding native callstack errors
run-android: export DISABLE_HERMES := true
# INFO: If it's empty (no devices attached, parsing issues, script error) - for Nix it's the same as not set.
run-android: export ANDROID_ABI_INCLUDE ?= $(shell ./scripts/adb_devices_abis.sh)
run-android: ##@run Build Android APK and start it on the device
Expand Down
51 changes: 31 additions & 20 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.grad
import com.android.build.OutputFile
import com.sun.org.apache.xalan.internal.xsltc.compiler.Copy

def isDebugBuild = gradle.startParameter.taskNames.any { it.toLowerCase().contains('debug') }

/*
* This is the configuration block to customize your React Native Android app.
* By default you don't need to apply any configuration, just uncomment the lines you need.
Expand Down Expand Up @@ -61,6 +63,8 @@ react {
*/
def enableProguardInReleaseBuilds = false

def enableHermes = hermesEnabled.toBoolean();

/**
* The preferred build flavor of JavaScriptCore (JSC)
*
Expand All @@ -74,23 +78,6 @@ def enableProguardInReleaseBuilds = false
*/
def jscFlavor = 'org.webkit:android-jsc:+'

/*
Enabling Hermes for debug builds is crashing the app with exceeding native callstack errors
this flag can be used to disable Hermes while building app.
https://github.com/status-im/status-mobile/issues/18493
*/

def disableHermes = System.getenv('DISABLE_HERMES') == 'true'

/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = !disableHermes;

def getCommitHash = { ->
if (project.hasProperty("commitHash")) {
return project.commitHash
Expand Down Expand Up @@ -276,10 +263,10 @@ dependencies {
implementation("com.facebook.react:react-android")
implementation "androidx.core:core-splashscreen:1.0.0"

if (enableHermes) {
if (isDebugBuild) {
implementation jscFlavor
} else {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}

// react-native-screens
Expand Down Expand Up @@ -327,6 +314,30 @@ task hemroidBuild(type: Exec) {
executable execPath
}

// We need to do this so that we could disable hermes for local builds
// unfortunately the only way to do that is modifying a key value pair in gradle.properties
// and to set it to false, there is no dynamic way to do this, hence we have to take this drastic measure
// otherwise local debug builds crash frequently, ref: https://github.com/status-im/status-mobile/issues/18493
task selectGradleProperties {
doLast {
def envPropsFile = isDebugBuild ? 'gradle.properties.local' : 'gradle.properties.ci'
def propsFile = file(envPropsFile)

if (propsFile.exists()) {
copy {
from propsFile
into project.rootDir
rename { 'gradle.properties' }
}
println "Copied $envPropsFile to gradle.properties"
} else {
println "$envPropsFile not found. Using existing gradle.properties."
}
}
}

preBuild.dependsOn selectGradleProperties

preBuild.dependsOn hemroidBuild

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
60 changes: 60 additions & 0 deletions android/app/gradle.properties.ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# To create a new keystore for development purposes (https://developer.android.com/studio/publish/app-signing.html)
# $keytool -genkey -v -keystore ./status-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias status

# Version requirements used throughout the Gradle scripts
minSdkVersion=24
compileSdkVersion=33
targetSdkVersion=33
buildToolsVersion=33.0.0
supportLibVersion=28.0.0
# This should match version from nix/pkgs/aapt2/default.nix
gradlePluginVersion=7.4.2
kotlinPluginVersion=1.9.0

android.useAndroidX=true
android.enableJetifier=true

KEYSTORE_PATH=~/.gradle/status-im.keystore
KEYSTORE_PASSWORD=password
KEYSTORE_ALIAS=status
KEYSTORE_KEY_PASSWORD=password

# By default we build a mostly universal APK
ANDROID_ABI_SPLIT=false
# Some platforms are excluded though
ANDROID_ABI_INCLUDE=armeabi-v7a;arm64-v8a;x86;x86_64

org.gradle.jvmargs=-Xmx8704M

versionCode=9999
commitHash=unknown

# Use this property to enable support to the new architecture.
# This will allow you to use TurboModules and the Fabric render in
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=false

# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=true
60 changes: 60 additions & 0 deletions android/app/gradle.properties.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# To create a new keystore for development purposes (https://developer.android.com/studio/publish/app-signing.html)
# $keytool -genkey -v -keystore ./status-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias status

# Version requirements used throughout the Gradle scripts
minSdkVersion=24
compileSdkVersion=33
targetSdkVersion=33
buildToolsVersion=33.0.0
supportLibVersion=28.0.0
# This should match version from nix/pkgs/aapt2/default.nix
gradlePluginVersion=7.4.2
kotlinPluginVersion=1.9.0

android.useAndroidX=true
android.enableJetifier=true

KEYSTORE_PATH=~/.gradle/status-im.keystore
KEYSTORE_PASSWORD=password
KEYSTORE_ALIAS=status
KEYSTORE_KEY_PASSWORD=password

# By default we build a mostly universal APK
ANDROID_ABI_SPLIT=false
# Some platforms are excluded though
ANDROID_ABI_INCLUDE=armeabi-v7a;arm64-v8a;x86;x86_64

org.gradle.jvmargs=-Xmx8704M

versionCode=9999
commitHash=unknown

# Use this property to enable support to the new architecture.
# This will allow you to use TurboModules and the Fabric render in
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=false

# Use this property to enable or disable the Hermes JS engine.
# If set to false, you will be using JSC instead.
hermesEnabled=false

0 comments on commit 4eff0c9

Please sign in to comment.