2023-04-28 22:00:29 +09:00
|
|
|
import java.nio.file.Paths
|
|
|
|
|
|
2019-02-24 10:52:56 +08:00
|
|
|
buildscript {
|
2022-08-21 16:22:32 +08:00
|
|
|
// The Android Gradle plugin is only required when opening the android folder stand-alone.
|
|
|
|
|
// This avoids unnecessary downloads and potential conflicts when the library is included as a
|
|
|
|
|
// module dependency in an application project.
|
|
|
|
|
if (project == rootProject) {
|
|
|
|
|
repositories {
|
|
|
|
|
google()
|
|
|
|
|
mavenCentral()
|
|
|
|
|
}
|
2019-02-24 10:52:56 +08:00
|
|
|
|
2022-08-21 16:22:32 +08:00
|
|
|
dependencies {
|
|
|
|
|
classpath("com.android.tools.build:gradle:4.2.2")
|
|
|
|
|
}
|
2019-03-03 15:43:30 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-21 16:22:32 +08:00
|
|
|
task downloadDependencies() {
|
|
|
|
|
description 'Download all dependencies to the Gradle cache'
|
|
|
|
|
doLast {
|
|
|
|
|
configurations.findAll().each { config ->
|
|
|
|
|
if (config.name.contains("minReactNative") && config.canBeResolved) {
|
|
|
|
|
print config.name
|
|
|
|
|
print '\n'
|
|
|
|
|
config.files
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getExtOrInitialValue(name, initialValue) {
|
|
|
|
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : initialValue
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-03 15:43:30 +08:00
|
|
|
def getExtOrDefault(name) {
|
|
|
|
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeCameraRoll_' + name]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def getExtOrIntegerDefault(name) {
|
|
|
|
|
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ReactNativeCameraRoll_' + name]).toInteger()
|
2019-02-24 10:52:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
apply plugin: 'com.android.library'
|
|
|
|
|
|
2023-04-28 22:00:29 +09:00
|
|
|
/**
|
|
|
|
|
* Original code: https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/build.gradle#L382
|
|
|
|
|
*
|
|
|
|
|
* Finds the path of the installed npm package with the given name using Node's
|
|
|
|
|
* module resolution algorithm, which searches "node_modules" directories up to
|
|
|
|
|
* the file system root. This handles various cases, including:
|
|
|
|
|
*
|
|
|
|
|
* - Working in the open-source RN repo:
|
|
|
|
|
* Gradle: /path/to/react-native/ReactAndroid
|
|
|
|
|
* Node module: /path/to/react-native/node_modules/[package]
|
|
|
|
|
*
|
|
|
|
|
* - Installing RN as a dependency of an app and searching for hoisted
|
|
|
|
|
* dependencies:
|
|
|
|
|
* Gradle: /path/to/app/node_modules/react-native/ReactAndroid
|
|
|
|
|
* Node module: /path/to/app/node_modules/[package]
|
|
|
|
|
*
|
|
|
|
|
* - Working in a larger repo (e.g., Facebook) that contains RN:
|
|
|
|
|
* Gradle: /path/to/repo/path/to/react-native/ReactAndroid
|
|
|
|
|
* Node module: /path/to/repo/node_modules/[package]
|
|
|
|
|
*
|
|
|
|
|
* The search begins at the given base directory (a File object). The returned
|
|
|
|
|
* path is a string.
|
|
|
|
|
*/
|
|
|
|
|
def findNodeModulePath(baseDir, packageName) {
|
|
|
|
|
def basePath = baseDir.toPath().normalize()
|
|
|
|
|
// Node's module resolution algorithm searches up to the root directory,
|
|
|
|
|
// after which the base path will be null
|
|
|
|
|
while (basePath) {
|
|
|
|
|
def candidatePath = Paths.get(basePath.toString(), "node_modules", packageName)
|
|
|
|
|
if (candidatePath.toFile().exists()) {
|
|
|
|
|
return candidatePath.toString()
|
|
|
|
|
}
|
|
|
|
|
basePath = basePath.getParent()
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
2023-03-09 14:47:47 +01:00
|
|
|
|
|
|
|
|
def resolveReactNativeDirectory() {
|
2023-04-28 22:00:29 +09:00
|
|
|
def reactNative = file("${findNodeModulePath(rootProject.projectDir, "react-native")}")
|
|
|
|
|
if (reactNative.exists()) {
|
|
|
|
|
return reactNative
|
2023-03-09 14:47:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new Exception(
|
2023-03-13 11:24:14 +01:00
|
|
|
"[react-native-cameraroll] Unable to resolve react-native location in " +
|
2023-03-09 14:47:47 +01:00
|
|
|
"node_modules. You should add project extension property (in app/build.gradle) " +
|
|
|
|
|
"`REACT_NATIVE_NODE_MODULES_DIR` with path to react-native."
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def REACT_NATIVE_DIR = resolveReactNativeDirectory()
|
|
|
|
|
|
|
|
|
|
def reactProperties = new Properties()
|
|
|
|
|
file("$REACT_NATIVE_DIR/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
|
|
|
|
|
|
|
|
def REACT_NATIVE_VERSION = reactProperties.getProperty("VERSION_NAME")
|
|
|
|
|
def REACT_NATIVE_MINOR_VERSION = REACT_NATIVE_VERSION.startsWith("0.0.0-") ? 1000 : REACT_NATIVE_VERSION.split("\\.")[1].toInteger()
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-26 11:26:44 +02:00
|
|
|
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
|
|
|
|
|
def shouldUseNameSpace = agpVersion >= 7
|
|
|
|
|
def PACKAGE_PROP = "package=\"com.reactnativecommunity.cameraroll\""
|
|
|
|
|
def manifestOutFile = file("${projectDir}/src/main/AndroidManifest.xml")
|
|
|
|
|
def manifestContent = manifestOutFile.getText()
|
|
|
|
|
if(shouldUseNameSpace){
|
|
|
|
|
manifestContent = manifestContent.replaceAll(
|
|
|
|
|
PACKAGE_PROP,
|
|
|
|
|
''
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
if(!manifestContent.contains("$PACKAGE_PROP")){
|
|
|
|
|
manifestContent = manifestContent.replace(
|
|
|
|
|
'<manifest',
|
|
|
|
|
"<manifest $PACKAGE_PROP "
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
manifestContent.replaceAll(" ", " ")
|
|
|
|
|
manifestOutFile.write(manifestContent)
|
|
|
|
|
|
2019-02-24 10:52:56 +08:00
|
|
|
android {
|
2023-06-26 11:26:44 +02:00
|
|
|
if(shouldUseNameSpace){
|
2023-06-26 17:18:12 -04:00
|
|
|
namespace = "com.reactnativecommunity.cameraroll"
|
2023-06-26 11:26:44 +02:00
|
|
|
}
|
2019-03-03 15:43:30 +08:00
|
|
|
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
|
2022-08-21 16:22:32 +08:00
|
|
|
|
2023-03-09 14:47:47 +01:00
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-21 16:22:32 +08:00
|
|
|
compileOptions {
|
|
|
|
|
sourceCompatibility JavaVersion.VERSION_1_8
|
|
|
|
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
|
|
|
}
|
2019-02-24 10:52:56 +08:00
|
|
|
|
2019-03-03 15:43:30 +08:00
|
|
|
defaultConfig {
|
|
|
|
|
minSdkVersion getExtOrIntegerDefault('minSdkVersion')
|
|
|
|
|
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
|
|
|
|
|
}
|
2023-03-09 14:47:47 +01:00
|
|
|
|
|
|
|
|
sourceSets.main {
|
|
|
|
|
java {
|
|
|
|
|
if (!isNewArchitectureEnabled()) {
|
|
|
|
|
srcDirs += 'src/paper/java'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-21 16:22:32 +08:00
|
|
|
lintOptions{
|
|
|
|
|
abortOnError false
|
|
|
|
|
}
|
2019-02-24 10:52:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
repositories {
|
2022-08-21 16:22:32 +08:00
|
|
|
maven {
|
|
|
|
|
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
|
|
|
url "$rootDir/../node_modules/react-native/android"
|
|
|
|
|
}
|
2019-03-03 15:43:30 +08:00
|
|
|
google()
|
2022-08-21 16:22:32 +08:00
|
|
|
mavenLocal()
|
2019-03-03 15:43:30 +08:00
|
|
|
mavenCentral()
|
2019-02-24 10:52:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dependencies {
|
2023-03-09 14:47:47 +01:00
|
|
|
if (isNewArchitectureEnabled() && REACT_NATIVE_MINOR_VERSION < 71) {
|
|
|
|
|
implementation project(":ReactAndroid")
|
|
|
|
|
} else {
|
|
|
|
|
//noinspection GradleDynamicVersion
|
|
|
|
|
implementation 'com.facebook.react:react-native:+'
|
|
|
|
|
}
|
2023-03-13 11:24:14 +01:00
|
|
|
}
|