Skip to content

Commit

Permalink
Update RN in sample app and completely redo android
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Franco committed Mar 6, 2022
1 parent d4451f5 commit 27ab7e2
Show file tree
Hide file tree
Showing 26 changed files with 5,249 additions and 2,551 deletions.
2 changes: 2 additions & 0 deletions .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ project.xcworkspace
.idea
.gradle
local.properties
android.iml
*.iml
*.hprof

# Cocoapods
#
Expand Down
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby '2.7.4'
gem 'cocoapods', '~> 1.11', '>= 1.11.2'
33 changes: 6 additions & 27 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
cmake_minimum_required(VERSION 3.4.1)
cmake_minimum_required(VERSION 3.9.0)

set (PACKAGE_NAME "react-native-quick-sqlite")
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 11)

# Uncomment the following lines to compile the example project
include_directories(
../cpp
../node_modules/react-native/React
../node_modules/react-native/React/Base
../node_modules/react-native/ReactCommon/jsi
"${NODE_MODULES_DIR}/react-native/React"
"${NODE_MODULES_DIR}/react-native/React/Base"
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi"
)

add_library(sequel
SHARED

../node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp
"${NODE_MODULES_DIR}/react-native/ReactCommon/jsi/jsi/jsi.cpp"
../cpp/sequel.cpp
../cpp/sequel.h
../cpp/SequelResult.h
Expand All @@ -25,24 +24,4 @@ add_library(sequel
cpp-adapter.cpp
)

# include_directories(
# ../cpp
# ../../react-native/React
# ../../react-native/React/Base
# ../../react-native/ReactCommon/jsi
# )

# add_library(sequel
# SHARED
# ../../react-native/ReactCommon/jsi/jsi/jsi.cpp
# ../cpp/sequel.cpp
# ../cpp/sequel.h
# ../cpp/SequelResult.h
# ../cpp/react-native-quick-sqlite.cpp
# ../cpp/react-native-quick-sqlite.h
# ../cpp/sqlite3.h
# ../cpp/sqlite3.c
# cpp-adapter.cpp
# )

target_link_libraries(sequel android log)
43 changes: 27 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
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['Sequel_kotlinVersion']

import java.nio.file.Paths

buildscript {
repositories {
google()
jcenter()
mavenCentral()
}

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

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

def getExtOrDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['Sequel_' + name]
Expand All @@ -25,20 +23,39 @@ def getExtOrIntegerDefault(name) {
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['Sequel_' + name]).toInteger()
}

static def findNodeModules(baseDir) {
def basePath = baseDir.toPath().normalize()
// Node's module resolution algorithm searches up to the root directory,
// after which the base path will be null
while (basePath) {
def nodeModulesPath = Paths.get(basePath.toString(), "node_modules")
def reactNativePath = Paths.get(nodeModulesPath.toString(), "react-native")
if (nodeModulesPath.toFile().exists() && reactNativePath.toFile().exists()) {
return nodeModulesPath.toString()
}
basePath = basePath.getParent()
}
throw new GradleException("react-native-quick-base64: Failed to find node_modules/ path!")
}

def nodeModules = findNodeModules(projectDir);
logger.warn("react-native-quick-sqlite: node_modules/ found at: ${nodeModules}");

android {
compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
buildToolsVersion getExtOrDefault('buildToolsVersion')

defaultConfig {
minSdkVersion 16
minSdkVersion 21
targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
versionCode 1
versionName "1.0"

externalNativeBuild {
cmake {
cppFlags "-O2 -frtti -fexceptions -Wall -Wno-unused-variable -fstack-protector-all"
arguments "-DDEV_CMAKE=true"
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
arguments "-DNODE_MODULES_DIR=${nodeModules}"
}
}

Expand Down Expand Up @@ -66,7 +83,6 @@ android {

repositories {
mavenCentral()
jcenter()
google()

def found = false
Expand All @@ -76,10 +92,7 @@ repositories {
if (rootProject.ext.has('reactNativeAndroidRoot')) {
defaultDir = rootProject.ext.get('reactNativeAndroidRoot')
} else {
defaultDir = new File(
projectDir,
'/../../../node_modules/react-native/android'
)
defaultDir = file("$nodeModules/react-native/android")
}

if (defaultDir.exists()) {
Expand Down Expand Up @@ -135,10 +148,8 @@ repositories {
}
}

def kotlin_version = getExtOrDefault('kotlinVersion')

dependencies {
// noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
8 changes: 4 additions & 4 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sequel_kotlinVersion=1.3.50
Sequel_compileSdkVersion=29
Sequel_buildToolsVersion=29.0.2
Sequel_targetSdkVersion=29
Sequel_kotlinVersion=1.6.0
Sequel_compileSdkVersion=30
Sequel_buildToolsVersion=30
Sequel_targetSdkVersion=30
46 changes: 20 additions & 26 deletions android/src/main/java/com/reactnativesequel/SequelModule.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,39 @@
package com.reactnativequicksqlite;

import androidx.annotation.NonNull;
import android.util.Log;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

class SequelModule extends ReactContextBaseJavaModule {
static {
System.loadLibrary("sequel");
}

public static final String NAME = "QuickSQLite";
private static native void initialize(long jsiPtr, String docDir);
private static native void destruct();

public SequelModule(ReactApplicationContext reactContext) {
super(reactContext);
public SequelModule(ReactApplicationContext context) {
super(context);
}

@NonNull
@Override
public String getName() {
return "Sequel";
return NAME;
}


@NonNull
@Override
public void initialize() {
super.initialize();

// LEFT HERE:
// Convert the second arg into a std::string in the cpp-adapter file
// https://stackoverflow.com/questions/41820039/jstringjni-to-stdstringc-with-utf8-characters
SequelModule.initialize(
this.getReactApplicationContext().getJavaScriptContextHolder().get(),
this.getReactApplicationContext().getFilesDir().getAbsolutePath()
);
}

@Override
public void onCatalystInstanceDestroy() {
SequelModule.destruct();
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean install() {
try {
System.loadLibrary("sequel");

ReactApplicationContext context = getReactApplicationContext();
initialize(
context.getJavaScriptContextHolder().get(),
context.getFilesDir().getAbsolutePath()
);
return true;
} catch (Exception exception) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SequelPackage implements ReactPackage {
@NonNull
@Override
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new SequelModule(reactContext));
return Collections.singletonList(new SequelModule(reactContext));
}

@NonNull
Expand Down
16 changes: 9 additions & 7 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,9 @@ def jscFlavor = 'org.webkit:android-jsc:+'
def enableHermes = project.ext.react.get("enableHermes", false);

android {
compileSdkVersion rootProject.ext.compileSdkVersion
ndkVersion rootProject.ext.ndkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
applicationId "com.example.reactnativequicksqlite"
Expand Down Expand Up @@ -153,6 +150,11 @@ android {
buildTypes {
debug {
signingConfig signingConfigs.debug
// if (nativeArchitectures) {
// ndk {
// abiFilters nativeArchitectures.split(',')
// }
// }
}
release {
// Caution! In production, you need to generate your own keystore file.
Expand All @@ -171,7 +173,7 @@ android {
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}

}
Expand Down Expand Up @@ -200,7 +202,7 @@ dependencies {
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
from configurations.implementation
into 'libs'
}

Expand Down
7 changes: 6 additions & 1 deletion example/android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
<application
android:usesCleartextTraffic="true"
tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
1 change: 0 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public boolean getUseDeveloperSupport() {
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for SequelExample:
// packages.add(new MyReactNativePackage());
packages.add(new SequelPackage());
return packages;
}
Expand All @@ -46,6 +44,5 @@ public ReactNativeHost getReactNativeHost() {
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
// initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="@dimen/abc_edit_text_inset_horizontal_material"
android:insetRight="@dimen/abc_edit_text_inset_horizontal_material"
android:insetTop="@dimen/abc_edit_text_inset_top_material"
android:insetBottom="@dimen/abc_edit_text_inset_bottom_material">
<selector>
<!--
This file is a copy of abc_edit_text_material (https://bit.ly/3k8fX7I).
The item below with state_pressed="false" and state_focused="false" causes a NullPointerException.
NullPointerException:tempt to invoke virtual method 'android.graphics.drawable.Drawable android.graphics.drawable.Drawable$ConstantState.newDrawable(android.content.res.Resources)'
<item android:state_pressed="false" android:state_focused="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/>
For more info, see https://bit.ly/3CdLStv (react-native/pull/29452) and https://bit.ly/3nxOMoR.
-->
<item android:state_enabled="false" android:drawable="@drawable/abc_textfield_default_mtrl_alpha"/>
<item android:drawable="@drawable/abc_textfield_activated_mtrl_alpha"/>
</selector>
</inset>
5 changes: 2 additions & 3 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:textColor">#000000</item>
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
</style>

</resources>
Loading

0 comments on commit 27ab7e2

Please sign in to comment.