React Native: Could not find method isNewArchitectureEnabled() for arguments on project :app - react-native

Trying to run React native project on my new device Macbook Pro got following error.
My Device specification:
Note: The project was running properly in my previous intel chip device.
Got stuck with an error and could not found the proper solution, any help and suggestion will be very helpful. Thanks in advance.

If the project use React native version < 0.68.0, you consider first migrate the whole project to the newer like >= 0.68.
Run the following command to start the process of upgrading to the latest version:
npx react-native upgrade
You may specify a React Native version by passing an argument, e.g. to upgrade to 0.XX.X
documentation here link
if you have a react native version >= 0.68.0 go to the
app/build.gradle
and you need to change many things like:
old version
...
/*** Architectures to build native code for in debug.
*/
def nativeArchitectures = project.getProperties().get("reactNativeDebugArchitectures")
new version
/*** Architectures to build native code for in debug.
*/
def reactNativeArchitectures() {
def value = project.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}
...
defaultConfig {
...
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
if (isNewArchitectureEnabled()) {
// We configure the CMake build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
cmake {
arguments "-DPROJECT_BUILD_DIR=$buildDir",
"-DREACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
"-DREACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
"-DNODE_MODULES_DIR=$rootDir/../node_modules",
"-DANDROID_STL=c++_shared"
}
}
if (!enableSeparateBuildPerCPUArchitecture) {
ndk {
abiFilters (*reactNativeArchitectures())
}
}
}
if (isNewArchitectureEnabled()) {
// We configure the NDK build only if you decide to opt-in for the New Architecture.
externalNativeBuild {
cmake {
path "$projectDir/src/main/jni/CMakeLists.txt"
}
}
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")
preDebugBuild.dependsOn(packageReactNdkDebugLibs)
preReleaseBuild.dependsOn(packageReactNdkReleaseLibs)
// Due to a bug inside AGP, we have to explicitly set a dependency
// between configureCMakeDebug* tasks and the preBuild tasks.
// This can be removed once this is solved: https://issuetracker.google.com/issues/207403732
configureCMakeRelWithDebInfo.dependsOn(preReleaseBuild)
configureCMakeDebug.dependsOn(preDebugBuild)
reactNativeArchitectures().each { architecture ->
tasks.findByName("configureCMakeDebug[${architecture}]")?.configure {
dependsOn("preDebugBuild")
}
tasks.findByName("configureCMakeRelWithDebInfo[${architecture}]")?.configure {
dependsOn("preReleaseBuild")
}
}
}
}
splits {
abi {
...
include (*reactNativeArchitectures())
}
}
dependencies {
...
}
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")
substitute(module("com.facebook.react:hermes-engine"))
.using(project(":ReactAndroid:hermes-engine"))
.because("On New Architecture we're building Hermes from source")
}
}
}
...
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" }
I hope this help you, for more information you can check the upgrade helper tool link
cheers ヽ( •_)ᕗ

Related

How properly to publish a Kotlin Multiplatform package with 1.6.10

I'm trying to publish to GitHub private package repo, and failing when I try to build the dependent project.
I've built and published it, and loaded it into a dependent project. Gradle makes no complaint and appears to download the requested project. The editor sees the symbols and is able to give autocomplete advice and type checking, but when I try to build, the :common:compileKotlinMetadata task fails with Unresolved references on the import statements referring to my package.
I've never yet seen something like a manifest describing exactly which artifacts are required by Kotlin MPP's various components. This project builds and runs fine if the dependency is just added as a subproject to build.gradle.kts and built along with the main package.
Again, the symbols all appear to have been published and acquired by the dependent project.
So, what artifacts might be missing, that the compiler requires for compileKotlinMetadata? I'd be fascinated to learn something about the kotlin toolchain here, namely: what files/resources are needed by the compiler versus those used by the editor to produce coding advice!
A rundown of what I've done:
On the dependent project:
gradle.properties
kotlin.code.style=official
kotlin.native.enableDependencyPropagation=false
android.useAndroidX=true
kotlin.version=1.6.10
agp.version=7.0.4
compose.version=1.1.1
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.disableCompilerDaemon=true
build.gradle.kts
repositories {
/* configure my repo here */
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("com.mycompany.groupname:package:1.0.12")
}
}
desktopMain {
implementation("com.mycompany.groupname:package-jvm:1.0.12")
}
}
}
On the published project:
gradle.properties
kotlin.code.style=official
kotlin.mpp.enableGranularSourceSetsMetadata=true
kotlin.native.enableDependencyPropagation=false
android.useAndroidX=true
kotlin.version=1.6.10
agp.version=7.0.4
compose.version=1.1.1
realm.version=0.10.2
build.gradle.kts
fun String.dasherize() = fold("") {acc, value ->
if (value.isUpperCase()) {
"$acc-${value.toLowerCase()}"
} else {
"$acc$value"
}
}
fun makeArtifactId(name: String) =
if ("kotlinMultiplatform" in name) {
mvnArtifactId
} else {
"$mvnArtifactId-${name.dasherize()}"
}
afterEvaluate {
configure<PublishingExtension> {
publications.all {
val mavenPublication = this as? MavenPublication
mavenPublication?.artifactId = makeArtifactId(name)
}
}
}
configure<PublishingExtension> {
publications {
withType<MavenPublication> {
groupId = "com.meowbox.fourpillars"
artifactId = makeArtifactId(name)
version
}
}
}

Runing coroutines in IntelliJ Kotlinx error

I'm trying to run a native Kotlin project using coroutines using IntelliJ IDEA Community 2020.
Here is how my build.gradle looks:
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
}
repositories {
mavenCentral()
}
kotlin {
// For ARM, should be changed to iosArm32 or iosArm64
// For Linux, should be changed to e.g. linuxX64
// For MacOS, should be changed to e.g. macosX64
// For Windows, should be changed to e.g. mingwX64
mingwX64("mingw") {
binaries {
executable {
// Change to specify fully qualified name of your application's entry point:
entryPoint = 'sample.main'
// Specify command-line arguments, if necessary:
runTask?.args('')
}
}
}
sourceSets {
// Note: To enable common source sets please comment out 'kotlin.import.noCommonSourceSets' property
// in gradle.properties file and re-import your project in IDE.
mingwMain {
}
mingwTest {
}
}
}
// Use the following Gradle tasks to run your application:
// :runReleaseExecutableMingw - without debug symbols
// :runDebugExecutableMingw - with debug symbols
And here is a simple KT file:
package sample
import kotlinx.coroutines.*
fun main() = runBlocking<Unit> {
val deferred = async(Dispatchers.Unconfined, CoroutineStart.LAZY) {
println("Running Async Unconfined: on thread ${Thread.currentThread().name} has run.")
42
}
val result = deferred.await()
println("Async Unconfined Result is ${result}")
}
I installed the maven plugin under Project Structure | Module and screenshot attached.
Nevertheless, I'm getting "Unresolved References..." error. Attached screenshot...
Request if someone can help me to resolve this please?
Thanks
In your Project Structure > Modules > Dependencies tab, you selected Runtime as the scope, which makes the dependency only available at runtime (usually used for transitive dependencies). Try selecting Compile here.

why kotlin multiplatform don't execute and export iOS framework?

I started develop kotlin multiplatform and I developed a simple lib for test. I can exported .jar file for android but I can't export .framework file for iOS.
I reviewed other project but I didn't find my issue.
my Gradle script for lib is:
apply plugin: 'kotlin-multiplatform'
kotlin {
targets {
final def iOSTarget =
System.getenv('SDK_NAME')?.startsWith("iphoneos") \
? presets.iosArm64 : presets.iosX64
fromPreset(iOSTarget, 'iOS') {
compilations.main.outputKinds('FRAMEWORK')
}
fromPreset(presets.jvm, 'android')
}
sourceSets {
core.dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
}
android.dependencies {
api 'org.jetbrains.kotlin:kotlin-stdlib'
}
}
Have you added the task to build the actual framework? If not, try adding this code at the end of your build.gradle file:
task packForXCode(type: Sync) {
final File frameworkDir = new File(buildDir, "xcode-frameworks")
final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
inputs.property "mode", mode
dependsOn kotlin.targets.iOS.compilations.main.linkTaskName("FRAMEWORK", mode)
from { kotlin.targets.iOS.compilations.main.getBinary("FRAMEWORK", mode).parentFile }
into frameworkDir
doLast {
new File(frameworkDir, 'gradlew').with {
text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$#\n"
setExecutable(true)
}
}
}
tasks.build.dependsOn packForXCode
The iOS framework will be available on the build/xcode-frameworks directory of your library.
You'll have to configure also your Xcode project to use the framework. For further details you can read Setting up Framework Dependency in Xcode.
What do you mean by "exporting a framework"? Are you going to use it from another Gradle project or from XCode or from something else?
P.S. Sorry for asking in answers: just have no enough reputation to leave a comment. So I think it would be more convenient to discuss you problem in issues at GitHub.

Unable to add react native plugin

I am trying to add react-native firebase plugin.
https://github.com/invertase/react-native-firebase
Unfortunately i am stuck at this issue. Any help will be appreciated
check link
Update your app/build.gradle on Android Studio
com.google.android.gms:play-services-gcm
dependencies {
compile(project(':react-native-firebase')) {
transitive = false
}
...
// From node_modules
compile project(':react-native-push-notification')
>>> compile ('com.google.android.gms:play-services-gcm:11.6.0') {
force = true;
}
// Firebase dependencies
compile "com.google.android.gms:play-services-base:11.6.0"
compile "com.google.firebase:firebase-core:11.6.0"
compile "com.google.firebase:firebase-analytics:11.6.0"
}

Cannot initialize Crashlytics NDK

I got a problem in initalizing Crashlytics for Android. The Java part works correctly but i cannot make NDK part to work because crashlytics_init() return a null value;
My project/build.gradle
buildscript {
repositories {
jcenter()
google()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'io.fabric.tools:gradle:1.24.4'
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
google()
maven {
url 'https://maven.fabric.io/public'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle containing
compileSdkVersion 26
android {
defaultConfig {
...
minSdkVersion 19
targetSdkVersion 22
...
}
...
}
crashlytics {
enableNdk true
manifestPath 'C:\\full\\path\\to\\manifest\\AndroidManifest.xml'
}
dependencies {
implementation 'com.google.firebase:firebase-crash:11.6.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6#aar') {
transitive = true;
}
compile 'com.google.firebase:firebase-core:11.6.0'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'org.apache.commons:commons-compress:1.12'
compile 'org.tukaani:xz:1.5'
}
main activity code
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
jniCrashlyticsInit();
...
}
and the native content of jniCrashlyticsInit()
void Java_com_my_app_MainActivity_jniCrashlyticsInit(JNIEnv *env,
jobject thiz)
{
crashlytics = crashlytics_init();
if (crashlytics == NULL)
log("CRASHLYTICS NULL");
else
log("CRASHLYTICS NON NULL");
}
As you imagine, "CRASHLYTICS NULL" is logged and it cannot initialize all the stuff.
I've put logs also inside crashlytics.h and it happens to fail on this line (returning a null value)
__crashlytics_unspecified_t* ctx = ((__crashlytics_initialize_t) sym_ini)();
Since i got no further infos, i really don't know how to proceed.
Ideas?
Some info more:
I use Android studio 3.0.0, and the NDK libraries are compiled manually with the following command
/cygdrive/c/Android/ndk-r15c/ndk-build.cmd NDK_DEBUG=0 APP_BUILD_SCRIPT=./Android.mk NDK_PROJECT_PATH=. APP_PLATFORM=android-19
**** Update November 20th ****
As suggested by Todd Burner, I switched from "compile" to "implementation" on build.gradle from
compile('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
compile('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6#aar') {
transitive = true;
}
to
implementation('com.crashlytics.sdk.android:crashlytics:2.7.1#aar') {
transitive = true
}
implementation('com.crashlytics.sdk.android:crashlytics-ndk:1.1.6#aar') {
transitive = true;
}
then i ran
./gradlew assemble --refresh-dependencies
Unfortunally, crashlytics_init() still returns NULL
I struggled days with this same issue. In my case I would blame partly the not-so-very-thorough documentation in the Fabric website and partly the lack of my reading comprehension.
I cannot be sure if you experience just the same thing, but my problem was that I tried to load Crashlytics NDK twice.
If you do the initialization from java like this:
Fabric.with(this, new Crashlytics(), new CrashlyticsNdk());
the native Crashlytics is automatically loaded and you don't need to initialize Crashlytics from C++. If you step into the decompiled Crashlytics .class files starting from CrashlyticsNdk.class you can see that JniNativeApi.class already calls System.loadLibrary("crashlytics").
In fact, if you still try to initialize Crashlytics from native side after that, the line
__crashlytics_unspecified_t* ctx = ((__crashlytics_initialize_t) sym_ini)();
will return NULL because the library has been already loaded.
What confused me is that the Official Fabric documentation doesn't say with bright red flashing letters that if you call new CrashlyticsNdk() from Java, you shouldn't try to load native Crashlytics from C++. To be fair, the documentation does say the following: In the process of initialization via Fabric.with(), the NDK Kit uses System.loadLibrary to load libcrashlytics. But it's a single line right before the Native API explanation starts and is easily overlooked.