apply plugin: 'com.android.library'


def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3"
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 28
def DEFAULT_NDK_VERSION = "20.1.5948944"

android {
    compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
    buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION
    ndkVersion rootProject.hasProperty('ndkVersion') ? rootProject.ndkVersion : DEFAULT_NDK_VERSION

    namespace "com.nozbe.watermelondb.jsi"

    defaultConfig {
        minSdkVersion rootProject.hasProperty('minSdkVersion') ? rootProject.minSdkVersion : DEFAULT_MIN_SDK_VERSION
        targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            cmake {
                // Not sure if this is necessary. I added this in attempt to fix catching
                // C++ errors across .so bounds, but it still doesn't work, so can probably get rid
                // of this
                // NOTE: It appears that doing this causes some ABI compatibility issues (or something):
                //   libc++_shared.so
                //   libc++_shared.so (__gxx_personality_v0+416)
                //   libreactnativejni.so
                //   libreactnativejni.so (_Unwind_RaiseException+263)
                //   libfbjni.so (__cxa_throw+108)
                //   libc++_shared.so (std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const+212)
                //   libwatermelondb-jsi.so (std::__ndk1::basic_ostream<char, std::__ndk1::char_traits<char>>::operator<<(long long)+124)
                //   libwatermelondb-jsi.so (std::__ndk1::basic_string<char, watermelondb::to_json_string<simdjson::fallback::ondemand::value&>::char_traits<char>, watermelondb::to_json_string<simdjson::fallback::ondemand::value&>::allocator<char>> watermelondb::to_json_string<simdjson::fallback::ondemand::value&>(simdjson::fallback::ondemand::value&&&)+3486)
                // arguments "-DANDROID_STL=c++_shared"
            }
        }
    }
    externalNativeBuild {
        cmake {
            // version '3.10.2'
            path "src/main/cpp/CMakeLists.txt"
        }
    }

    packagingOptions {
        // TODO: This only seems necessary if c++_shared is enabled in cmake
        // pickFirst '**/libc++_shared.so'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.facebook.react:react-native:+'
}
