Skip to content

Commit

Permalink
refactor: drop Android.mk and support for old versions of React Nativ…
Browse files Browse the repository at this point in the history
…e for new architecture

As the new architecture is constantly a moving target, we only plan to keep support for latest version of React Native when using new architecture until its stable. So this change removes support for React Native 0.68 using Android.mk for the new architecture
  • Loading branch information
satya164 committed Oct 19, 2023
1 parent ef69d0d commit 8c1a0c3
Show file tree
Hide file tree
Showing 10 changed files with 1 addition and 232 deletions.
12 changes: 0 additions & 12 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ const SWIFT_FILES = {
view_legacy: path.resolve(__dirname, '../templates/swift-view-legacy'),
} as const;

const CPP_VIEW_FILES = {
// view_legacy does NOT need component registration
view_mixed: path.resolve(__dirname, '../templates/cpp-view-mixed'),
view_new: path.resolve(__dirname, '../templates/cpp-view-new'),
} as const;

type ArgName =
| 'slug'
| 'description'
Expand Down Expand Up @@ -747,12 +741,6 @@ async function create(argv: yargs.Arguments<any>) {
await copyDir(CPP_FILES, folder);
await fs.remove(path.join(folder, 'ios', `${options.project.name}.m`));
}

if (moduleType === 'view') {
if (arch === 'new' || arch === 'mixed') {
await copyDir(CPP_VIEW_FILES[`${moduleType}_${arch}`], folder);
}
}
}

if (example !== 'none') {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@
import com.facebook.react.uimanager.ViewManagerDelegate;
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerDelegate;
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerInterface;
import com.facebook.soloader.SoLoader;

public abstract class <%- project.name -%>ViewManagerSpec<T extends View> extends SimpleViewManager<T> implements <%- project.name -%>ViewManagerInterface<T> {
static {
if (BuildConfig.CODEGEN_MODULE_REGISTRATION != null) {
SoLoader.loadLibrary(BuildConfig.CODEGEN_MODULE_REGISTRATION);
}
}

private final ViewManagerDelegate<T> mDelegate;

public <%- project.name -%>ViewManagerSpec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerDelegate;
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerInterface;
import com.facebook.soloader.SoLoader;

@ReactModule(name = <%- project.name -%>ViewManager.NAME)
public class <%- project.name -%>ViewManager extends SimpleViewManager<<%- project.name -%>View> implements <%- project.name -%>ViewManagerInterface<<%- project.name -%>View> {

public static final String NAME = "<%- project.name -%>View";

static {
if (BuildConfig.CODEGEN_MODULE_REGISTRATION != null) {
SoLoader.loadLibrary(BuildConfig.CODEGEN_MODULE_REGISTRATION);
}
}

private final ViewManagerDelegate<<%- project.name -%>View> mDelegate;

public <%- project.name -%>ViewManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerDelegate
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerInterface
import com.facebook.soloader.SoLoader

abstract class <%- project.name -%>ViewManagerSpec<T : View> : SimpleViewManager<T>(), <%- project.name -%>ViewManagerInterface<T> {
private val mDelegate: ViewManagerDelegate<T>
Expand All @@ -19,12 +18,4 @@ abstract class <%- project.name -%>ViewManagerSpec<T : View> : SimpleViewManager
override fun getDelegate(): ViewManagerDelegate<T>? {
return mDelegate
}

companion object {
init {
if (BuildConfig.CODEGEN_MODULE_REGISTRATION != null) {
SoLoader.loadLibrary(BuildConfig.CODEGEN_MODULE_REGISTRATION)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.facebook.react.uimanager.ViewManagerDelegate
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerInterface
import com.facebook.react.viewmanagers.<%- project.name -%>ViewManagerDelegate
import com.facebook.soloader.SoLoader

@ReactModule(name = <%- project.name -%>ViewManager.NAME)
class <%- project.name -%>ViewManager : SimpleViewManager<<%- project.name -%>View>(),
Expand Down Expand Up @@ -38,11 +37,5 @@ class <%- project.name -%>ViewManager : SimpleViewManager<<%- project.name -%>Vi

companion object {
const val NAME = "<%- project.name -%>View"

init {
if (BuildConfig.CODEGEN_MODULE_REGISTRATION != null) {
SoLoader.loadLibrary(BuildConfig.CODEGEN_MODULE_REGISTRATION)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,6 @@ apply plugin: "com.android.library"
apply plugin: "kotlin-android"
<% } -%>

<% if (project.view && (project.arch === "new" || project.arch === "mixed")) { -%>
import groovy.json.JsonSlurper

// https://github.com/callstack/react-native-builder-bob/discussions/359
def registrationCompat = {
// The new distribution model uses Maven Central https://reactnative.dev/blog/2023/01/12/version-071
def reactAndroidProject = rootProject.allprojects.find { it.name == 'ReactAndroid' }
if (reactAndroidProject == null) return false

def reactNativeManifest = file("${reactAndroidProject.projectDir}/../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 = "<%- project.name + 'View' -%>"
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"
}
Expand Down Expand Up @@ -86,7 +59,7 @@ android {
}
}

<% if (project.cpp || (project.view && (project.arch === "new" || project.arch === "mixed"))) { -%>
<% if (project.cpp) { -%>
ndkVersion getExtOrDefault("ndkVersion")
<% } -%>
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
Expand All @@ -96,9 +69,6 @@ android {
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
<% if (project.arch === "new" || project.arch === "mixed") { -%>
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
<% if (project.view) { -%>
buildConfigField "String", "CODEGEN_MODULE_REGISTRATION", (isNewArchitectureEnabled() && registrationCompat ? "\"${codegenViewModuleName}_registration\"" : "null")
<% } -%>
<% } -%>

<% if (project.cpp) { -%>
Expand All @@ -108,25 +78,6 @@ android {
abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
}
}
<% } else if (project.view && (project.arch === "new" || project.arch === "mixed")) { -%>
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 (project.cpp) { -%>
Expand All @@ -136,16 +87,6 @@ android {
path "CMakeLists.txt"
}
}
<% } else if (project.view && (project.arch === "new" || project.arch === "mixed")) { -%>

if (isNewArchitectureEnabled() && registrationCompat) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
ndkBuild {
path "Android.mk"
}
}
}
<% } -%>
<% if (project.arch === "new" || project.arch === "mixed") { -%>

Expand Down Expand Up @@ -221,11 +162,7 @@ dependencies {
if (isNewArchitectureEnabled()) {
react {
jsRootDir = file("../src/")
<% if (project.view) { -%>
libraryName = codegenViewLibraryName
<% } else { -%>
libraryName = "<%- project.view ? project.name + 'View' : project.name -%>"
<% } -%>
codegenJavaPackageName = "com.<%- project.package -%>"
}
}
Expand Down

0 comments on commit 8c1a0c3

Please sign in to comment.