A New Collection of Thoughtful Learning Apps — Now Available on iOS & Android

Image
I’m excited to share a set of mobile apps I’ve recently completed and published on both the Google Play Store and the Apple App Store. These apps are designed with a simple goal in mind: to make meaningful, structured content more accessible, whether you’re studying theology or improving your English vocabulary. 📱 Now Available on Both Platforms All apps are live and available for download: Google Play Developer Page: https://play.google.com/store/apps/dev?id=5835943159853189043 Apple App Store Developer Page: https://apps.apple.com/ca/developer/q-z-l-corp/id1888794100 📖 Theology & Confession Study Apps For those interested in Reformed theology and classical Christian teachings, I’ve developed a series of apps that present foundational texts in a clean, focused reading format: The Belgic Confession Canons of Dort Heidelberg Catechism Westminster Shorter Catechism Each app is designed to provide a distraction-free experience, making it easier to read, reflect, and revisit these im...

React Native 使用 TypeScript + Hermes 时 Android Release 构建报错解决方案

React Native 使用 TypeScript + Hermes 时 Android Release 构建报错解决方案



如果你把 React Native 项目的入口文件从 index.js 改成了 index.ts,然后在构建 Android Release 版本时失败,这篇文章可以帮你解决。

常见的报错包括:

Task ':app:createBundleReleaseJsAndAssets' property 'entryFile' specifies file 'index.js' which doesn't exist.

或者:

java.lang.OutOfMemoryError: Metaspace
Execution failed for task ':react-native-xxx:lintVitalAnalyzeRelease'

这通常是由于入口文件未正确配置,以及 Gradle 内存不足导致的。下面是完整修复步骤。


1. 修复入口文件路径错误

React Native 默认查找 index.js,如果你使用 TypeScript,需要告诉 Gradle 使用 index.ts

打开 android/app/build.gradle,在 react {} 配置中加入:

react {
    entryFile = file("../../index.ts")
}

同时确认 package.json 中的入口文件:

"main": "index.ts"

并在 metro.config.js 中支持 TypeScript:

resolver: {
  sourceExts: ["js", "json", "ts", "tsx"]
}

2. 解决 Gradle Metaspace 内存不足

Android 在 Release 构建时会运行 Lint 分析 React Native 库的 Kotlin 文件,默认内存太小会导致崩溃。

编辑 android/gradle.properties,增加 JVM 内存:

org.gradle.jvmargs=-Xmx6g -XX:MaxMetaspaceSize=2g -Dfile.encoding=UTF-8

如果电脑内存不够,可以使用:

org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1g -Dfile.encoding=UTF-8

3. 禁用 Release 版本的 Lint 检查(推荐)

这些错误来自第三方库而不是你的代码,可以安全关闭。

android/app/build.gradle 中加入:

android {
    lint {
        checkReleaseBuilds false
        abortOnError false
    }
}

4. 清理并重新构建

cd android
./gradlew clean
cd ..
npx react-native run-android --variant=release

完成 🎉

现在你的 React Native + TypeScript + Hermes 项目应该可以成功生成 Android Release APK / AAB 了。

这个方法适用于 React Native 0.72+ 及新版 Gradle 构建环境。

祝开发顺利!

❤️ Support This Blog


If this post helped you, you can support my writing with a small donation. Thank you for reading.


Comments

Popular Posts

Fix “A problem occurred starting process 'command node'” in Android Studio for React Native

Fix up watchman issue with Ghost

Using Mutual TLS (mTLS) in Next.js (Server-Side Only)