KMM in Android Studio build return Command PhaseScriptExecution failed with a nonzero exit code - kotlin

I've just created a new KMM project through out KMM Plugin, but I can't run or even debug in Xcode iosApp part of the project. When I try to run iosApp from Android Studio, the build process fails (Command PhaseScriptExecution failed with nonzero exit code)
The final lines of building was:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':shared:compileKotlinIosX64'.
Compilation finished with errors
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 8s
1 actionable task: 1 executed
Command PhaseScriptExecution failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Run\ Script /Users/tamegajr/AndroidStudioProjects/TesteKMM5/build/ios/iosApp.build/Release-iphonesimulator/iosApp.build/Script-7555FFB5242A651A00829871.sh
(1 failure)
Can anyone help to solve this problem?

I had the same issue but this solution helped me:
From KMM pluging you will obtain (on dependencies):
Change this:
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
To this:
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")

What i found to be the solution was to uncomment the "iosSimulatorArm64()" in the "build.gradle.kts(:shared)".
kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64() //sure all ios dependencies support this target
cocoapods {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
ios.deploymentTarget = "14.1"
podfile = project.file("../iosLink/Podfile")
framework {
baseName = "shared"
}
}
sourceSets {
val commonMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val androidMain by getting
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
}
}
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
val iosX64Test by getting
val iosArm64Test by getting
//val iosSimulatorArm64Test by getting
val iosTest by creating {
dependsOn(commonTest)
iosX64Test.dependsOn(this)
iosArm64Test.dependsOn(this)
//iosSimulatorArm64Test.dependsOn(this)
}
}
}

After some code review from 2-3 months old KMM examples project and comparing them with new ones, I found out a solution for this build failure when trying to run iosApp on Ios Simulators, just apply this change to build.gradle.kts on root project:
From KMM pluging you will obtain (on dependencies):
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10")
Change it to:
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")
And that's it, problem solve. I hope someone on Jetbrains can solve this problem in future updates of KMM plugin.
08/30/2020:
It seems that Jetbrains has correct some issues and now you can build and run a KMM project with version 1.7.10, the last stable version at this time.
By the way, if you have any trouble is worthy to check this stack overflow post about JDK version used by Android Studio : How to set or change the default Java (JDK) version on macOS?
Multiplatform error when building iosApp: Command PhaseScriptExecution failed with a nonzero exit code

Related

Execution failed for task ':app:mergeDebugNativeLibs' while running react-native app

While running react native app I am getting following error:
`
Task :app:mergeDebugNativeLibs FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.9.2/userguide/command_line_interface.html#sec:command_line_warnings
574 actionable tasks: 2 executed, 572 up-to-date
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
2 files found with path 'lib/armeabi-v7a/libfbjni.so' from inputs:
- C:\Users\nouman.gradle\caches\transforms-3\6ef14503de3c85fa1ab2aba364d580cc\transformed\jetified-react-native-0.71.0-rc.0-debug\jni
- C:\Users\nouman.gradle\caches\transforms-3\64faf76bb2f0142d731347d7bfff47d4\transformed\jetified-fbjni-0.3.0\jni
If you are using jniLibs and CMake IMPORTED targets, see
https://developer.android.com/r/tools/jniLibs-vs-imported-targets
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 32s
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.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
A failure occurred while executing com.android.build.gradle.internal.tasks.MergeJavaResWorkAction
2 files found with path 'lib/armeabi-v7a/libfbjni.so' from inputs:
- C:\Users\nouman.gradle\caches\transforms-3\6ef14503de3c85fa1ab2aba364d580cc\transformed\jetified-react-native-0.71.0-rc.0-debug\jni
- C:\Users\nouman.gradle\caches\transforms-3\64faf76bb2f0142d731347d7bfff47d4\transformed\jetified-fbjni-0.3.0\jni
If you are using jniLibs and CMake IMPORTED targets, see
https://developer.android.com/r/tools/jniLibs-vs-imported-targets
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 32s
at makeError (D:\BayQi-Customer-Mobile-App\node_modules\execa\index.js:174:9)
at D:\BayQi-Customer-Mobile-App\node_modules\execa\index.js:278:16
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async runOnAllDevices (D:\BayQi-Customer-Mobile-App\node_modules\react-native\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:5)
at async Command.handleAction (D:\BayQi-Customer-Mobile-App\node_modules\#react-native-community\cli\build\index.js:192:9)
info Run CLI with --verbose flag for more details.
`
I am trying to run my react native app in physical device but getting this error.
It was running okay but suddenly has stopped working
UPDATED ANSWER
📢 Patches for >= 0.63 We have prepared releases for all the main versions of react-native with an hotfix:
🛳 0.70.5: https://github.com/facebook/react-native/releases/tag/v0.70.5
🛳️ 0.69.7: https://github.com/facebook/react-native/releases/tag/v0.69.7
🛳 0.68.5: https://github.com/facebook/react-native/releases/tag/v0.68.5
🛳️ 0.67.5: https://github.com/facebook/react-native/releases/tag/v0.67.5
🛳️ 0.66.5: https://github.com/facebook/react-native/releases/tag/v0.66.5
🛳️ 0.65.3: https://github.com/facebook/react-native/releases/tag/v0.65.3
🛳️ 0.64.4: https://github.com/facebook/react-native/releases/tag/v0.64.4
🛳️ 0.63.5: https://github.com/facebook/react-native/releases/tag/v0.63.5
By updating to these patch versions, your Android build should start working again.
Source https://github.com/facebook/react-native/issues/35210
OLD ANSWER
Add this to your android/build.gradle,
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
allprojects {
configurations.all {
resolutionStrategy {
force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
}
}
If that does not work for you (with the dynamic version), then hard code your version in:
PLEASE BE CAREFUL TO MOVE THIS VERSION WHEN YOU UPDATE REACT-NATIVE
allprojects {
configurations.all {
resolutionStrategy {
force 'com.facebook.react:react-native:<your version>'
}
}
repositories {
// ...
}
}
Check this for more updates https://github.com/facebook/react-native/issues/35204
add this to your app/build.gradle
android {
// yout existing code
packagingOptions {
pickFirst '**/libc++_shared.so'
pickFirst '**/libfbjni.so'
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
// ...
}
allprojects {
repositories {
+ exclusiveContent {
+ // We get React Native's Android binaries exclusively through npm,
+ // from a local Maven repo inside node_modules/react-native/.
+ // (The use of exclusiveContent prevents looking elsewhere like Maven Central
+ // and potentially getting a wrong version.)
+ filter {
+ includeGroup "com.facebook.react"
+ }
+ forRepository {
+ maven {
+ url "$rootDir/../node_modules/react-native/android"
+ }
+ }
+ }
// ...
}
}
New patch release for react-native
https://github.com/facebook/react-native/issues/35210#:%7E:text=We%20have%20prepared%20releases%20for%20all%20the%20main%20versions%20of%20react%2Dnative%20with%20an%20hotfix%3A
just update your package.json with latest react-native version
This helped me to resolve the issue.
This is happening because all the templates reference the React Native dependency by range, like implementation com.facebook.react:react-native:+. Usually this dependency gets resolved from the local Maven repo in ./node_modules/react-native/android but, since it has been published to Maven Central, it's now grabbing the very latest RC.
You can resolve this problem by forcing the React Native dependency to the version you expect with something like this implementation com.facebook.react:react-native:0.68.2!! in your app's Gradle file. The !! is shorthand for restricting Gradle from upgrading if your project or its transitive dependencies depend on a newer version. AFAIK Maven Central is immutable and the published dependency can't removed so this might be the only solution.
File: android/app/build.gradle
dependencies {
implementation 'com.facebook.react:react-native:0.67.2!!'
}
Reference: https://github.com/facebook/react-native/issues/35204
Workaround: I have made the following changes & It is working:
In gradle-wrapper.properties file, change gradle version
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
In project level build.gradle file, add following lines:
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0")
}
allprojects {
repositories {
exclusiveContent {
// We get React Native's Android binaries exclusively through
npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like
Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
}
configurations.all {
resolutionStrategy {
force 'androidx.core:core:1.6.0'
force 'androidx.core:core-ktx:1.6.0'
}
}
In app level build.gradle, add these dependecies:
implementation 'androidx.core:core-ktx:1.6.0',
implementation 'androidx.core:core:1.6.0'
Add following lines inside the android>build.gradle file -
allprojects {
repositories {
...
exclusiveContent {
// We get React Native's Android binaries exclusively through npm,
// from a local Maven repo inside node_modules/react-native/.
// (The use of exclusiveContent prevents looking elsewhere like Maven Central
// and potentially getting a wrong version.)
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
}
This issue occurred from November 4th 2022. See the reference: https://github.com/facebook/react-native/issues/35210

Kotlin native platform posix compilation without gradle

I am trying to compile a basic Kotlin/Native program with just the kotlinc-native CLI compiler rather than a full Gradle build. However, I cannot get the platform.posix library to work, despite compiling on linux for linux.
The source code I am using is:
import platform.posix.exit
fun main() {
println("Should exit with status 10")
exit(10)
}
When compiled with the following build.gradle.kts it works fine:
plugins {
kotlin("multiplatform") version "1.6.10"
}
repositories {
mavenCentral()
}
kotlin {
linuxX64("native") {
binaries {
executable()
}
}
}
However, when compiled from the command-line with:
kotlinc-native test.kt
I get:
test.kt:1:8: error: unresolved reference: platform
import platform.posix.exit
^
test.kt:4:5: error: unresolved reference: exit
exit(10)
^
Anyone know how to get Kotlin/Native compilation working fully without using Gradle? Or is there some magic that Gradle does that makes it work?
Thanks.

Unresolved reference: protoc - when using Gradle + Protocol Buffers

I have a gradle project which uses the Kotlin DSL
build.gradle.kts
plugins {
kotlin("jvm") version "1.4.21"
id("com.google.protobuf") version "0.8.10"
}
group = "schema"
version = "0.0.1-SNAPSHOT"
repositories {
mavenCentral()
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.0.0"
}
}
schema.proto
syntax = "proto3";
package schema;
message Message {
string content = 1;
string date_time = 2;
}
and project structure
schema
-src/main/proto/schema.proto
-build.gradle.kts
Whenever I run gradle build I get error:
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/x/schema/build.gradle.kts' line: 13
* What went wrong:
Script compilation errors:
Line 15: protoc {
^ Unresolved reference: protoc
Line 16: artifact = "com.google.protobuf:protoc:3.0.0"
^ Unresolved reference: artifact
* 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 8s
The only thing I am doing different to various tutorials is using the Gradle Kotlin DSL. What am I doing wrong?
I think this is happening because you are referencing a single task within the protobuf gradle plugin. Try importing the whole bundle to make use of type-safe accessors as you desired.
import com.google.protobuf.gradle.*
For whatever reason this works
import com.google.protobuf.gradle.protoc
protobuf {
protobuf.protoc {
artifact = "com.google.protobuf:protoc:3.0.0"
}
}
It seems a little ugly having to specify protobuf twice mind

io.micronaut.runtime.Micronaut - No embedded container found

I'm trying to build a Kotlin application but, even with successfully build, I face with the error bellow. What I'm doing wrong?
▶ java -jar build/libs/app-0.1.jar
22:10:02.122 [main] INFO io.micronaut.runtime.Micronaut - No embedded container found. Running as CLI application
Here is my build status:
▶ ./gradlew assemble
BUILD SUCCESSFUL in 3s
14 actionable tasks: 1 executed, 13 up-to-date
That is the part of my gradle.build file:
apply from: "dependencies.gradle"
apply from: "protobuf.gradle"
version "0.1"
group "app"
mainClassName = "app.Application"
dependencies {
compile "ch.qos.logback:logback-classic:1.2.3"
}
jar {
manifest {
attributes "Main-Class": mainClassName
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
I had a similar issue:
I was able to run code from IDE, but failed to run Docker container with the app
And had compile 'io.micronaut:micronaut-http-server-netty:1.1.0' in my build.gradle.
Also I was using shadowJar plugin and there was the issue. Adding:
shadowJar {
mergeServiceFiles()
}
solved the problem. It transforms entries in META-INF/services resources into a single resource. My shadowed jar file contained a lot of entries in this folder.
It is difficult to say for sure without seeing the project but one thing that could cause that issue would be not having a dependency on io.micronaut:micronaut-http-server-netty. A newly created app will have something like this in build.gradle...
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
compile "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
compile "io.micronaut:micronaut-runtime"
compile "io.micronaut:micronaut-http-client"
// Make Sure You Have This...
compile "io.micronaut:micronaut-http-server-netty"
kapt "io.micronaut:micronaut-inject-java"
kapt "io.micronaut:micronaut-validation"
kaptTest "io.micronaut:micronaut-inject-java"
runtime "ch.qos.logback:logback-classic:1.2.3"
runtime "com.fasterxml.jackson.module:jackson-module-kotlin:2.9.4.1"
testCompile "org.junit.jupiter:junit-jupiter-api:5.1.0"
testCompile "org.jetbrains.spek:spek-api:1.1.5"
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.1.0"
testRuntime "org.jetbrains.spek:spek-junit-platform-engine:1.1.5"
}

How to setup/build LibGDX + Kotlin project correctly?

I've downloaded gdx-setup.jar and try to build empty project with the following settings:
And here is what I get in console:
Generating app in C:\Users\Divelix\Desktop\test
Executing 'C:\Users\Divelix\Desktop\test/gradlew.bat clean --no-daemon idea'
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/4.6/userguide/gradle_daemon.html.
Daemon will be stopped at the end of the build stopping after processing
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation'.
It will be removed at the end of 2018
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':android'.
> Failed to notify project evaluation listener.
> com.android.build.gradle.internal.variant.BaseVariantData.getOutputs()Ljava/util/List;
* 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 22s
Done!
To import in Eclipse: File -> Import -> General -> Existing Projects into Workspace
To import to Intellij IDEA: File -> Open -> YourProject.ipr
If I do not mark "Use Kotlin" it builds well, so why is that and what am I doing wrong?
Well, I've finally figured out how to build project correctly with Kotlin (and if you have trouble with gradle it also will help you). Firstly, you just should to build it without "Use Kotlin" and than than edit your project build.gradle file like this:
buildscript {
ext.kotlinVersion = '1.1.1'
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
Also you should delete google() if you have it after jcenter()
In :desktop replace java with kotlin plugin and add kotlin-stdlib
project(":desktop") {
apply plugin: "kotlin"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
}
In :android add kotlin-android plugin and kotlin-stdlib
project(":android") {
apply plugin: "android"
apply plugin: "kotlin-android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
}
In :core replace java with kotlin plugin and add kotlin-stdlib
project(":core") {
apply plugin: "kotlin"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.ashley:ashley:$ashleyVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
}
If you have just kotlin issue it would be enough.
If you also have gradle issue like me, so open gradle-wrapper.properties and fix gradle version to 3.3:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip