Closed sanjeevyadavIT closed 1 year ago
Can you please provide the content of those files:
android/gradle/wrapper/gradle-wrapper.properties
android/app/build.gradle
android/build.gradle
?@cortinico
Context, we have a hybrid React native setup, where react-native
is inside android
project not the other way around, and also we have multi-module Android project, and react native integration code is inside one of the module
Android structure
/android
|--------> app. // main app
|-----------> build.gradle.kts
|--------->react. // All react native integration like ReactNativeHost, Packages etc etc lies here
|-------------> build.gradle.kts
|---------> reactNative // actual js code
|------------> node_modules/
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
// Top-level build file where you can add configuration options common to all sub-projects/modules.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.apache.tools.ant.taskdefs.condition.Os
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties
buildscript {
repositories {
mavenCentral()
google()
gradlePluginPortal()
maven { url = uri("https://jitpack.io") }
}
dependencies {
// ......
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
}
}
plugins {
id("org.gradle.android.cache-fix").version("2.5.5").apply(false)
id("org.sonarqube").version("2.7")
id("com.diffplug.spotless").version("6.6.0")
id("com.github.triplet.play").version("3.7.0").apply(false)
id("io.gitlab.arturbosch.detekt").version(libs.versions.detekt.get())
}
addProjectExtra()
apply(from = "$rootDir/scripts/force-enable-aar.gradle")
apply(from = "$rootDir/scripts/local-aar-config.gradle")
apply(from = "$rootDir/scripts/local-aar.gradle")
apply(from = "${project.rootDir}/scripts/sonarqube-main.gradle")
apply(plugin = "io.gitlab.arturbosch.detekt")
subprojects {
plugins.withType<com.android.build.gradle.api.AndroidBasePlugin> {
apply(plugin = "org.gradle.android.cache-fix")
project.apply(from = "$rootDir/scripts/spotless.gradle")
}
}
val localProperties = gradleLocalProperties(rootDir)
val guser = (extra["guser"] as? String) ?: ""
val gtoken = (extra["gtoken"] as? String) ?: ""
val PLOTLINE_USER: String by project
val projectSource = file(projectDir)
val configFile = files("$rootDir/config/detekt/detekt-config.yml")
val baselineFile = file("$rootDir/config/detekt/detekt-baseline.xml")
val statisticsConfigFile = file("$rootDir/config/detekt/statistics.yml")
val kotlinFiles = "**/*.kt"
val resourceFiles = "**/resources/**"
val buildFiles = "**/build/**"
allprojects {
repositories {
exclusiveContent {
forRepository {
maven {
// All of React Native (JS, Android binaries) is installed from npm
url = uri("$rootDir/reactNative/node_modules/react-native/android")
}
}
filter {
includeGroup("com.facebook.react")
}
}
maven {
url = uri("$rootDir/reactNative/node_modules/jsc-android/dist")
content {
includeGroup("org.webkit")
}
}
google()
mavenCentral()
maven {
url = uri("https://jitpack.io")
credentials {
username = System.getenv("PLOTLINE_USERNAME") ?: "$PLOTLINE_USER"
}
}
mavenLocal()
}
tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf(
"-Xjvm-default=enable",
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=kotlin.time.ExperimentalTime",
"-Xinline-classes"
)
jvmTarget = "1.8"
}
}
}
extra.apply {
set("supportVersion", "28.0.0")
set("kotlinVersion", "1.6.21")
set("compileSdkVersion", 31)
set("targetSdkVersion", 30)
set("minSdkVersion", 21)
set("buildToolsVersion", "30.0.3")
set("reactNativeVersion", "0.69.7")
set("reactNative", "0.69.7")
}
import org.gradle.kotlin.dsl.withType
//import groovy.lang.Closure
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
fun Project.setReactExtra() {
extra["react"] = mapOf<String, Any>(
Pair("entryFile", "index.android.js"),
Pair("bundleAssetName", "index.android.bundle"),
Pair("root", "${project.rootDir}/reactNative/"),
Pair("enableHermes", true),
Pair("hermesCommand", "${project.rootDir}/reactNative/node_modules/hermes-engine/%OS-BIN%/hermesc"),
Pair("bundleInDebug", false),
Pair("bundleInRelease", true),
Pair("devDisabledInRelease", true),
Pair("cliPath", "${project.rootDir}/reactNative/node_modules/react-native/cli.js"),
Pair("ndkVersion", "24.0.8215888")
)
}
setReactExtra()
val jscFlavor = "org.webkit:android-jsc:+"
val enableHermes = ((extra["react"] as Map<String, Any>)["enableHermes"] as Boolean?) ?: false
android {
packagingOptions {
jniLibs.pickFirsts.add("**/libjsc.so")
jniLibs.pickFirsts.add("**/libc++_shared.so")
}
defaultConfig {
// buildConfigField("Boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true")
// 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/reactNative/node_modules/react-native/ReactAndroid",
"REACT_ANDROID_BUILD_DIR=$rootDir/reactNative/node_modules/react-native/ReactAndroid/build",
"NODE_MODULES_DIR=$rootDir/reactNative/node_modules")
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("myproject_appmodules")
relativeProjectPath("$projectDir/src/main/jni/Android.mk")
}
cmake {
arguments("-DPROJECT_BUILD_DIR=$buildDir",
"-DREACT_ANDROID_DIR=$rootDir/reactNative/node_modules/react-native/ReactAndroid",
"-DREACT_ANDROID_BUILD_DIR=$rootDir/reactNative/node_modules/react-native/ReactAndroid/build",
"-DNODE_MODULES_DIR=$rootDir/reactNative/node_modules",
"-DANDROID_STL=c++_shared")
relativeProjectPath("$projectDir/src/main/jni/CMakeLists.txt")
}
}
}
// val reactAndroidProjectDir = project(':ReactAndroid').projectDir
// val packageReactNdkLibs = tasks.register("packageReactNdkLibs", Copy) {
// dependsOn(":ReactAndroid:packageReactNdkLibsForBuck")
// dependsOn("generateCodegenArtifactsFromSchema")
// from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
// into("$buildDir/react-ndk/exported")
// }
//
// afterEvaluate {
// preBuild.dependsOn(packageReactNdkLibs)
// configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
// configureCMakeDebug.dependsOn(preDebugBuild)
// }
//
// packagingOptions {
// pickFirst('**/libhermes.so')
// pickFirst('**/libjsc.so')
// }
kapt {
correctErrorTypes = true
}
}
dependencies {
implementation(project(":@react-native-community_async-storage")) {
exclude(group = "com.facebook.soloader", module = "soloader")
}
implementation(project(":react-native-svg")) {
exclude(group = "com.facebook.soloader", module = "soloader")
}
implementation(project(":react-native-code-push")) {
exclude(group = "com.facebook.soloader", module = "soloader")
}
implementation(project(":react-native-webview")) {
exclude(group = "com.facebook.soloader", module = "soloader")
}
implementation(project(":@react-native-picker_picker")) {
exclude(group = "com.facebook.soloader", module = "soloader")
}
implementation(project(":react-native-video")) {
exclude(group = "com.facebook.soloader", module = "soloader")
}
implementation(project(":react-native-sound")) {
exclude(group = "com.facebook.soloader", module = "soloader")
}
implementation(files("src/main/libs/soloader-0.10.4.aar"))
// https://github.com/facebook/SoLoader/issues/19
implementation(libs.react.library) {
exclude(group = "com.facebook.soloader", module = "soloader")
}
implementation(libs.soloader.nativeloader)
implementation(libs.soloader.annotation)
// lottie
implementation(libs.lottie) {
exclude(module = "appcompat-v7")
}
debugImplementation(libs.flipper.base) {
exclude(group = "com.facebook.fbjni")
exclude(group = "com.facebook.soloader", module = "soloader")
}
debugImplementation(libs.flipper.network) {
exclude(group = "com.facebook.flipper")
exclude(group = "com.squareup.okhttp3", module = "okhttp")
exclude(group = "com.facebook.soloader", module = "soloader")
}
debugImplementation(libs.flipper.fresco) {
exclude(group = "com.facebook.flipper")
exclude(group = "com.facebook.soloader", module = "soloader")
}
if (enableHermes) {
//noinspection GradleDynamicVersion
implementation("com.facebook.react:hermes-engine:+") { // From node_modules
exclude(group = "com.facebook.fbjni")
exclude(group = "com.facebook.soloader", module = "soloader")
}
} else {
implementation(jscFlavor)
}
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.4")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0")
}
// 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")
substitute(module("com.facebook.react:hermes-engine"))
.using(project(":ReactAndroid:hermes-engine"))
.because("On New Architecture we're building Hermes from source")
}
}
tasks.withType<Copy>().configureEach{
from(configurations.implementation)
into("libs")
}
fun isNewArchitectureEnabled(): Boolean {
return true
}
The problem is inside your last build.gradle
file.
If you're nto using the new Architecture, you should remove:
// 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")
substitute(module("com.facebook.react:hermes-engine"))
.using(project(":ReactAndroid:hermes-engine"))
.because("On New Architecture we're building Hermes from source")
}
}
Or follow the template and make sure is inside an if-then-else: https://github.com/facebook/react-native/blob/5e537036954f01f5177b78dd7cd6454d6a5ae56e/template/android/app/build.gradle#L289-L303
hi @cortinico I want to use new architecture, to my understanding isNewArchitectureEnabled()
function returns true, and the configurations.all
code runs, since I have written
fun isNewArchitectureEnabled(): Boolean {
return true
}
I though no need to write inside if block
hi @cortinico I want to use new architecture, to my understanding
isNewArchitectureEnabled()
function returns true, and theconfigurations.all
code runs, since I have written
Ok then you should not comment out this section:
// val reactAndroidProjectDir = project(':ReactAndroid').projectDir
// val packageReactNdkLibs = tasks.register("packageReactNdkLibs", Copy) {
// dependsOn(":ReactAndroid:packageReactNdkLibsForBuck")
// dependsOn("generateCodegenArtifactsFromSchema")
// from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib")
// into("$buildDir/react-ndk/exported")
// }
//
// afterEvaluate {
// preBuild.dependsOn(packageReactNdkLibs)
// configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
// configureCMakeDebug.dependsOn(preDebugBuild)
// }
Sorry I assumed you were on the old architecture due to those sections being commented.
Are you able to update to 0.69 successfully without turning on the New Architecture?
I am trying upgrade to 0.69 with new Architecture only, as the primary reason to upgrade was to use new architecture
Ok let me try two things
0.69
by keeping new Architecture false upgrade to 0.69 by keeping new Architecture false
This should be the first thing to achieve. As the New Architecture is still experimental as mentioned on the website.
As you're in real specific brownfield setup and I believe something from your Android application it's conflicting with out setup (not sure what, need fruther investigation) -> It might be even worth to wait for 0.71 where we encapsulated a lot of the setup.
@cortinico I have created a reproducible demo
0.69.7
by keeping newArchitecture
disabled is working fine (you can check the changes for upgrade here https://github.com/sanjeevyadavIT/android-react-native-hybrid/pull/2)newArchitecture
build is failinggit clone https://github.com/sanjeevyadavIT/android-react-native-hybrid.git
reactNative
folderyarn install
to install npm dependency gradle.properties
by setting newArchEnabled=true
You will get error
Build file '/Users/username/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/ReactAndroid/build.gradle' line: 11
Error resolving plugin [id: 'org.jetbrains.kotlin.android', version: '1.6.10']
> Plugin request for plugin already on the classpath must not include a version
/Users/username/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/ReactAndroid/build.gradle
and manually edit it
from
plugins {
...
...
id("org.jetbrains.kotlin.android") version "1.6.10"
...
...
}
to
plugins {
...
...
id("org.jetbrains.kotlin.android") apply false
...
...
}
Rebuild the project in Android Studio, You will get error
Invalid value for "PACKAGE_PATH": Directory
"/Users/username/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/ReactAndroid/hermes-engine/build/intermediates/prefab_package_configuration/debug/prefab" is not readable.
CMake Error: The source directory
"/Users/sanjeevyadav/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/sdks/hermes" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.
brew install cmake
or brew reinstall cmake
(if brew is already install)/Users/username/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java:356: error: cannot find symbol
MapBuffer localData,
^
symbol: class MapBuffer
location: class ViewManager<T,C>
where T,C are type-variables:
T extends View declared in class ViewManager
C extends ReactShadowNode declared in class ViewManager
FAILURE: Build completed with 2 failures.
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':ReactAndroid:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* 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.
==============================================================================
2: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction
> 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs:
- /Users/username/AndroidStudioProjects/HybridSetup/react/build/intermediates/library_jni/debug/jni/arm64-v8a/libc++_shared.so
- /Users/username/.gradle/caches/transforms-3/d8674da4422f7ce14c3f36129819f3d1/transformed/react-native-0.69.7-debug/jni/arm64-v8a/libc++_shared.so
If you are using jniLibs and CMake IMPORTED targets, see
https://developer.android.com/r/tools/jniLibs-vs-imported-targets
Entire build log-> build_fails_log.txt
And now I am stuck, can you please look into this
@cortinico I have created a reproducible demo
- Upgrade to
0.69.7
by keepingnewArchitecture
disabled is working fine (you can check the changes for upgrade here feat: Upgrade to React Native 0.69.7 sanjeevyadavIT/android-react-native-hybrid#2)- Enabling
newArchitecture
build is failingReproducible steps
- Clone
git clone https://github.com/sanjeevyadavIT/android-react-native-hybrid.git
- Checkout to feat/react-native-upgrade-69 branch
- cd
reactNative
folder- run
yarn install
to install npm dependency- Build project from Android Studio and build works
- enable new architecture from
gradle.properties
by settingnewArchEnabled=true
You will get error
Build file '/Users/username/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/ReactAndroid/build.gradle' line: 11 Error resolving plugin [id: 'org.jetbrains.kotlin.android', version: '1.6.10'] > Plugin request for plugin already on the classpath must not include a version
Open the file
/Users/username/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/ReactAndroid/build.gradle
and manually edit it fromplugins { ... ... id("org.jetbrains.kotlin.android") version "1.6.10" ... ... }
to
plugins { ... ... id("org.jetbrains.kotlin.android") apply false ... ... }
Rebuild the project in Android Studio, You will get error
Invalid value for "PACKAGE_PATH": Directory "/Users/username/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/ReactAndroid/hermes-engine/build/intermediates/prefab_package_configuration/debug/prefab" is not readable. CMake Error: The source directory "/Users/sanjeevyadav/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/sdks/hermes" does not exist. Specify --help for usage, or press the help button on the CMake GUI.
- run this command in terminal(make sure you are in Android directory)
brew install cmake
orbrew reinstall cmake
(if brew is already install)- Rebuild the project from Android Studio, Now the build start building c++ related files
- But the build fails again
/Users/username/AndroidStudioProjects/HybridSetup/reactNative/node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManager.java:356: error: cannot find symbol MapBuffer localData, ^ symbol: class MapBuffer location: class ViewManager<T,C> where T,C are type-variables: T extends View declared in class ViewManager C extends ReactShadowNode declared in class ViewManager
FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':ReactAndroid:compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details. * 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. ============================================================================== 2: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:mergeDebugNativeLibs'. > A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction > 2 files found with path 'lib/arm64-v8a/libc++_shared.so' from inputs: - /Users/username/AndroidStudioProjects/HybridSetup/react/build/intermediates/library_jni/debug/jni/arm64-v8a/libc++_shared.so - /Users/username/.gradle/caches/transforms-3/d8674da4422f7ce14c3f36129819f3d1/transformed/react-native-0.69.7-debug/jni/arm64-v8a/libc++_shared.so If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/r/tools/jniLibs-vs-imported-targets
Entire build log-> build_fails_log.txt
And now I am stuck, can you please look into this
I am stuck on the same issue
@cortinico I have created a reproducible demo
Thanks for your patience @sanjeevyadavIT Could you try on 0.71 as I believe we addressed your specific issue by encapsulating some build logic? I believe your problem is related to a conflicting Kotlin versino
@cortinico I have created a reproducible demo
Thanks for your patience @sanjeevyadavIT Could you try on 0.71 as I believe we addressed your specific issue by encapsulating some build logic? I believe your problem is related to a conflicting Kotlin versino
Hi, very sorry to weite you here but if any suggestion i will take it. since 7 months i had same issue, i'm on : Kali linux 2024 / Linux Rolling x kernel 6.6.9
i can event build ( development build) an empty project, i always this error: FAILURE: Build failed with an exception.
[CXX1210] /home/nobe/work/RN/demo/test-build/node_modules/expo-modules-core/android/CMakeLists.txt debug|armeabi-v7a : No compatible library found
New Version
0.69.7
Old Version
0.63.4
Build Target(s)
Android Studio Build Failing
Output of
react-native info
info Fetching system and libraries information... System: OS: macOS 12.6.1 CPU: (10) arm64 Apple M1 Pro Memory: 135.81 MB / 32.00 GB Shell: 3.2.57 - /bin/sh Binaries: Node: 16.14.0 - /usr/local/bin/node Yarn: 1.22.17 - /opt/homebrew/bin/yarn npm: 8.3.1 - /usr/local/bin/npm Watchman: 2022.06.27.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: iOS 15.0, DriverKit 20.4, macOS 11.3, tvOS 15.0, watchOS 8.0 Android SDK: Not Found IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8815526 Xcode: 13.0/13A233 - /usr/bin/xcodebuild Languages: Java: 11.0.11 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.0.0 => 18.0.0 react-native: 0.69.7 => 0.69.7 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Issue and Reproduction Steps
I am trying to upgrade RN version from
0.63.4
to0.69.7
, I made the changes mention in upgrade helper tool https://react-native-community.github.io/upgrade-helper/?from=0.63.4&to=0.69.7, I have also enabled the new architecture, when I am trying to build the Project on Android studio the build is failing and getting this error