Skip to content

Commit

Permalink
feat(*): add support for new architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Aug 17, 2023
1 parent 4719728 commit 447fad0
Show file tree
Hide file tree
Showing 112 changed files with 26,067 additions and 7,651 deletions.
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ project.xcworkspace

# Android/IJ
#
.idea
.classpath
.cxx
.gradle
.idea
.project
.settings
local.properties
android.iml

# Cocoapods
#
example/ios/Pods

# Ruby
example/vendor/

# node.js
#
node_modules/
Expand All @@ -54,7 +61,10 @@ android/app/libs
android/keystores/debug.keystore

# Expo
.expo/*
.expo/

# Turborepo
.turbo/

# generated by bob
lib/
45 changes: 45 additions & 0 deletions android/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
THIS_DIR := $(call my-dir)

include $(REACT_ANDROID_DIR)/Android-prebuilt.mk

include ${GENERATED_SRC_DIR}/codegen/jni/Android.mk

include $(CLEAR_VARS)

LOCAL_PATH := $(THIS_DIR)

# Define the library name here.
LOCAL_MODULE := ${CODEGEN_MODULE_NAME}_registration

LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp)

LOCAL_SHARED_LIBRARIES := \
libfabricjni \
libfbjni \
libglog \
libjsi \
libreact_codegen_rncore \
libreact_codegen_${CODEGEN_MODULE_NAME} \
libreact_debug \
libreact_nativemodule_core \
libreact_render_componentregistry \
libreact_render_core \
libreact_render_debug \
libreact_render_graphics \
librrc_view \
libruntimeexecutor \
libturbomodulejsijni \
libyoga

ifneq ($(filter $(call modules-get-list),folly_runtime),)
LOCAL_SHARED_LIBRARIES += libfolly_runtime # since [email protected]
else
LOCAL_SHARED_LIBRARIES += libfolly_futures libfolly_json # [email protected]
endif

LOCAL_CFLAGS := \
-DLOG_TAG=\"ReactNative\" \
-DCODEGEN_COMPONENT_DESCRIPTOR_H="<react/renderer/components/${CODEGEN_MODULE_NAME}/ComponentDescriptors.h>"
LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall

include $(BUILD_SHARED_LIBRARY)
212 changes: 125 additions & 87 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,134 +1,172 @@
buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['ReactNativeLiveStream_kotlinVersion']
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["ApiVideoLivestream_kotlinVersion"]

repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.2'
classpath "com.android.tools.build:gradle:7.2.1"
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

import groovy.json.JsonSlurper

// https://github.com/callstack/react-native-builder-bob/discussions/359
def registrationCompat = {
def reactNativeManifest = file("$projectDir/../node_modules/react-native/package.json").exists()
? file("$projectDir/../node_modules/react-native/package.json") // developer mode, to run example app
: file("$projectDir/../../react-native/package.json")
def reactNativeVersion = new JsonSlurper().parseText(reactNativeManifest.text).version as String
// Fabric was introduced at [email protected], full CMake support were introduced at [email protected]
// Use Android.mk for compatibility with [email protected]/0.69
reactNativeVersion.matches('(0.68.*|0.69.*)')
}()

def codegenViewLibraryName = "ApiVideoLiveStreamView"
def codegenViewModuleName = {
// Autolink for Fabric uses codegenConfig.name in package.json since [email protected]
// Use codegenViewLibraryName for compatibility with [email protected]/0.69
def libraryManifestJson = new JsonSlurper().parseText(file("$projectDir/../package.json").text)
registrationCompat ? codegenViewLibraryName : libraryManifestJson.codegenConfig.name
}()

def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['ReactNativeLiveStream_' + name]
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["ApiVideoLivestream_" + name]
}

def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['ReactNativeLiveStream_' + name]).toInteger()
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["ApiVideoLivestream_" + name]).toInteger()
}

def supportsNamespace() {
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
def major = parsed[0].toInteger()
def minor = parsed[1].toInteger()

// Namespace support was added in 7.3.0
if (major == 7 && minor >= 3) {
return true
}

return major >= 8
}

android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')
defaultConfig {
minSdkVersion 21
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"
multiDexEnabled true
if (supportsNamespace()) {
namespace "video.api.reactnative.livestream"

sourceSets {
main {
manifest.srcFile "src/main/AndroidManifestNew.xml"
}
}
}

ndkVersion getExtOrDefault("ndkVersion")
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

defaultConfig {
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
buildConfigField "String", "CODEGEN_MODULE_REGISTRATION", (isNewArchitectureEnabled() && registrationCompat ? "\"${codegenViewModuleName}_registration\"" : "null")
if (isNewArchitectureEnabled() && registrationCompat) {
def reactAndroidProject = project(':ReactAndroid')
externalNativeBuild {
ndkBuild {
arguments "APP_PLATFORM=android-21",
"APP_STL=c++_shared",
"NDK_TOOLCHAIN_VERSION=clang",
"GENERATED_SRC_DIR=$buildDir/generated/source", // for react_codegen_* in this library's codegen/jni
"PROJECT_BUILD_DIR=${appProject.buildDir}", // for REACT_NDK_EXPORT_DIR in ReactAndroid's Android-prebuilt.mk
"REACT_ANDROID_DIR=${reactAndroidProject.projectDir}",
"REACT_ANDROID_BUILD_DIR=${reactAndroidProject.buildDir}",
"CODEGEN_MODULE_NAME=$codegenViewModuleName"
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
cppFlags "-std=c++17"
targets "${codegenViewModuleName}_registration"
}
}
}
}
if (isNewArchitectureEnabled() && registrationCompat) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
ndkBuild {
path "Android.mk"
}
}
}
buildTypes {
release {
minifyEnabled false
}
}

lintOptions {
disable 'GradleCompatible'
disable "GradleCompatible"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

sourceSets {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"src/newarch",
// This is needed to build Kotlin project with NewArch enabled
"${project.buildDir}/generated/source/codegen/java"
]
} else {
java.srcDirs += ["src/oldarch"]
}
}
}
}

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
google()

def found = false
def defaultDir = null
def androidSourcesName = 'React Native sources'

if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
}

if (defaultDir.exists()) {
maven {
url defaultDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.canonicalPath}")
found = true
} else {
def parentDir = rootProject.projectDir

1.upto(5, {
if (found) return true
parentDir = parentDir.parentFile

def androidSourcesDir = new File(
parentDir,
'node_modules/react-native'
)

def androidPrebuiltBinaryDir = new File(
parentDir,
'node_modules/react-native/android'
)

if (androidPrebuiltBinaryDir.exists()) {
maven {
url androidPrebuiltBinaryDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidPrebuiltBinaryDir.canonicalPath}")
found = true
} else if (androidSourcesDir.exists()) {
maven {
url androidSourcesDir.toString()
name androidSourcesName
}

logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}")
found = true
}
})
}

if (!found) {
throw new GradleException(
"${project.name}: unable to locate React Native android sources. " +
"Ensure you have you installed React Native as a dependency in your project and try again."
)
}
}

def kotlin_version = getExtOrDefault('kotlinVersion')
def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
implementation "androidx.multidex:multidex:2.0.1"
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
// 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"

implementation "video.api:android-live-stream:1.3.1"
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
}

if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
libraryName = codegenViewLibraryName
codegenJavaPackageName = "video.api.reactnative.livestream"
}
}
10 changes: 5 additions & 5 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ReactNativeLiveStream_kotlinVersion=1.5.30
ReactNativeLiveStream_compileSdkVersion=31
ReactNativeLiveStream_buildToolsVersion=30.0.2
ReactNativeLiveStream_targetSdkVersion=31
android.useAndroidX=true
ApiVideoLivestream_kotlinVersion=1.7.0
ApiVideoLivestream_minSdkVersion=21
ApiVideoLivestream_targetSdkVersion=33
ApiVideoLivestream_compileSdkVersion=33
ApiVideoLivestream_ndkversion=21.4.7075529
Binary file removed android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 0 additions & 5 deletions android/gradle/wrapper/gradle-wrapper.properties

This file was deleted.

Loading

0 comments on commit 447fad0

Please sign in to comment.