Skip to content

Commit a1297e4

Browse files
committed
feat: add new arch support
1 parent 3a0da89 commit a1297e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+5766
-4669
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,9 @@ android/keystores/debug.keystore
7777
# generated by bob
7878
lib/
7979

80+
# React Native Codegen
81+
ios/generated
82+
android/generated
83+
8084
# tests
8185
.tap

.yarnrc.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ nodeLinker: node-modules
22
nmHoistingLimits: workspaces
33

44
plugins:
5-
- path: scripts/pod-install.cjs
65
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
76
spec: "@yarnpkg/plugin-interactive-tools"
87
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 David Angulo
3+
Copyright (c) 2024 David Angulo
44
Permission is hereby granted, free of charge, to any person obtaining a copy
55
of this software and associated documentation files (the "Software"), to deal
66
in the Software without restriction, including without limitation the rights

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@ Proof Key for Code Exchange (PKCE) challenge generator for React Native.
1717
|Node.js |🟢
1818

1919
## Installation
20+
### New Arch
2021
```bash
2122
yarn add react-native-pkce-challenge
22-
npx pod-install ios # iOS Only
23-
npx pod-install macos # macOS Only
23+
npx pod-install
24+
```
25+
26+
### Old Arch
27+
```bash
28+
29+
npx pod-install
2430
```
2531

2632
## Usage
@@ -60,4 +66,8 @@ See [UPGRADING.md](UPGRADING.md)
6066
See [CHANGELOGS.md](CHANGELOGS.md)
6167

6268
## License
63-
Copyright © 2023 David Angulo, released under the MIT license, see [LICENSE](LICENSE).
69+
Copyright © 2024 David Angulo, released under the MIT license, see [LICENSE](LICENSE).
70+
71+
---
72+
73+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

android/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(PkceChallenge)
44
set (CMAKE_VERBOSE_MAKEFILE ON)
55
set (CMAKE_CXX_STANDARD 14)
66

7-
add_library(cpp
7+
add_library(react-native-pkce-challenge
88
SHARED
99
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp"
1010
../cpp/react-native-pkce-challenge.cpp

android/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import java.nio.file.Paths
22
import org.apache.tools.ant.taskdefs.condition.Os
33

44
buildscript {
5+
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
6+
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["PkceChallenge_kotlinVersion"]
7+
58
repositories {
69
google()
710
mavenCentral()
811
}
912

1013
dependencies {
1114
classpath "com.android.tools.build:gradle:7.2.1"
15+
// noinspection DifferentKotlinGradleVersion
16+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1217
}
1318
}
1419

@@ -33,11 +38,17 @@ static def findNodeModules(baseDir) {
3338

3439
def nodeModules = findNodeModules(projectDir)
3540

41+
def reactNativeArchitectures() {
42+
def value = rootProject.getProperties().get("reactNativeArchitectures")
43+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
44+
}
45+
3646
def isNewArchitectureEnabled() {
3747
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
3848
}
3949

4050
apply plugin: "com.android.library"
51+
apply plugin: "kotlin-android"
4152

4253
if (isNewArchitectureEnabled()) {
4354
apply plugin: "com.facebook.react"
@@ -77,11 +88,13 @@ android {
7788
defaultConfig {
7889
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
7990
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
91+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
8092

8193
externalNativeBuild {
8294
cmake {
8395
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
8496
arguments "-DNODE_MODULES_DIR=${nodeModules}"
97+
abiFilters (*reactNativeArchitectures())
8598
}
8699
}
87100
}
@@ -92,6 +105,10 @@ android {
92105
}
93106
}
94107

108+
buildFeatures {
109+
buildConfig true
110+
}
111+
95112
buildTypes {
96113
release {
97114
minifyEnabled false
@@ -106,18 +123,38 @@ android {
106123
sourceCompatibility JavaVersion.VERSION_1_8
107124
targetCompatibility JavaVersion.VERSION_1_8
108125
}
126+
127+
sourceSets {
128+
main {
129+
if (isNewArchitectureEnabled()) {
130+
java.srcDirs += [
131+
"generated/java",
132+
"generated/jni"
133+
]
134+
}
135+
}
136+
}
109137
}
110138

111139
repositories {
112140
mavenCentral()
113141
google()
114142
}
115143

144+
def kotlin_version = getExtOrDefault("kotlinVersion")
116145

117146
dependencies {
118147
// For < 0.71, this will be from the local maven repo
119148
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
120149
//noinspection GradleDynamicVersion
121150
implementation "com.facebook.react:react-native:+"
151+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
122152
}
123153

154+
if (isNewArchitectureEnabled()) {
155+
react {
156+
jsRootDir = file("../src/")
157+
libraryName = "PkceChallenge"
158+
codegenJavaPackageName = "com.pkcechallenge"
159+
}
160+
}

android/cpp-adapter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22
#include "react-native-pkce-challenge.h"
33

44
extern "C"
5-
JNIEXPORT void JNICALL
6-
Java_com_pkcechallenge_PkceChallengeModule_nativeInstall(JNIEnv *env, jobject thiz, jlong jsi) {
7-
auto runtime = reinterpret_cast<facebook::jsi::Runtime *>(jsi);
5+
JNIEXPORT jstring JNICALL
6+
Java_com_pkcechallenge_PkceChallengeModule_nativeGetRandomBase64String(JNIEnv *env, jclass type, jdouble byte_length) {
7+
std::string encoded_data = pkcechallenge::getRandomBase64String(byte_length);
88

9-
if (runtime)
10-
{
11-
pkcechallenge::install(*runtime);
12-
}
9+
return env->NewStringUTF(encoded_data.c_str());
1310
}

android/src/main/java/com/pkcechallenge/PkceChallengeModule.java

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.pkcechallenge
2+
3+
import com.facebook.react.bridge.ReactApplicationContext
4+
import com.facebook.react.module.annotations.ReactModule
5+
6+
import java.security.SecureRandom
7+
import android.util.Base64
8+
9+
@ReactModule(name = PkceChallengeModule.NAME)
10+
class PkceChallengeModule(reactContext: ReactApplicationContext) :
11+
NativePkceChallengeSpec(reactContext) {
12+
13+
override fun getName(): String {
14+
return NAME
15+
}
16+
17+
// Example method
18+
// See https://reactnative.dev/docs/native-modules-android
19+
override fun getRandomBase64String(byteLength: Double): String {
20+
val bytes = ByteArray(byteLength.toInt())
21+
val secureRandom = SecureRandom()
22+
secureRandom.nextBytes(bytes)
23+
24+
return Base64.encodeToString(bytes, Base64.NO_WRAP)
25+
}
26+
27+
companion object {
28+
const val NAME = "PkceChallenge"
29+
}
30+
}

android/src/main/java/com/pkcechallenge/PkceChallengePackage.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)