Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Commit 2b26576

Browse files
committed
fix android gradle lint
1 parent f57f5c9 commit 2b26576

File tree

9 files changed

+65
-230
lines changed

9 files changed

+65
-230
lines changed

bun.lockb

456 Bytes
Binary file not shown.

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"react-native-quick-base64": "2.1.2",
3434
"react-native-quick-crypto": "workspace:^",
3535
"react-native-safe-area-context": "4.10.8",
36-
"react-native-screens": "3.34.0",
36+
"react-native-screens": "3.32.0",
3737
"react-native-vector-icons": "^10.1.0",
3838
"readable-stream": "4.5.2",
3939
"util": "0.12.5"
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
project(QuickCrypto)
22
cmake_minimum_required(VERSION 3.9.0)
33

4-
set(PACKAGE_NAME "QuickCrypto")
4+
set(PACKAGE_NAME QuickCrypto)
55
set(CMAKE_VERBOSE_MAKEFILE ON)
66
set(CMAKE_CXX_STANDARD 20)
77

88
# Add Nitrogen specs :)
99
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/QuickCrypto+autolinking.cmake)
1010

1111
# Third party libraries (Prefabs)
12-
find_package(openssl REQUIRED CONFIG)
1312
find_library(LOG_LIB log)
13+
find_library(REACT_NATIVE_SCREENS_LIB rnscreens)
1414

15+
# Define C++ library and add all sources
1516
add_library(
16-
${PACKAGE_NAME}
17-
SHARED
18-
"src/main/cpp/cpp-adapter.cpp"
19-
"../cpp/HybridRandom.cpp"
17+
${PACKAGE_NAME} SHARED
18+
src/main/cpp/cpp-adapter.cpp
19+
../cpp/HybridRandom.cpp
2020
)
2121

2222
# Link all libraries together
2323
target_link_libraries(
2424
${PACKAGE_NAME}
2525
${LOG_LIB} # <-- Logcat logger
26+
${REACT_NATIVE_SCREENS_LIB} # <-- React Native Screens
2627
android # <-- Android core
27-
openssl::crypto # <-- OpenSSL (Crypto)
2828
)
Lines changed: 54 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,54 @@
1-
import java.nio.file.Paths
2-
import com.android.Version
3-
4-
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
5-
def agpVersionMajor = agpVersion.tokenize('.')[0].toInteger()
6-
def agpVersionMinor = agpVersion.tokenize('.')[1].toInteger()
7-
81
buildscript {
92
repositories {
10-
maven {
11-
url "https://plugins.gradle.org/m2/"
12-
}
13-
mavenCentral()
143
google()
4+
mavenCentral()
155
}
166

177
dependencies {
18-
classpath("com.android.tools.build:gradle:8.3.1")
8+
classpath "com.android.tools.build:gradle:7.2.1"
199
}
2010
}
2111

22-
def isNewArchitectureEnabled() {
23-
// To opt-in for the New Architecture, you can either:
24-
// - Set `newArchEnabled` to true inside the `gradle.properties` file
25-
// - Invoke gradle with `-newArchEnabled=true`
26-
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
27-
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
12+
def reactNativeArchitectures() {
13+
def value = rootProject.getProperties().get("reactNativeArchitectures")
14+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
2815
}
2916

30-
def resolveBuildType() {
31-
Gradle gradle = getGradle()
32-
String tskReqStr = gradle.getStartParameter().getTaskRequests()['args'].toString()
33-
34-
return tskReqStr.contains('Release') ? 'release' : 'debug'
17+
def isNewArchitectureEnabled() {
18+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
3519
}
3620

37-
apply plugin: 'com.android.library'
21+
apply plugin: "com.android.library"
3822
apply plugin: 'org.jetbrains.kotlin.android'
3923
apply from: '../nitrogen/generated/android/QuickCrypto+autolinking.gradle'
4024

4125
if (isNewArchitectureEnabled()) {
4226
apply plugin: "com.facebook.react"
4327
}
4428

45-
def safeExtGet(prop, fallback) {
46-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
47-
}
48-
49-
def reactNativeArchitectures() {
50-
def value = project.getProperties().get("reactNativeArchitectures")
51-
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
52-
}
53-
54-
static def findNodeModules(baseDir) {
55-
def basePath = baseDir.toPath().normalize()
56-
// Node's module resolution algorithm searches up to the root directory,
57-
// after which the base path will be null
58-
while (basePath) {
59-
def nodeModulesPath = Paths.get(basePath.toString(), "node_modules")
60-
def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native")
61-
if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) {
62-
return nodeModulesPath.toString()
63-
}
64-
basePath = basePath.getParent()
65-
}
66-
throw new GradleException("react-native-quick-crypto: Failed to find node_modules/ path!")
29+
def getExtOrDefault(name) {
30+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["Nitro_" + name]
6731
}
6832

69-
def nodeModules = findNodeModules(projectDir)
70-
71-
repositories {
72-
google()
73-
mavenCentral()
33+
def getExtOrIntegerDefault(name) {
34+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["Nitro_" + name]).toInteger()
7435
}
7536

7637
android {
77-
compileSdkVersion safeExtGet("compileSdkVersion", 31)
38+
namespace "com.margelo.nitro.quickcrypto"
7839

79-
if ((agpVersionMajor == 7 && agpVersionMinor >= 3) || agpVersionMajor >= 8) {
80-
// Namespace support was added in 7.3.0
81-
namespace "com.margelo.quickcrypto"
82-
83-
sourceSets {
84-
main {
85-
manifest.srcFile "src/main/AndroidManifestNew.xml"
86-
}
87-
}
88-
}
89-
90-
if (agpVersionMajor >= 8) {
91-
buildFeatures {
92-
buildConfig = true
93-
}
94-
}
95-
96-
// Used to override the NDK path/version on internal CI or by allowing
97-
// users to customize the NDK path/version from their root project (e.g. for M1 support)
98-
if (rootProject.hasProperty("ndkPath")) {
99-
ndkPath rootProject.ext.ndkPath
100-
}
101-
if (rootProject.hasProperty("ndkVersion")) {
102-
ndkVersion rootProject.ext.ndkVersion
103-
}
104-
105-
buildFeatures {
106-
prefab true
107-
}
40+
ndkVersion getExtOrDefault("ndkVersion")
41+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
10842

10943
defaultConfig {
110-
minSdkVersion safeExtGet('minSdkVersion', 28)
111-
targetSdkVersion safeExtGet('targetSdkVersion', 31)
112-
versionCode 1
113-
versionName "1.0"
44+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
45+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
11446
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
47+
11548
externalNativeBuild {
11649
cmake {
117-
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all -DANDROID"
118-
arguments "-DANDROID_STL=c++_shared", "-DNODE_MODULES_DIR=${nodeModules}"
50+
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
51+
arguments "-DANDROID_STL=c++_shared"
11952
abiFilters (*reactNativeArchitectures())
12053
}
12154
}
@@ -127,67 +60,64 @@ android {
12760
}
12861
}
12962

130-
packagingOptions {
131-
doNotStrip resolveBuildType() == 'debug' ? "**/**/*.so" : ''
132-
excludes = [
133-
"**/libc++_shared.so",
134-
"**/libfbjni.so",
135-
"**/libreactnativejni.so",
136-
"**/libjsi.so",
137-
"**/libreact_nativemodule_core.so",
138-
"**/libturbomodulejsijni.so",
139-
"**/MANIFEST.MF",
140-
]
63+
buildFeatures {
64+
buildConfig true
65+
prefab true
14166
}
14267

14368
buildTypes {
14469
release {
14570
minifyEnabled false
14671
}
147-
debug {
148-
packagingOptions {
149-
doNotStrip '**/*.so'
150-
}
151-
minifyEnabled false
152-
debuggable true
153-
jniDebuggable true
154-
renderscriptDebuggable true
155-
}
15672
}
15773

15874
lintOptions {
159-
disable 'GradleCompatible'
75+
disable "GradleCompatible"
16076
}
77+
16178
compileOptions {
16279
sourceCompatibility JavaVersion.VERSION_1_8
16380
targetCompatibility JavaVersion.VERSION_1_8
16481
}
16582

83+
sourceSets {
84+
main {
85+
if (isNewArchitectureEnabled()) {
86+
java.srcDirs += [
87+
// React Codegen files
88+
"${project.buildDir}/generated/source/codegen/java"
89+
]
90+
}
91+
}
92+
}
16693
}
16794

16895
repositories {
16996
mavenCentral()
17097
google()
17198
}
17299

100+
173101
dependencies {
102+
// For < 0.71, this will be from the local maven repo
103+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
174104
//noinspection GradleDynamicVersion
175-
implementation "com.facebook.react:react-android:+"
176-
// https://mvnrepository.com/artifact/com.android.ndk.thirdparty/openssl
177-
implementation 'com.android.ndk.thirdparty:openssl:1.1.1q-beta-1'
105+
implementation "com.facebook.react:react-native:+"
106+
107+
// Add a dependency on NitroModules
108+
implementation project(":react-native-nitro-modules")
109+
110+
// Add a dependency on React Native Screens
111+
implementation project(':react-native-screens')
112+
113+
// Add a dependency on React Native Vector Icons
114+
implementation project(':react-native-vector-icons')
178115
}
179116

180-
// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
181-
tasks.whenTaskAdded { task ->
182-
if (task.name.contains("configureCMakeDebug")) {
183-
rootProject.getTasksByName("packageReactNdkDebugLibs", true).forEach {
184-
task.dependsOn(it)
185-
}
186-
}
187-
// We want to add a dependency for both configureCMakeRelease and configureCMakeRelWithDebInfo
188-
if (task.name.contains("configureCMakeRel")) {
189-
rootProject.getTasksByName("packageReactNdkReleaseLibs", true).forEach {
190-
task.dependsOn(it)
191-
}
117+
if (isNewArchitectureEnabled()) {
118+
react {
119+
jsRootDir = file("../src/")
120+
libraryName = "QuickCrypto"
121+
codegenJavaPackageName = "com.margelo.nitro.quickcrypto"
192122
}
193-
}
123+
}
File renamed without changes.

packages/react-native-quick-crypto/android/src/main/cpp/cpp-adapter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
using namespace margelo::nitro::crypto;
77

88
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
9-
HybridObjectRegistry::registerHybridObjectConstructor(
10-
"Random", []() -> std::shared_ptr<HybridObject> { return std::make_shared<HybridRandom>(); });
9+
HybridObjectRegistry::registerHybridObjectConstructor("Random",
10+
[]() -> std::shared_ptr<HybridObject> { return std::make_shared<HybridRandom>(); });
1111

1212
return JNI_VERSION_1_2;
1313
}

packages/react-native-quick-crypto/android/src/main/java/com/margelo/quickcrypto/QuickCryptoModule.java

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

packages/react-native-quick-crypto/android/src/main/java/com/margelo/quickcrypto/QuickCryptoPackage.java

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

0 commit comments

Comments
 (0)