Closed Abhishek2250 closed 1 year ago
same here
[CXX1405] error when building with ndkBuild using /Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/src/main/jni/Android.mk: Build command failed.
Are you using the New Architecture? If yes, that's a relevant detail that you haven't mentioned in the issue report.
I would first check if you're able to upgrade to 0.68.1 without enabling the New Architecture at all.
@cortinico I'm able to build having react-native version 0.68.1 without enabling the new arch. When I enable the new arch on android then I get the error in Android Studio mentioned in the issue.
Are you either:
-PreactNativeArchitectures=
filter --active-arch-only
flagIf yes, that's reason your build is failing. This is explained here: https://reactnative.dev/docs/build-speed#clean-android-build-with---active-arch-only-is-failing
You'll have to do a full build with npx react-native run-android
first. This is fixed in RN 0.69.x and won't be a requirement in the future anymore.
@cortinico I've tried building from CLI using command npx react-native run-android
and getting same error...
`FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:buildNdkBuildDebug[XX_appmodules]'.
Build command failed. Error while executing process /Users/abhishek/Library/Android/sdk/ndk/21.4.7075529/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/abhishek/XX/source/XX-mob/XX/android/app/src/main/jni/Android.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 NDK_OUT=/Users/abhishek/XX/source/XX-mob/XX/android/app/build/intermediates/cxx/Debug/3t3w192i/obj NDK_LIBS_OUT=/Users/abhishek/XX/source/XX-mob/XX/android/app/build/intermediates/cxx/Debug/3t3w192i/lib APP_CFLAGS+=-Wall APP_CFLAGS+=-Werror APP_CFLAGS+=-fexceptions APP_CFLAGS+=-frtti APP_CFLAGS+=-DWITH_INSPECTOR=1 APP_CPPFLAGS+=-std=c++17 APP_PLATFORM=android-21 APP_STL=c++_shared NDK_TOOLCHAIN_VERSION=clang GENERATED_SRC_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/app/build/generated/source PROJECT_BUILD_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/app/build REACT_ANDROID_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/../node_modules/react-native/ReactAndroid REACT_ANDROID_BUILD_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/../node_modules/react-native/ReactAndroid/build XX_appmodules} [armeabi-v7a] Compile++ thumb: XX_appmodules <= OnLoad.cpp [armeabi-v7a] Compile++ thumb: XX_appmodules <= MainComponentsRegistry.cpp [armeabi-v7a] Compile++ thumb: XX_appmodules <= MainApplicationTurboModuleManagerDelegate.cpp [armeabi-v7a] Compile++ thumb: XX_appmodules <= MainApplicationModuleProvider.cpp
/Users/abhishek/XX/source/XX-mob/XX/android/app/src/main/jni/MainApplicationModuleProvider.cpp:1:9: error: #pragma once in main file [-Werror,-Wpragma-once-outside-header]
^
1 error generated. make: *** [/Users/abhishek/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:478: /Users/abhishek/XX/source/XX-mob/XX/android/app/build/intermediates/cxx/Debug/3t3w192i/obj/local/armeabi-v7a/objs-debug/XX_appmodules//Users/abhishek/XX/source/XX-mob/XX/android/app/src/main/jni/MainApplicationModuleProvider.o] Error 1`
Where XX
is project name.
/Users/abhishek/XX/source/XX-mob/XX/android/app/src/main/jni/MainApplicationModuleProvider.cpp:1:9: error: #pragma once in main file [-Werror,-Wpragma-once-outside-header]
pragma once
^
Your build is failing most likely due to a copy-paste error.
You should not have #pragma
inside the MainApplicationModuleProvider.cpp
.
That's most likely some iOS code that you accidentally copied there.
Could you please post the content of the android/app/src/main/jni/MainApplicationModuleProvider.cpp
file?
It should look like this one: https://github.com/facebook/react-native/blob/main/template/android/app/src/main/jni/MainApplicationModuleProvider.cpp
@cortinico thanks for the pointing the issue. It solved the error but getting new error now. `2 files found with path 'lib/armeabi-v7a/libc++_shared.so' from inputs:
- /Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native-safe-area-context/android/build/intermediates/library_jni/debug/jni/armeabi-v7a/libc++_shared.so
- /Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native-screens/android/build/intermediates/library_jni/debug/jni/armeabi-v7a/libc++_shared.so
This happens because you're importing both react-native-safe-area-context
and react-native-screens
which both bundles libc++_shared.so
.
You can solve this by adding the following to your android/app/build.gradle
:
android {
+ packagingOptions {
+ pickFirst '**/libc++_shared.so'
+ }
}
Just note that this could lead to runtime crash as you're letting Gradle decide which libc++_shared.so
to include in the final bundle.
If you configured the New Architecture correctly, you should not be seeing this error at all (as your app will already provide a libc++_shared.so
which will take precedence against the other 2 provided from the libraries).
Thanks for the response. I double checked the react-native upgrade changes and made some changes. Getting new error now:
C/C++: fcntl(): Bad file descriptor
C/C++: /Users/abhishek/Library/Android/sdk/ndk/21.4.7075529/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting . Stop.
[CXX1405] error when building with ndkBuild using /Users/abhishek/XX/source/XX-mob/XX/android/app/src/main/jni/Android.mk: Build command failed.
Error while executing process /Users/abhishek/Library/Android/sdk/ndk/21.4.7075529/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/abhishek/XX/source/XX-mob/XX/android/app/src/main/jni/Android.mk APP_ABI=x86 NDK_ALL_ABIS=x86 NDK_DEBUG=1 NDK_OUT=/Users/abhishek/XX/source/XX-mob/XX/android/app/build/intermediates/cxx/Debug/3t3w192i/obj NDK_LIBS_OUT=/Users/abhishek/XX/source/XX-mob/XX/android/app/build/intermediates/cxx/Debug/3t3w192i/lib APP_CFLAGS+=-Wall APP_CFLAGS+=-Werror APP_CFLAGS+=-fexceptions APP_CFLAGS+=-frtti APP_CFLAGS+=-DWITH_INSPECTOR=1 APP_CPPFLAGS+=-std=c++17 APP_PLATFORM=android-21 APP_STL=c++_shared NDK_TOOLCHAIN_VERSION=clang GENERATED_SRC_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/app/build/generated/source PROJECT_BUILD_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/app/build REACT_ANDROID_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/../node_modules/react-native/ReactAndroid REACT_ANDROID_BUILD_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/../node_modules/react-native/ReactAndroid/build APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: ERROR:/Users/abhishek/XX/source/XX-mob/XX/android/app/src/main/jni/Android.mk:fb: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that /Users/abhishek/XX/source/XX-mob/XX/android/app/build/react-ndk/exported/x86/libfb.so exists or that its path is correct
fcntl(): Bad file descriptor /Users/abhishek/Library/Android/sdk/ndk/21.4.7075529/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting . Stop.
C/C++: /Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/../ReactCommon/butter/Android.mk:28: *** Android NDK: Aborting. . Stop.
[CXX1405] error when building with ndkBuild using /Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/src/main/jni/react/jni/Android.mk: Build command failed.
Error while executing process /Users/abhishek/Library/Android/sdk/ndk/21.4.7075529/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/src/main/jni/react/jni/Android.mk APP_ABI=x86 NDK_ALL_ABIS=x86 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/build/intermediates/cxx/Debug/6e2ds6c4/obj NDK_LIBS_OUT=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/build/intermediates/cxx/Debug/6e2ds6c4/lib NDK_APPLICATION_MK=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/src/main/jni/Application.mk THIRD_PARTY_NDK_DIR=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/build/third-party-ndk REACT_COMMON_DIR=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/../ReactCommon REACT_GENERATED_SRC_DIR=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/build/generated/source REACT_SRC_DIR=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react -j8 --output-sync=none APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
Android NDK: WARNING: Ignoring unknown import directory: /Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/build/generated/source
Android NDK: /Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/../ReactCommon/butter/Android.mk: Cannot find module with tag 'glog' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/../ReactCommon/butter/Android.mk:28: *** Android NDK: Aborting. . Stop.
This error was coming before when I clean the project.
I found the same issue on github and tried his soln but didnt work https://github.com/software-mansion/react-native-screens/issues/1389
Thanks again for your time
When I clean the project then I get this error:
Build command failed.
Error while executing process /Users/abhishek/Library/Android/sdk/ndk/21.4.7075529/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native-gesture-handler/android/src/main/jni/Android.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 NDK_OUT=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native-gesture-handler/android/build/intermediates/cxx/Release/661v54m6/obj NDK_LIBS_OUT=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native-gesture-handler/android/build/intermediates/cxx/Release/661v54m6/lib APP_CFLAGS+=-Wall APP_CFLAGS+=-Werror APP_CFLAGS+=-fexceptions APP_CFLAGS+=-frtti APP_CFLAGS+=-DWITH_INSPECTOR=1 APP_CPPFLAGS+=-std=c++17 APP_PLATFORM=android-21 APP_STL=c++_shared NDK_TOOLCHAIN_VERSION=clang GENERATED_SRC_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/app/build/generated/source PROJECT_BUILD_DIR=/Users/abhishek/XX/source/XX-mob/XX/android/app/build REACT_ANDROID_DIR=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid REACT_ANDROID_BUILD_DIR=/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native/ReactAndroid/build clean}
Android NDK: ERROR:/Users/abhishek/XX/source/XX-mob/XX/node_modules/react-native-gesture-handler/android/src/main/jni/Android.mk:fb: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that /Users/abhishek/XX/source/XX-mob/XX/android/app/build/react-ndk/exported/armeabi-v7a/libfb.so exists or that its path is correct
fcntl(): Bad file descriptor /Users/abhishek/Library/Android/sdk/ndk/21.4.7075529/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting . Stop.
I think there's something wrong with NDK configurations or versions.
Could you post the content of your android/app/build.gradle
?
apply plugin: "com.android.application"
import org.apache.tools.ant.taskdefs.condition.Os
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation. If none specified and
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
* // default. Can be overridden with ENTRY_FILE environment variable.
* entryFile: "index.android.js",
*
* // https://reactnative.dev/docs/performance#enable-the-ram-format
* bundleCommand: "ram-bundle",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
enableHermes: true, // clean and rebuild if changing
bundleInDebug: false,
bundleInRelease: true,
bundleDevDebug: false,
bundleUatDebug: true,
bundleProdDebug: true,
bundleDevRelease: false,
bundleUatRelease: true,
bundleProdRelease: true,
devDisabledInDebug: false,
devDisabledInRelease: true,
devDisabledInDevDebug: false,
devDisabledInUatDebug: false,
devDisabledInProdDebug: false,
devDisabledInDevRelease: true,
devDisabledInUatRelease: true,
devDisabledInProdRelease: true,
jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
jsBundleDirRelease: "$buildDir/intermediates/assets/release",
//jsBundleDirDevDebug: "$buildDir/intermediates/assets/devdebug",
//jsBundleDirUatDebug: "$buildDir/intermediates/assets/uatdebug",
//jsBundleDirProdDebug: "$buildDir/intermediates/assets/proddebug",
//jsBundleDirDevRelease: "$buildDir/intermediates/assets/devrelease",
//jsBundleDirUatRelease: "$buildDir/intermediates/assets/uatrelease",
//jsBundleDirProdRelease: "$buildDir/intermediates/assets/prodrelease",
resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
//resourcesDirDevDebug: "$buildDir/intermediates/assets/devdebug",
//resourcesDirUatDebug: "$buildDir/intermediates/assets/uatdebug",
//resourcesDirProdDebug: "$buildDir/intermediates/assets/proddebug",
//resourcesDirDevRelease: "$buildDir/intermediates/assets/devrelease",
//resourcesDirUatRelease: "$buildDir/intermediates/assets/uatrelease",
//resourcesDirProdRelease: "$buildDir/intermediates/assets/prodrelease",
inputExcludes: ["android/**", "ios/**", "__tests__/**", "js_build/**"],
nodeExecutableAndArgs: ["node", "--max-old-space-size=8192"]
]
apply from: "../../node_modules/react-native/react.gradle"
/**
* Set this to true to create two separate APKs instead of one:
* - An APK that only works on ARM devices
* - An APK that only works on x86 devices
* The advantage is the size of the APK is reduced by about 4MB.
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and that value will be read here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);
/**
* Architectures to build native code for.
*/
def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}
android {
buildFeatures {
buildConfig = true
}
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
// cm added this
//sourceCompatibility "1.8"
//targetCompatibility "1.8"
flavorDimensions "default" // <-- !!! add this line for multiple variants!!!
defaultConfig {
applicationId "com.XX"
resValue "string", "build_config_package", "app.XX"
resValue "string", "deeplink_url", "dev.link.XX.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
// versionCode 1 <- added to AndroidManifest.xml for CI
// versionName "1.0" 1 <- added to AndroidManifest.xml for CI
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
if (isNewArchitectureEnabled()) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
ndkBuild {
arguments "APP_PLATFORM=android-21",
"APP_STL=c++_shared",
"NDK_TOOLCHAIN_VERSION=clang",
"GENERATED_SRC_DIR=$buildDir/generated/source",
"PROJECT_BUILD_DIR=$buildDir",
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
cppFlags "-std=c++17"
// Make sure this target name is the same you specify inside the
// src/main/jni/Android.mk file for the `LOCAL_MODULE` variable.
targets "XX_appmodules"
// Fix for windows limit on number of character in file paths and in command lines
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx",
"NDK_APP_SHORT_COMMANDS=true"
}
}
}
if (!enableSeparateBuildPerCPUArchitecture) {
ndk {
abiFilters (*reactNativeArchitectures())
}
}
}
multiDexEnabled true
missingDimensionStrategy 'react-native-camera', 'general' // for react-native-camera
vectorDrawables.useSupportLibrary = true // for react-native-image-crop-picker
}
if (isNewArchitectureEnabled()) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
ndkBuild {
path "$projectDir/src/main/jni/Android.mk"
}
}
def reactAndroidProjectDir = project(':ReactAndroid').projectDir
def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) {
dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck")
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
into("$buildDir/react-ndk/exported")
}
def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) {
dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck")
from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
into("$buildDir/react-ndk/exported")
}
afterEvaluate {
// If you wish to add a custom TurboModule or component locally,
// you should uncomment this line.
// preBuild.dependsOn("generateCodegenArtifactsFromSchema")
preDevDebugBuild.dependsOn(packageReactNdkDebugLibs)
preDevReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
// Due to a bug inside AGP, we have to explicitly set a dependency
// between configureNdkBuild* tasks and the preBuild tasks.
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
configureNdkBuildRelease.dependsOn(preDevReleaseBuild)
configureNdkBuildDebug.dependsOn(preDevDebugBuild)
reactNativeArchitectures().each { architecture ->
tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure {
dependsOn("preDevDebugBuild")
}
tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure {
dependsOn("preDevReleaseBuild")
}
}
}
}
signingConfigs {
release {
//release configs here
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include (*reactNativeArchitectures())
}
}
// https://developer.android.com/studio/build/build-variants
// https://medium.com/@tgpski/android-react-native-fastlane-working-with-multiple-build-types-a9a6641c5704
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
debuggable false
}
}
productFlavors {
dev {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'com.XX'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "app.xx"
resValue "string", "deeplink_url", "dev.link.xx.app"
//applicationIdSuffix ".dev"
//buildConfigField "String", "BUILD_VARIANT", "\"dev\""
}
uat {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'app.xx.uat'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "app.xx"
resValue "string", "deeplink_url", "pilot.link.xx.app"
//applicationIdSuffix ".uat"
//buildConfigField "String", "BUILD_VARIANT", "\"uat\""
}
prod {
minSdkVersion rootProject.ext.minSdkVersion
applicationId 'app.xx'
targetSdkVersion rootProject.ext.targetSdkVersion
resValue "string", "build_config_package", "app.xx"
resValue "string", "deeplink_url", "link.xx.app"
//buildConfigField "String", "BUILD_VARIANT", "\"prod\""
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
def abi = output.getFilter(com.android.build.OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
}
}
}
dexOptions {
preDexLibraries false
javaMaxHeapSize "8g" // this to speed up the builds
}
}
dependencies {
implementation project(':react-native-contacts')
implementation project(':react-native-orientation')
implementation project(':react-native-splash-screen')
implementation 'com.facebook.fresco:fresco:2.0.0' // fresco to use gifs in react native (custom implementation)
implementation 'com.facebook.fresco:animated-gif:2.6.0' // fresco to use gifs in react native (custom implementation)
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.1.0' //for gif support in native android
//implementation project(':react-native-geolocation-service')
implementation(project(':react-native-geolocation-service')) {
exclude group: 'com.google.android.gms', module: 'play-services-location'
}
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.0.0" // react-native-video 5 and up
//implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" // react-native-video 4 and below
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
// implementation 'com.google.firebase:firebase-crashlytics:18.0.1'
// implementation group: 'com.google.firebase', name: 'firebase-crashlytics-gradle', version: '2.7.0'
// implementation 'com.google.firebase:firebase-analytics:19.0.0'
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
exclude group:'com.squareup.okhttp3', module:'okhttp'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
// <-- Add this line if you wish to use badge on Android
implementation 'com.google.android.gms:play-services-base:16.0.1'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
}
if (isNewArchitectureEnabled()) {
// If new architecture is enabled, we let you build RN from source
// Otherwise we fallback to a prebuilt .aar bundled in the NPM package.
// This will be applied to all the imported transtitive dependency.
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("com.facebook.react:react-native"))
.using(project(":ReactAndroid")).because("On New Architecture we're building React Native from source")
}
}
}
// 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.implementation
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
def isNewArchitectureEnabled() {
// To opt-in for the New Architecture, you can either:
// - Set `newArchEnabled` to true inside the `gradle.properties` file
// - Invoke gradle with `-newArchEnabled=true`
// - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}
// https://stackoverflow.com/questions/52330253/incompatible-firebase-libraries/52496742#52496742
// com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true // this disables some warning about firebase incompatible versions etc
I'm upgrading react-native from 0.67.2 to 0.68.2 doing diligently steps from the guide https://reactnative.dev/docs/new-architecture-app-intro But now I got stuck with the similar issue as @Abhishek2250 has. My stacktrace:
Task :app:processDebugGoogleServices Execution optimizations have been disabled for task ':app:processDebugGoogleServices' to ensure correctness due to the following reasons:
- Gradle detected a problem with the following location: '/Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/app/build/generated/res/google-services/debug'. Reason: Task ':app:generateCodegenSchemaFromJavaScript' uses this output of task ':app:processDebugGoogleServices' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.3/userguide/validation_problems.html#implicit_dependency for more details about this problem.
Task :app:configureNdkBuildDebug FAILED C/C++: fcntl(): Bad file descriptor C/C++: /Users/mikhail_dziarbeyeu/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:651: Android NDK: Module myapplication_appmodules depends on undefined modules: react_codegen_samplelibrary
C/C++: /Users/mikhail_dziarbeyeu/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:664: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies. . Stop.
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.3/userguide/command_line_interface.html#sec:command_line_warnings
Execution optimizations have been disabled for 2 invalid unit(s) of work during this build to ensure correctness. Please consult deprecation warnings for more details. 916 actionable tasks: 10 executed, 906 up-to-date
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':app:configureNdkBuildDebug'.
[CXX1405] error when building with ndkBuild using /Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/app/src/main/jni/Android.mk: Build command failed. Error while executing process /Users/mikhail_dziarbeyeu/Library/Android/sdk/ndk/21.4.7075529/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/app/src/main/jni/Android.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 NDK_OUT=/Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/app/build/intermediates/cxx/Debug/731j4282/obj NDK_LIBS_OUT=/Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/app/build/intermediates/cxx/Debug/731j4282/lib APP_CFLAGS+=-Wall APP_CFLAGS+=-Werror APP_CFLAGS+=-fexceptions APP_CFLAGS+=-frtti APP_CFLAGS+=-DWITH_INSPECTOR=1 APP_CPPFLAGS+=-std=c++17 APP_PLATFORM=android-21 APP_STL=c++_shared NDK_TOOLCHAIN_VERSION=clang GENERATED_SRC_DIR=/Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/app/build/generated/source PROJECT_BUILD_DIR=/Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/app/build REACT_ANDROID_DIR=/Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/../node_modules/react-native/ReactAndroid REACT_ANDROID_BUILD_DIR=/Users/mikhail_dziarbeyeu/Desktop/h3-fe-consumer/android/../node_modules/react-native/ReactAndroid/build APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}
fcntl(): Bad file descriptor
/Users/mikhail_dziarbeyeu/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:651: Android NDK: Module myapplication_appmodules depends on undefined modules: react_codegen_samplelibrary
/Users/mikhail_dziarbeyeu/Library/Android/sdk/ndk/21.4.7075529/build/core/build-binary.mk:664: *** Android NDK: Note that old versions of ndk-build silently ignored this error case. If your project worked on those versions, the missing libraries were not needed and you can remove those dependencies from the module to fix your build. Alternatively, set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies. . Stop.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 51s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup. Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
What's the version of your com.android.tools.build:gradle
used in android/build.gradle
?
I tried to use a higher version than in the template and I've had these Android NDK issues.
Sticking to classpath("com.android.tools.build:gradle:7.0.4")
helped.
See https://react-native-community.github.io/upgrade-helper/?from=0.66.4&to=0.68.2
I'm able to build the app successfully but app is crashing now when it launches. Below is the crash logs from Android Studio
`D/SoLoader: libjscexecutor.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: libjscexecutor.so not found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: libjscexecutor.so not found on /system/lib64 D/SoLoader: libjscexecutor.so not found on /vendor/lib64 E/SoLoader: couldn't find DSO to load: libjscexecutor.so SoSource 0: com.facebook.soloader.ApkSoSource[root = /data/data/com.PROJETC_NAME/lib-main flags = 1] SoSource 1: com.facebook.soloader.DirectorySoSource[root = /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 flags = 0] SoSource 2: com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2] SoSource 3: com.facebook.soloader.DirectorySoSource[root = /vendor/lib64 flags = 2] Native lib dir: /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 result: 0 D/SoLoader: libhermes.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: libhermes.so found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: Not resolving dependencies for libhermes.so D/SoLoader: libhermes-executor-debug.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: libhermes-executor-debug.so found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: Not resolving dependencies for libhermes-executor-debug.so I/FA: Tag Manager is not found and thus will not be used D/SoLoader: libfbjni.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: libfbjni.so found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: Not resolving dependencies for libfbjni.so D/SoLoader: libflipper.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: libflipper.so found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: Not resolving dependencies for libflipper.so
E/unknown:ReactRootView: Unable to update root layout specs for ReactRootView: no rootViewTag set yet V/AsyncStorageExpoMigration: No scoped database found D/a: logging level: 0 D/InstallReferrerState: OK I/RNFusedLocation: RNFusedLocation initialized D/SoLoader: librngesturehandler_modules.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: librngesturehandler_modules.so found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: Not resolving dependencies for librngesturehandler_modules.so D/SoLoader: librnscreens_modules.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: librnscreens_modules.so found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: Not resolving dependencies for librnscreens_modules.so D/SoLoader: libreactnativejni.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: libreactnativejni.so found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: Not resolving dependencies for libreactnativejni.so E/GraphResponse: {HttpStatus: 400, errorCode: 100, subErrorCode: 33, errorType: GraphMethodException, errorMessage: Unsupported get request. Object with ID '354159935197864' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api} D/RNPushNotification: Refreshed token: d8BrOtqmQxq397CMWsUDiO:APA91bHbIOG4f1hWNk9lGM13XHS8Pecx9Izof163RdTz-_h8cj7E7-PXUklOskQKKAyRT1t_jUBPAUmz3p5cpawjcqy3xD85PUUpRBv7C6fAbpqvZ3bpZZr78NJlyUYWLgA2xtN5LINZ W/unknown:ReactContext: initializeMessageQueueThreads() is called. D/SoLoader: libPROJETC_NAME_appmodules.so not found on /data/data/com.PROJETC_NAME/lib-main D/SoLoader: libPROJETC_NAME_appmodules.so found on /data/app/~~pHAIaIkKMNWh2WCRF-kScA==/com.PROJETC_NAME-n5H0lY28Ptiac7186_wRUA==/lib/arm64 D/SoLoader: Not resolving dependencies for libPROJETC_NAME_appmodules.so A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 29867 (create_react_co), pid 29473 (com.PROJETC_NAME)`
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 29867 (create_react_co), pid 29473 (com.PROJETC_NAME)`
It seems it's failing with a segmentation fault. The reasons could be multiple. Could you provide a reproducer of any form?
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.
New Version
0.68.1
Old Version
0.66.4
Build Target(s)
Android device in debug and release mode
Output of
react-native info
System: OS: macOS 12.3.1 CPU: (8) x64 Apple M1 Pro Memory: 143.27 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.0.0 - /usr/local/bin/node Yarn: Not Found npm: 7.10.0 - /usr/local/bin/npm Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /Users/abhishek/.rbenv/shims/pod SDKs: iOS SDK: Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3 Android SDK: Android NDK: 22.1.7171670 IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8309675 Xcode: 13.2/13C90 - /usr/bin/xcodebuild Languages: Java: 11.0.13 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: ^17.0.2 => 17.0.2 react-native: ^0.68.1 => 0.68.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Issue and Reproduction Steps
[CXX1405] error when building with ndkBuild using /Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/src/main/jni/Android.mk: Build command failed. Error while executing process /Users/abhishek/Library/Android/sdk/ndk/24.0.8215888/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/src/main/jni/Android.mk APP_ABI=x86 NDK_ALL_ABIS=x86 NDK_DEBUG=1 NDK_OUT=/Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/build/intermediates/cxx/Debug/3t3w192i/obj NDK_LIBS_OUT=/Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/build/intermediates/cxx/Debug/3t3w192i/lib APP_CFLAGS+=-Wall APP_CFLAGS+=-Werror APP_CFLAGS+=-fexceptions APP_CFLAGS+=-frtti APP_CFLAGS+=-DWITH_INSPECTOR=1 APP_CPPFLAGS+=-std=c++17 APP_PLATFORM=android-21 APP_STL=c++_shared NDK_TOOLCHAIN_VERSION=clang GENERATED_SRC_DIR=/Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/build/generated/source PROJECT_BUILD_DIR=/Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/build REACT_ANDROID_DIR=/Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/../node_modules/react-native/ReactAndroid REACT_ANDROID_BUILD_DIR=/Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/../node_modules/react-native/ReactAndroid/build APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n} Android NDK: ERROR:/Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/src/main/jni/Android.mk:fb: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that /Users/abhishek/PROJECT_NAME/source/PROJECT_NAME-mob/PROJECT_NAME/android/app/build/react-ndk/exported/x86/libfb.so exists or that its path is correct
fcntl(): Bad file descriptor /Users/abhishek/Library/Android/sdk/ndk/24.0.8215888/build/core/prebuilt-library.mk:51: *** Android NDK: Aborting . Stop.