diff --git a/android/CMakeLists.txt b/android/CMakeLists.txt index a90395c..17bcf67 100644 --- a/android/CMakeLists.txt +++ b/android/CMakeLists.txt @@ -1,63 +1,36 @@ cmake_minimum_required(VERSION 3.9.0) -set (PACKAGE_NAME "react-native-fast-rsa") set (CMAKE_VERBOSE_MAKEFILE ON) set (CMAKE_CXX_STANDARD 14) set (BUILD_DIR ${CMAKE_SOURCE_DIR}/build) add_library(rsa_bridge SHARED IMPORTED) + file(TO_CMAKE_PATH ${NODE_MODULES_DIR} NODE_MODULES_DIR) + set_target_properties(rsa_bridge PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/librsa_bridge.so -) - -include_directories( - ../cpp - "${NODE_MODULES_DIR}/react-native/React" - "${NODE_MODULES_DIR}/react-native/React/Base" - "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi" -) + ) add_library(fast-rsa - SHARED + SHARED + "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp" ../cpp/react-native-fast-rsa.cpp + ../cpp/react-native-fast-rsa.h fast-rsa-adapter.cpp ) -set_target_properties( - fast-rsa PROPERTIES - CXX_STANDARD 14 - CXX_EXTENSIONS OFF - POSITION_INDEPENDENT_CODE ON -) - -file (GLOB LIBRN_DIR "${BUILD_DIR}/react-native-0*/jni/${ANDROID_ABI}") - -find_library( - log-lib - log -) -find_library( - JSI_LIB - jsi - PATHS ${LIBRN_DIR} - NO_CMAKE_FIND_ROOT_PATH -) -find_library( - REACT_NATIVE_JNI_LIB - reactnativejni - PATHS ${LIBRN_DIR} - NO_CMAKE_FIND_ROOT_PATH +include_directories( + fast-rsa + PRIVATE + "${NODE_MODULES_DIR}/react-native/ReactCommon/jsi" + ../cpp ) -target_link_libraries( - fast-rsa +target_link_libraries(fast-rsa rsa_bridge - ${log-lib} - ${JSI_LIB} - ${REACT_NATIVE_JNI_LIB} android -) \ No newline at end of file + log) \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index ddb2895..3bf6cc3 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,345 +1,149 @@ -import groovy.json.JsonSlurper -import org.apache.tools.ant.filters.ReplaceTokens -import java.nio.file.Paths - 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['FastRsa_kotlinVersion'] + // 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['FastRsa_kotlinVersion'] - repositories { - google() - jcenter() - maven { - url "https://plugins.gradle.org/m2/" + repositories { + google() + mavenCentral() + jcenter() } - } dependencies { classpath 'com.android.tools.build:gradle:4.2.2' // noinspection DifferentKotlinGradleVersion classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'de.undercouch:gradle-download-task:4.1.2' } } apply plugin: 'com.android.library' -apply plugin: 'de.undercouch.download' apply plugin: 'kotlin-android' - def getExtOrDefault(name) { return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['FastRsa_' + name] } def getExtOrIntegerDefault(name) { - return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['FastRsa_' + name]).toInteger() + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['FastRsa_' + name]).toInteger() } android { - compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') - buildToolsVersion getExtOrDefault('buildToolsVersion') - ndkVersion getExtOrDefault('ndkVersion') + compileSdkVersion getExtOrIntegerDefault('compileSdkVersion') + buildToolsVersion getExtOrDefault('buildToolsVersion') + defaultConfig { + minSdkVersion 16 + targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') + versionCode 1 + versionName "1.0" + + externalNativeBuild { + cmake { + cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all" + abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' + arguments "-DNODE_MODULES_DIR=${rootDir}/../node_modules" + } + } + } - defaultConfig { - minSdkVersion 21 - targetSdkVersion getExtOrIntegerDefault('targetSdkVersion') - versionCode 1 - versionName "1.0" externalNativeBuild { - cmake { - cppFlags "-fexceptions", "-frtti", "-std=c++1y", "-DONANDROID", "-fexceptions", "-O2", "-Wall", "-Wno-unused-variable", "-fstack-protector-all" - abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' - arguments '-DANDROID_STL=c++_shared', - "-DNODE_MODULES_DIR=${rootDir}/../node_modules" - } + cmake { + version '3.10.2' + path "CMakeLists.txt" + } } - } - externalNativeBuild { - cmake { - path "CMakeLists.txt" + buildTypes { + release { + minifyEnabled false + } } - } - - packagingOptions { - excludes = ["**/libc++_shared.so", "**/libfbjni.so", "**/libjsi.so", "**/libreactnativejni.so"] - pickFirst "**/librsa_bridge.so" - } - - buildTypes { - release { - minifyEnabled false + lintOptions { + disable 'GradleCompatible' + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + packagingOptions { + pickFirst "**/librsa_bridge.so" } - } - lintOptions { - disable 'GradleCompatible' - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - configurations { - extractHeaders - extractJNI - } } repositories { - mavenCentral() - 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' - ) - } + mavenCentral() + jcenter() + google() - if (defaultDir.exists()) { - maven { - url defaultDir.toString() - name androidSourcesName + 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' + ) } - 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()) { + if (defaultDir.exists()) { maven { - url androidSourcesDir.toString() - name androidSourcesName + url defaultDir.toString() + name androidSourcesName } - logger.info(":${project.name}:reactNativeAndroidRoot ${androidSourcesDir.canonicalPath}") + logger.info(":${project.name}:reactNativeAndroidRoot ${defaultDir.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') - -dependencies { - // noinspection GradleDynamicVersion - implementation 'com.facebook.react:react-native:+' - implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - - //noinspection GradleDynamicVersion - extractHeaders("com.facebook.fbjni:fbjni:+:headers") - //noinspection GradleDynamicVersion - extractJNI("com.facebook.fbjni:fbjni:+") - - def rnAAR = fileTree("${rootDir}/../node_modules/react-native/android").matching({ it.include "**/**/*.aar" }).singleFile - extractJNI(files(rnAAR)) -} - - -// third-party-ndk deps headers -// mostly a copy of https://github.com/software-mansion/react-native-reanimated/blob/master/android/build.gradle#L115 - -def downloadsDir = new File("$buildDir/downloads") -def thirdPartyNdkDir = new File("$buildDir/third-party-ndk") -def thirdPartyVersionsFile = new File("${rootDir}/../node_modules/react-native/ReactAndroid/gradle.properties") -def thirdPartyVersions = new Properties() -thirdPartyVersions.load(new FileInputStream(thirdPartyVersionsFile)) - -def BOOST_VERSION = thirdPartyVersions["BOOST_VERSION"] -def boost_file = new File(downloadsDir, "boost_${BOOST_VERSION}.tar.gz") -def DOUBLE_CONVERSION_VERSION = thirdPartyVersions["DOUBLE_CONVERSION_VERSION"] -def double_conversion_file = new File(downloadsDir, "double-conversion-${DOUBLE_CONVERSION_VERSION}.tar.gz") -def FOLLY_VERSION = thirdPartyVersions["FOLLY_VERSION"] -def folly_file = new File(downloadsDir, "folly-${FOLLY_VERSION}.tar.gz") -def GLOG_VERSION = thirdPartyVersions["GLOG_VERSION"] -def glog_file = new File(downloadsDir, "glog-${GLOG_VERSION}.tar.gz") - -task createNativeDepsDirectories { - doLast { - downloadsDir.mkdirs() - thirdPartyNdkDir.mkdirs() - } -} - -task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) { - src("https://github.com/react-native-community/boost-for-react-native/releases/download/v${BOOST_VERSION.replace("_", ".")}-0/boost_${BOOST_VERSION}.tar.gz") - onlyIfNewer(true) - overwrite(false) - dest(boost_file) -} - -task prepareBoost(dependsOn: downloadBoost, type: Copy) { - from(tarTree(resources.gzip(downloadBoost.dest))) - from("src/main/jni/third-party/boost/Android.mk") - include("Android.mk", "boost_${BOOST_VERSION}/boost/**/*.hpp", "boost/boost/**/*.hpp") - includeEmptyDirs = false - into("$thirdPartyNdkDir") // /boost_X_XX_X - doLast { - file("$thirdPartyNdkDir/boost_${BOOST_VERSION}").renameTo("$thirdPartyNdkDir/boost") - } -} - -task downloadDoubleConversion(dependsOn: createNativeDepsDirectories, type: Download) { - src("https://github.com/google/double-conversion/archive/v${DOUBLE_CONVERSION_VERSION}.tar.gz") - onlyIfNewer(true) - overwrite(false) - dest(double_conversion_file) -} - -task prepareDoubleConversion(dependsOn: downloadDoubleConversion, type: Copy) { - from(tarTree(downloadDoubleConversion.dest)) - from("src/main/jni/third-party/double-conversion/Android.mk") - include("double-conversion-${DOUBLE_CONVERSION_VERSION}/src/**/*", "Android.mk") - filesMatching("*/src/**/*", { fname -> fname.path = "double-conversion/${fname.name}" }) - includeEmptyDirs = false - into("$thirdPartyNdkDir/double-conversion") -} - -task downloadFolly(dependsOn: createNativeDepsDirectories, type: Download) { - src("https://github.com/facebook/folly/archive/v${FOLLY_VERSION}.tar.gz") - onlyIfNewer(true) - overwrite(false) - dest(folly_file) -} - -task prepareFolly(dependsOn: downloadFolly, type: Copy) { - from(tarTree(downloadFolly.dest)) - from("src/main/jni/third-party/folly/Android.mk") - include("folly-${FOLLY_VERSION}/folly/**/*", "Android.mk") - eachFile { fname -> fname.path = (fname.path - "folly-${FOLLY_VERSION}/") } - includeEmptyDirs = false - into("$thirdPartyNdkDir/folly") -} - -task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) { - src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz") - onlyIfNewer(true) - overwrite(false) - dest(glog_file) -} - -task prepareGlog(dependsOn: downloadGlog, type: Copy) { - from(tarTree(downloadGlog.dest)) - from("src/main/jni/third-party/glog/") - include("glog-${GLOG_VERSION}/src/**/*", "Android.mk", "config.h") - includeEmptyDirs = false - filesMatching("**/*.h.in") { - filter(ReplaceTokens, tokens: [ - ac_cv_have_unistd_h : "1", - ac_cv_have_stdint_h : "1", - ac_cv_have_systypes_h : "1", - ac_cv_have_inttypes_h : "1", - ac_cv_have_libgflags : "0", - ac_google_start_namespace : "namespace google {", - ac_cv_have_uint16_t : "1", - ac_cv_have_u_int16_t : "1", - ac_cv_have___uint16 : "0", - ac_google_end_namespace : "}", - ac_cv_have___builtin_expect : "1", - ac_google_namespace : "google", - ac_cv___attribute___noinline : "__attribute__ ((noinline))", - ac_cv___attribute___noreturn : "__attribute__ ((noreturn))", - ac_cv___attribute___printf_4_5: "__attribute__((__format__ (__printf__, 4, 5)))" - ]) - it.path = (it.name - ".in") - } - into("$thirdPartyNdkDir/glog") - - doLast { - copy { - from(fileTree(dir: "$thirdPartyNdkDir/glog", includes: ["stl_logging.h", "logging.h", "raw_logging.h", "vlog_is_on.h", "**/src/glog/log_severity.h"]).files) - includeEmptyDirs = false - into("$thirdPartyNdkDir/glog/exported/glog") + } 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 + } + }) } - } -} -task prepareThirdPartyNdkHeaders { - if (!boost_file.exists()) { - dependsOn(prepareBoost) - } - if (!double_conversion_file.exists()) { - dependsOn(prepareDoubleConversion) - } - if (!folly_file.exists()) { - dependsOn(prepareFolly) - } - if (!glog_file.exists()) { - dependsOn(prepareGlog) - } -} - -prepareThirdPartyNdkHeaders.mustRunAfter createNativeDepsDirectories - -task extractAARHeaders { - doLast { - configurations.extractHeaders.files.each { - def file = it.absoluteFile - copy { - from zipTree(file) - into "$buildDir/$file.name" - include "**/*.h" - } + 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." + ) } - } } -extractAARHeaders.mustRunAfter prepareThirdPartyNdkHeaders -task extractJNIFiles { - doLast { - configurations.extractJNI.files.each { - def file = it.absoluteFile - - copy { - from zipTree(file) - into "$buildDir/$file.name" - include "jni/**/*" - } - } - } -} -extractJNIFiles.mustRunAfter extractAARHeaders +def kotlin_version = getExtOrDefault('kotlinVersion') -tasks.whenTaskAdded { task -> - if (task.name == 'externalNativeBuildDebug' || task.name == 'externalNativeBuildRelease') { - task.dependsOn(extractAARHeaders) - task.dependsOn(extractJNIFiles) - task.dependsOn(prepareThirdPartyNdkHeaders) - } +dependencies { + // noinspection GradleDynamicVersion + api 'com.facebook.react:react-native:+' + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } \ No newline at end of file diff --git a/package.json b/package.json index 3b3ef91..9d58b81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-fast-rsa", - "version": "2.3.0", + "version": "2.3.1", "description": "library for use RSA", "main": "lib/commonjs/index", "module": "lib/module/index",