Skip to content

Commit

Permalink
Update build.gradle file
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Nov 19, 2024
1 parent 5cbfa9e commit 16150d2
Showing 1 changed file with 11 additions and 52 deletions.
63 changes: 11 additions & 52 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,6 @@ def isHmsEnabled() {
return (rootProject.hasProperty("airshipHmsEnabled") && rootProject.getProperty("airshipHmsEnabled") == "true") || (rootProject.ext.has("airshipHmsEnabled") && rootProject.ext.get("airshipHmsEnabled") == "true")
}

def resolveReactNativeDirectory() {
def reactNativeLocation = rootProject.hasProperty("reactNativeDir") ? rootProject.getProperty("reactNativeDir") : null

if (reactNativeLocation != null) {
return file(reactNativeLocation)
}

try {
// Resolve React Native location with Node
// This will make sure that we get installation location correctly in monorepos
def reactNativePackageJsonPathStdout = new ByteArrayOutputStream()

exec {
commandLine("node", "-p", "require.resolve('react-native/package.json')")
ignoreExitValue true
standardOutput = reactNativePackageJsonPathStdout
}

def reactNativeFromProjectNodeModules = file(reactNativePackageJsonPathStdout.toString().trim()).getParentFile();

if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}
} catch (e) {
// Ignore
}

throw new Exception(
"react-native-airship: Failed to resolve 'react-native' in the project. " +
"If you have a non-standard project structure, you can specify 'reactNativeDir' with the path to 'react-native' in your 'gradle.properties' file."
)
}


def reactNativeRootDir = resolveReactNativeDirectory()
def reactProperties = new Properties()
file("$reactNativeRootDir/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }

def reactNativeVersion = reactProperties.getProperty("VERSION_NAME")
def (reactNativeMajorVersion, reactNativeMinorVersion) = reactNativeVersion.split("\\.").collect { it.isInteger() ? it.toInteger() : it }


apply plugin: "com.android.library"
apply plugin: "kotlin-android"
Expand All @@ -81,6 +40,7 @@ def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Airship_" + name]).toInteger()
}


android {
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

Expand Down Expand Up @@ -111,12 +71,13 @@ android {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"src/newarch/java",
// This is needed to build Kotlin project with NewArch enabled
"${project.buildDir}/generated/source/codegen/java"
"src/newarch",
// Codegen specs
"generated/java",
"generated/jni"
]
} else {
java.srcDirs += ["src/oldarch/java"]
java.srcDirs += ["src/oldarch"]
}
}
}
Expand All @@ -142,14 +103,12 @@ def proxy_version = getExtOrDefault("airshipProxyVersion")
def airship_version = getExtOrDefault("airshipVersion")

dependencies {
if (reactNativeMajorVersion == 0 && reactNativeMinorVersion < 71) {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
} else {
implementation "com.facebook.react:react-android"
}

// 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 "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

api "com.urbanairship.android:airship-framework-proxy:$proxy_version"

if (isHmsEnabled()) {
Expand Down

0 comments on commit 16150d2

Please sign in to comment.