Skip to content

Commit

Permalink
android GHA more like mmkv
Browse files Browse the repository at this point in the history
  • Loading branch information
boorad committed Mar 31, 2024
1 parent c659203 commit 5763c0f
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 23 deletions.
99 changes: 85 additions & 14 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import com.android.Version
import java.nio.file.Paths

def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
def agpVersionMajor = agpVersion.tokenize('.')[0].toInteger()
def androidManifestPath = agpVersionMajor >= 7 ? 'src/main/AndroidManifest.xml' : 'src/hasNamespace/AndroidManifest.xml'

buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
repositories {
google()
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:8.3.1'
}
}

def resolveBuildType() {
Gradle gradle = getGradle()
String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()

return tskReqStr.contains('Release') ? 'release' : 'debug'
}

def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

if (isNewArchitectureEnabled()) {
apply plugin: 'com.facebook.react'
}
apply plugin: 'com.android.library'

def getExtOrDefault(name) {
Expand All @@ -22,6 +48,11 @@ def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['QuickBase64_' + name]).toInteger()
}

def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

static def findNodeModules(baseDir) {
def basePath = baseDir.toPath().normalize()
// Node's module resolution algorithm searches up to the root directory,
Expand All @@ -41,7 +72,34 @@ def nodeModules = findNodeModules(projectDir);
logger.warn("react-native-quick-base64: node_modules/ found at: ${nodeModules}");

android {
namespace 'com.reactnativequickbase64'
if (agpVersionMajor >= 7) {
namespace 'com.reactnativequickbase64'
}

if (agpVersionMajor >= 8) {
buildFeatures {
buildConfig = true
}
}

sourceSets {
main {
manifest.srcFile androidManifestPath
}
}

// Used to override the NDK path/version on internal CI or by allowing
// users to customize the NDK path/version from their root project (e.g. for M1 support)
if (rootProject.hasProperty("ndkPath")) {
ndkPath rootProject.ext.ndkPath
}
if (rootProject.hasProperty("ndkVersion")) {
ndkVersion rootProject.ext.ndkVersion
}

buildFeatures {
prefab true
}

compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')
Expand All @@ -52,21 +110,21 @@ android {
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"

buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
externalNativeBuild {
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
arguments "-DNODE_MODULES_DIR=${nodeModules}"
}
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
arguments "-DNODE_MODULES_DIR=${nodeModules} -DANDROID_STL=c++_shared"
abiFilters (*reactNativeArchitectures())
}
}

}

externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
cmake {
path "CMakeLists.txt"
}
}

buildTypes {
Expand Down Expand Up @@ -151,8 +209,21 @@ repositories {
}

dependencies {
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "com.facebook.react:react-android:+"
}

// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
tasks.whenTaskAdded { task ->
if (task.name.contains("configureCMakeDebug")) {
rootProject.getTasksByName("packageReactNdkDebugLibs", true).forEach {
task.dependsOn(it)
}
}
// We want to add a dependency for both configureCMakeRelease and configureCMakeRelWithDebInfo
if (task.name.contains("configureCMakeRel")) {
rootProject.getTasksByName("packageReactNdkReleaseLibs", true).forEach {
task.dependsOn(it)
}
}
}
Binary file added android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 3 additions & 0 deletions android/src/hasNamespace/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
4 changes: 3 additions & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.reactnativequickbase64"
>

</manifest>
8 changes: 0 additions & 8 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,4 @@ dependencies {
}
}

tasks.named("mergeDebugNativeLibs").configure {
dependsOn("mergeDebugJniLibFolders")
dependsOn("buildCMakeDebug[armeabi-v7a]")
dependsOn("buildCMakeDebug[arm64-v8a]")
dependsOn("buildCMakeDebug[x86]")
dependsOn("buildCMakeDebug[x86-64]")
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

0 comments on commit 5763c0f

Please sign in to comment.