diff --git a/android/build.gradle b/android/build.gradle
index f32425f..fb7bdda 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -1,10 +1,18 @@
+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 {
@@ -12,6 +20,24 @@ buildscript {
}
}
+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) {
@@ -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,
@@ -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')
@@ -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 {
@@ -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)
+ }
+ }
}
diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..f3d88b1
Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..ae04661
--- /dev/null
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -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
diff --git a/android/src/hasNamespace/AndroidManifest.xml b/android/src/hasNamespace/AndroidManifest.xml
new file mode 100644
index 0000000..0a0938a
--- /dev/null
+++ b/android/src/hasNamespace/AndroidManifest.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml
index 0a0938a..cd2a70e 100644
--- a/android/src/main/AndroidManifest.xml
+++ b/android/src/main/AndroidManifest.xml
@@ -1,3 +1,5 @@
-
+
diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle
index f14992b..b44c799 100644
--- a/example/android/app/build.gradle
+++ b/example/android/app/build.gradle
@@ -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)