A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
mobile: centralize prebuilt AAR config and add auto-detection script
kashaf-ansari-dev1501f3cca3b0
diff --git a/apps/mobile/android/prebuilt-aars.gradle b/apps/mobile/android/prebuilt-aars.gradleindex dc70d022b..550c72d53 100644--- a/apps/mobile/android/prebuilt-aars.gradle+++ b/apps/mobile/android/prebuilt-aars.gradle@@ -52,52 +52,8 @@ if (isSettings) {}}- def prebuiltLibraries = [- "react-native-screens": [- transitive: [- 'androidx.appcompat:appcompat:1.6.1',- 'androidx.fragment:fragment-ktx:1.6.1',- 'androidx.coordinatorlayout:coordinatorlayout:1.2.0',- 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0',- 'com.google.android.material:material:1.13.0',- 'androidx.core:core-ktx:1.8.0',- 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'- ]- ],- "react-native-gesture-handler": [- transitive: [- 'androidx.core:core-ktx:1.8.0'- ]- ],- "react-native-mmkv-storage": [- transitive: [- 'androidx.security:security-crypto:1.1.0-alpha03',- 'com.google.code.gson:gson:2.8.6'- ]- ],- "react-native-nitro-cloud-uploader": [- transitive: [- 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3',- 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3',- 'com.squareup.okhttp3:okhttp:4.12.0',- 'androidx.core:core-ktx:1.12.0'- ]- ],- "react-native-worklets": [- transitive: [- 'com.facebook.yoga:proguard-annotations:1.19.0',- 'androidx.transition:transition:1.1.0',- 'androidx.core:core:1.6.0'- ]- ],- "react-native-reanimated": [- transitive: [- 'com.facebook.yoga:proguard-annotations:1.19.0',- 'androidx.transition:transition:1.1.0',- 'androidx.core:core:1.6.0'- ]- ]- ]+ def configFile = new File(rootDir, "prebuilt-libraries.json")+ def prebuiltConfig = configFile.exists() ? new groovy.json.JsonSlurper().parse(configFile) : nullif (!prebuiltLibs.isEmpty()) {def proc = ["node", "${rootDir}/scripts/build-prebuilt-aars.js", "--aars"].execute(null, rootDir)@@ -119,7 +75,7 @@ if (isSettings) {debugImplementation files(aar.debug)releaseImplementation files(aar.release)- prebuiltLibraries[libName]?.transitive?.each { dep ->+ prebuiltConfig?.libraries?.get(libName)?.transitive?.each { dep ->implementation dep}println "[Prebuilt AAR] ${libName}: Using prebuilt AAR"diff --git a/apps/mobile/android/prebuilt-libraries.json b/apps/mobile/android/prebuilt-libraries.jsonnew file mode 100644index 000000000..bde10a157--- /dev/null+++ b/apps/mobile/android/prebuilt-libraries.json@@ -0,0 +1,108 @@+{+ "libraries": {+ "@callstack/repack": {+ "gradleProject": "callstack_repack",+ "filePrefix": "callstack-repack",+ "hasCpp": true,+ "transitive": [+ "com.squareup.okhttp3:okhttp:4.9.2",+ "com.squareup.okhttp3:okhttp-urlconnection:4.9.2",+ "com.nimbusds:nimbus-jose-jwt:9.48"+ ]+ },+ "react-native-fast-openpgp": {+ "gradleProject": "react-native-fast-openpgp",+ "filePrefix": "react-native-fast-openpgp",+ "hasCpp": true,+ "transitive": []+ },+ "react-native-gesture-handler": {+ "gradleProject": "react-native-gesture-handler",+ "filePrefix": "react-native-gesture-handler",+ "hasCpp": true,+ "transitive": [+ "androidx.appcompat:appcompat:1.7.0",+ "androidx.core:core-ktx:1.16.0",+ "androidx.core:core-ktx:1.8.0"+ ]+ },+ "react-native-mmkv-storage": {+ "gradleProject": "react-native-mmkv-storage",+ "filePrefix": "react-native-mmkv-storage",+ "hasCpp": true,+ "transitive": [+ "androidx.security:security-crypto:1.1.0-alpha03",+ "com.google.code.gson:gson:2.8.6"+ ]+ },+ "react-native-nitro-cloud-uploader": {+ "gradleProject": "react-native-nitro-cloud-uploader",+ "filePrefix": "react-native-nitro-cloud-uploader",+ "hasCpp": true,+ "transitive": [+ "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3",+ "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3",+ "com.squareup.okhttp3:okhttp:4.12.0",+ "androidx.core:core-ktx:1.12.0"+ ]+ },+ "react-native-nitro-modules": {+ "gradleProject": "react-native-nitro-modules",+ "filePrefix": "react-native-nitro-modules",+ "hasCpp": true,+ "transitive": []+ },+ "react-native-quick-sqlite": {+ "gradleProject": "react-native-quick-sqlite",+ "filePrefix": "react-native-quick-sqlite",+ "hasCpp": true,+ "transitive": [],+ "customFlagsProp": "quickSqliteFlags"+ },+ "react-native-reanimated": {+ "gradleProject": "react-native-reanimated",+ "filePrefix": "react-native-reanimated",+ "hasCpp": true,+ "transitive": [+ "com.facebook.yoga:proguard-annotations:1.19.0",+ "androidx.transition:transition:1.1.0",+ "androidx.core:core:1.6.0"+ ]+ },+ "react-native-screens": {+ "gradleProject": "react-native-screens",+ "filePrefix": "react-native-screens",+ "hasCpp": true,+ "transitive": [+ "androidx.appcompat:appcompat:1.6.1",+ "androidx.fragment:fragment-ktx:1.6.1",+ "androidx.coordinatorlayout:coordinatorlayout:1.2.0",+ "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0",+ "com.google.android.material:material:1.13.0",+ "androidx.core:core-ktx:1.8.0",+ "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"+ ]+ },+ "react-native-worklets": {+ "gradleProject": "react-native-worklets",+ "filePrefix": "react-native-worklets",+ "hasCpp": true,+ "transitive": [+ "com.facebook.yoga:proguard-annotations:1.19.0",+ "androidx.transition:transition:1.1.0",+ "androidx.core:core:1.6.0"+ ]+ }+ },+ "activeLibraries": [+ "react-native-fast-openpgp",+ "react-native-gesture-handler",+ "react-native-mmkv-storage",+ "react-native-nitro-modules",+ "react-native-nitro-cloud-uploader",+ "react-native-quick-sqlite",+ "react-native-worklets",+ "react-native-reanimated",+ "react-native-screens"+ ]+}diff --git a/apps/mobile/android/scripts/build-prebuilt-aars.js b/apps/mobile/android/scripts/build-prebuilt-aars.jsindex a0e79ae46..739804bae 100644--- a/apps/mobile/android/scripts/build-prebuilt-aars.js+++ b/apps/mobile/android/scripts/build-prebuilt-aars.js@@ -27,66 +27,22 @@ const mobileDir = path.resolve(androidDir, "..");const rootDir = path.resolve(mobileDir, "..", "..");const prebuiltDir = path.join(androidDir, ".prebuilt-aars");-// Library registry configuration-// gradleProject: Gradle project name (defaults to lib name with @ stripped and / replaced with _)-// filePrefix: Output file prefix (defaults to lib name with @ stripped and / replaced with -)-// customFlagsProp: gradle.properties property key containing extra compile flags-const ALL_LIBRARIES = {- "react-native-quick-sqlite": {- gradleProject: "react-native-quick-sqlite",- filePrefix: "react-native-quick-sqlite",- customFlagsProp: "quickSqliteFlags"- },- "react-native-fast-openpgp": {- gradleProject: "react-native-fast-openpgp",- filePrefix: "react-native-fast-openpgp"- },- "react-native-screens": {- gradleProject: "react-native-screens",- filePrefix: "react-native-screens"- },- "react-native-gesture-handler": {- gradleProject: "react-native-gesture-handler",- filePrefix: "react-native-gesture-handler"- },- "react-native-mmkv-storage": {- gradleProject: "react-native-mmkv-storage",- filePrefix: "react-native-mmkv-storage"- },- "@callstack/repack": {- gradleProject: "callstack_repack",- filePrefix: "callstack-repack"- },- "react-native-nitro-modules": {- gradleProject: "react-native-nitro-modules",- filePrefix: "react-native-nitro-modules"- },- "react-native-nitro-cloud-uploader": {- gradleProject: "react-native-nitro-cloud-uploader",- filePrefix: "react-native-nitro-cloud-uploader"- },- "react-native-worklets": {- gradleProject: "react-native-worklets",- filePrefix: "react-native-worklets"- },- "react-native-reanimated": {- gradleProject: "react-native-reanimated",- filePrefix: "react-native-reanimated"- }-};+// Load centralized prebuilt-libraries.json config (or generate if missing)+const prebuiltConfigPath = path.join(androidDir, "prebuilt-libraries.json");+let prebuiltConfig = null;+if (fs.existsSync(prebuiltConfigPath)) {+ try {+ prebuiltConfig = JSON.parse(fs.readFileSync(prebuiltConfigPath, "utf8"));+ } catch (e) {}+}-// All configured prebuilt libraries in dependency order-const ACTIVE_LIBRARIES = [- "react-native-quick-sqlite",- "react-native-fast-openpgp",- "react-native-screens",- "react-native-gesture-handler",- "react-native-mmkv-storage",- "react-native-nitro-modules",- "react-native-nitro-cloud-uploader",- "react-native-worklets",- "react-native-reanimated"-];+if (!prebuiltConfig) {+ const { generateConfig } = require("./generate-prebuilt-config");+ prebuiltConfig = generateConfig();+}++const ALL_LIBRARIES = prebuiltConfig.libraries || {};+const ACTIVE_LIBRARIES = prebuiltConfig.activeLibraries || Object.keys(ALL_LIBRARIES);function computeHash(libName) {const libConfig = ALL_LIBRARIES[libName] || {@@ -311,6 +267,14 @@ if (require.main === module) {for (const lib of libsToBuild) {buildPrebuiltAar(lib, targetVariant);}++ // Run ./gradlew clean as the final step+ console.log("\n[CLEAN] Running ./gradlew clean as final step...");+ execSync("./gradlew clean", {+ cwd: androidDir,+ stdio: "inherit"+ });+ console.log("[DONE] All prebuilt AARs compiled and workspace cleaned.");}module.exports = {diff --git a/apps/mobile/android/scripts/generate-prebuilt-config.js b/apps/mobile/android/scripts/generate-prebuilt-config.jsnew file mode 100644index 000000000..2a31286f0--- /dev/null+++ b/apps/mobile/android/scripts/generate-prebuilt-config.js@@ -0,0 +1,176 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++const fs = require("fs");+const path = require("path");++const scriptsDir = __dirname;+const androidDir = path.resolve(scriptsDir, "..");+const mobileDir = path.resolve(androidDir, "..");+const outputFile = path.join(androidDir, "prebuilt-libraries.json");++// Known custom properties or manual flags+const KNOWN_OVERRIDES = {+ "react-native-quick-sqlite": {+ customFlagsProp: "quickSqliteFlags"+ },+ "react-native-screens": {+ transitive: ["androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"]+ },+ "react-native-gesture-handler": {+ transitive: ["androidx.core:core-ktx:1.8.0"]+ }+};++// Dependency ordering: key must be built after dependency+const DEPENDENCIES = {+ "react-native-nitro-cloud-uploader": ["react-native-nitro-modules"],+ "react-native-reanimated": ["react-native-worklets"]+};++// Libraries excluded from active AAR prebuilding (e.g. built differently or experimental)+const EXCLUDE_FROM_ACTIVE = new Set(["@callstack/repack"]);++function extractTransitiveDeps(gradleFilePath) {+ if (!fs.existsSync(gradleFilePath)) return [];+ const content = fs.readFileSync(gradleFilePath, "utf8");+ const deps = [];+ const regex = /(?:implementation|api|compile)\s+['"]([^:'"]+:[^:'"]+:[^'"]+)['"]/g;+ let match;+ while ((match = regex.exec(content)) !== null) {+ const dep = match[1].trim();+ // Exclude react-native / fbjni / dynamic variables like $kotlin_version+ if (+ !dep.startsWith("com.facebook.react:") &&+ !dep.startsWith("com.facebook.fbjni:") &&+ !dep.includes("$") &&+ !dep.includes("@aar")+ ) {+ deps.push(dep);+ }+ }+ return [...new Set(deps)];+}++function hasCppNativeBuild(depAndroidDir) {+ const cmakePath = path.join(depAndroidDir, "CMakeLists.txt");+ if (fs.existsSync(cmakePath)) return true;++ const gradleFile = path.join(depAndroidDir, "build.gradle");+ if (fs.existsSync(gradleFile)) {+ const content = fs.readFileSync(gradleFile, "utf8");+ if (content.includes("externalNativeBuild") || content.includes("cmake {")) {+ return true;+ }+ }+ return false;+}++function generateConfig() {+ const pkgJsonPath = path.join(mobileDir, "package.json");+ const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));+ const allDeps = {+ ...pkgJson.dependencies,+ ...pkgJson.devDependencies+ };++ // Preserve existing user customizations if present+ let existingConfig = {};+ if (fs.existsSync(outputFile)) {+ try {+ existingConfig = JSON.parse(fs.readFileSync(outputFile, "utf8"));+ } catch (e) {}+ }++ const libraries = {};++ for (const depName of Object.keys(allDeps)) {+ const depDir = path.join(mobileDir, "node_modules", depName);+ const depAndroidDir = path.join(depDir, "android");+ if (!fs.existsSync(depAndroidDir)) continue;++ // Only target libraries with actual C++ native build+ if (!hasCppNativeBuild(depAndroidDir)) continue;++ const gradleProject = depName.replace(/^@/, "").replace(/\//g, "_");+ const filePrefix = depName.replace(/^@/, "").replace(/\//g, "-");+ const gradleFile = path.join(depAndroidDir, "build.gradle");+ const extractedTransitive = extractTransitiveDeps(gradleFile);++ // Merge with known manual overrides and existing config+ const overrides = KNOWN_OVERRIDES[depName] || {};+ const existing = (existingConfig.libraries && existingConfig.libraries[depName]) || {};++ const transitive = Array.from(+ new Set([+ ...extractedTransitive,+ ...(overrides.transitive || []),+ ...(existing.transitive || [])+ ])+ );++ const libEntry = {+ gradleProject: existing.gradleProject || overrides.gradleProject || gradleProject,+ filePrefix: existing.filePrefix || overrides.filePrefix || filePrefix,+ hasCpp: true,+ transitive+ };++ if (overrides.customFlagsProp || existing.customFlagsProp) {+ libEntry.customFlagsProp = overrides.customFlagsProp || existing.customFlagsProp;+ }++ libraries[depName] = libEntry;+ }++ // Active libraries: all detected C++ libraries except EXCLUDE_FROM_ACTIVE+ let activeLibraries = existingConfig.activeLibraries;+ if (!Array.isArray(activeLibraries) || activeLibraries.length === 0) {+ activeLibraries = Object.keys(libraries).filter((name) => !EXCLUDE_FROM_ACTIVE.has(name));+ } else {+ // Filter to only libraries that actually exist in the detected set+ activeLibraries = activeLibraries.filter((name) => libraries[name]);+ }++ // Topological sorting for dependencies (e.g., nitro-modules before nitro-cloud-uploader)+ activeLibraries.sort((a, b) => {+ if (DEPENDENCIES[b]?.includes(a)) return -1;+ if (DEPENDENCIES[a]?.includes(b)) return 1;+ return 0;+ });++ const finalConfig = {+ libraries,+ activeLibraries+ };++ fs.writeFileSync(outputFile, JSON.stringify(finalConfig, null, 2) + "\n");+ console.log(`[CONFIG] Generated ${outputFile}`);+ console.log(`[CONFIG] Detected C++ libraries: ${Object.keys(libraries).length}`);+ console.log(`[CONFIG] Active prebuilt libraries: ${activeLibraries.length} (${activeLibraries.join(", ")})`);+ return finalConfig;+}++if (require.main === module) {+ generateConfig();+}++module.exports = {+ generateConfig+};