Can not start new kotlin multiplatform library with dependency on exposed library - kotlin-multiplatform

I want to use jetbrains exposed library in a kotlin multiplatform library I am writing. How do I do this?
I am getting a gradle build error that it can not find everything it needs for exposed. Here is my gradle build
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.exposed:exposed-core:0.34.1")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jsMain by getting
val jsTest by getting
val nativeMain by getting
val nativeTest by getting
}
and I get this in the build log
Failed building KotlinMPPGradleModel
org.gradle.internal.resolve.ArtifactNotFoundException: Could not find exposed-core-0.34.1-samplessources.jar (org.jetbrains.exposed:exposed-core:0.34.1).
Searched in the following locations:
https://repo.maven.apache.org/maven2/org/jetbrains/exposed/exposed-core/0.34.1/exposed-core-0.34.1-samplessources.jar
at org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult.notFound(DefaultBuildableArtifactResolveResult.java:28)...

This library targets jvm only, since you have native targets it isn't compatible with your common source set

Related

Build failed while running KMM project in ios simulator ( Could not resolve com.android.tools.build:gradle:7.4.0 )

today i have created KMM project with latest android android studio version (Android Studio Electric Eel | 2022.1.1 Patch 1) but when running this project on ios simulator it throws the below exception while in android device it's working fine.
* What went wrong:
A problem occurred configuring root project 'kmm_project'.
> Could not resolve all files for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:7.4.0.
Required by:
project : > com.android.application:com.android.application.gradle.plugin:7.4.0
project : > com.android.library:com.android.library.gradle.plugin:7.4.0
> No matching variant of com.android.tools.build:gradle:7.4.0 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' but:
- Variant 'apiElements' capability com.android.tools.build:gradle:7.4.0 declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
- Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
- Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
- Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.0 declares a runtime of a component, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
* 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 4s
Command PhaseScriptExecution failed with a nonzero exit code
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution Run\ Script /Users/jayantkumar/Documents/android_studio/kmmproject/build/ios/iosApp.build/Debug-iphonesimulator/iosApp.build/Script-7555FFB5242A651A00829871.sh (in target 'iosApp' from project 'iosApp')
(1 failure)
My build.gradle(project)
plugins {
//trick: for the same plugin versions in all sub-modules
id("com.android.application").version("7.4.0").apply(false)
id("com.android.library").version("7.4.0").apply(false)
kotlin("android").version("1.7.10").apply(false)
kotlin("multiplatform").version("1.7.20").apply(false)
}
tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
}
My build.gradle(module) file
plugins {
id("com.android.application")
kotlin("android")
}
android {
namespace = "com.nameisjayant.kmmproject.android"
compileSdk = 33
defaultConfig {
applicationId = "com.nameisjayant.kmmproject.android"
minSdk = 24
targetSdk = 33
versionCode = 1
versionName = "1.0"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.3.2"
}
packagingOptions {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
dependencies {
implementation(project(":shared"))
implementation("androidx.compose.ui:ui:1.3.3")
implementation("androidx.compose.ui:ui-tooling:1.3.3")
implementation("androidx.compose.ui:ui-tooling-preview:1.3.3")
implementation("androidx.compose.foundation:foundation:1.3.1")
implementation("androidx.compose.material:material:1.3.1")
implementation("androidx.activity:activity-compose:1.6.1")
}
My gradle-wrapper.properties file
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
As i already selected the Java 11 version?
If anyone have any idea about this please let me know , Thanks :)

KMM Cocoapods Export (M1) Mac

So i am trying to export my KMM project as iOS framework
here is my build.gradle.kts
kotlin {
android()
ios()
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0-RC")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.1")
implementation("com.soywiz.korlibs.klock:klock:2.2.2")
implementation("com.ionspin.kotlin:bignum:0.3.2")
}
}
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 iosMain by getting {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
}
val iosTest by getting
}
cocoapods {
framework {
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
baseName = "sharedCode"
isStatic = false
export(project(":sharedCode"))
transitiveExport = true
}
podfile = project.file("/Users/user/Developments/SampleApp/Podfile")
ios.deploymentTarget = "14.0"
}
}
here is my Podfile
platform :ios, '14.0'
use_frameworks!
target 'Sample App' do
pod 'sharedCode', :path => '/Users/User/Developments/KotlinMultiplatform/sharedCode'
end
Whenever i run the gradle sync from Android Studio it will throw this error
Executing of 'pod install' failed with code 1.
Error message:
Please, check that file "/Users/User/Developments/SampleApp/Podfile" contains following lines in header:
source 'https://cdn.cocoapods.org'
Please, check that each target depended on sharedCode contains following dependencies:
And then i tried to run the pod install command from my terminal and it successfully installed the cocoapods. however during build I encounter this another problem
* What went wrong:
Execution failed for task ':sharedCode:linkPodDebugFrameworkIosArm64'.
Following dependencies exported in the podDebugFramework binary are not specified as API-dependencies of a corresponding source set:
Project :sharedCode
Please add them in the API-dependencies and rerun the build.
What am I missing here? Thank you
i had the same issue.
open terminal and run vim .zshrc. add LANG=en_US.UTF-8 then save it.
This resolved problem for me.

Importing GoogleWebRTC pod fails: module 'GoogleWebRTC' not found

I am currently working on a Kotlin multiplatform and am trying to interface with the GoogleWebRTC pod.
The pod exists, I was able to import it in a separate project (without Kotlin multiplatform). I can see the .framework is created in my build directory, however when doing a gradle sync or building from Xcode, I get the following error:
Exception in thread "main" java.lang.Error: /var/folders/hv/9cx28nxx4gz9hj_m86bp5rx40000gn/T/tmp362966650322311128.m:1:9: fatal error: module 'GoogleWebRTC' not found
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:152)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesASTFiles(ModuleSupport.kt:67)
at org.jetbrains.kotlin.native.interop.indexer.ModuleSupportKt.getModulesInfo(ModuleSupport.kt:13)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.buildNativeLibrary(main.kt:499)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:264)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.interop(main.kt:72)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:45)
at org.jetbrains.kotlin.cli.utilities.MainKt.mainImpl(main.kt:19)
at org.jetbrains.kotlin.cli.utilities.MainKt.main(main.kt:37)
Execution failed for task ':shared:cinteropGoogleWebRTCIosArm64'.
> Process 'command '/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
AFNetworking seems to work fine, but adding the WebRTC pod seems to break the project.
Am I missing a limitation of Kotlin multiplatform or something?
This is my build.gradle.kts:
cocoapods {
// Configure fields required by CocoaPods.
summary = "Some description for a Kotlin/Native module"
homepage = "Link to a Kotlin/Native module homepage"
// You can change the name of the produced framework.
// By default, it is the name of the Gradle project.
frameworkName = "shared"
ios.deploymentTarget = "10.0"
pod("GoogleWebRTC", "~> 1.1")
pod("AFNetworking", "~> 4.0.0")
}
I was able to reproduce this issue but I didn't figure out the reason why.
It seems a there's something wrong with GoogleWebRTC pod and the Kotlin-native/cocoapods integration.
I've opened an issue here.
We have an official help.
It seems that the frameworks name is different from the pod name. So a possible solution could be that:
kotlin {
cocoapods {
[...]
pod("GoogleWebRTC", moduleName = "WebRTC", version = "~> 1.1")
[...]
}
[...]
}
I tried it and it works.

MultiView FXML Project on iOS using Gluon-mobile and Java9

Creating a completely new MultiView FXML Project and then adding the Java9 necessities in Gradle:
buildscript {
repositories {
jcenter()
google()
maven{
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:2.0.5'
}
}
...
sourceCompatibility = 1.8
targetCompatibility = 1.8
...
dependencies {
compile 'com.gluonhq:charm:4.4.0-jdk9'
androidRuntime 'com.gluonhq:charm:4.4.1'
compile 'com.airhacks:afterburner.mfx:1.6.3'
// Added because of javax.annotation.PostConstruct Java9 issues
compile group: 'javax.xml.ws', name: 'jaxws-api', version: '2.2.6'
}
leads to [SUB] Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: Stage must be showing before making the Dialog visible.
full console log
The project runs as expected on Desktop and Android, but not on iOS simulator and device. I have tried many things, but since this error comes on newly created projects leads me to believe that it's something caused by the interplay of gluon-mobile and Java9.
Bonus: Changing only the jfxmobile-plugin to 2.0.18 fails even compiling with:
[15:08:15:141] com.gluonhq.higgs.Higgs: Still compiling... 8823
classes left.
[15:08:25:143] com.gluonhq.higgs.Higgs: Still
compiling... 4152 classes left.
[15:08:34:389] com.gluonhq.higgs.Compiler: halfway done round 0
java.lang.StackOverflowError
at java.base/java.util.HashMap.putVal(HashMap.java:642)
at java.base/java.util.HashMap.put(HashMap.java:612)
at java.base/java.util.HashSet.add(HashSet.java:220)
at com.gluonhq.higgs.DependencyGraph.visitReachableNodes(DependencyGraph.java:170)
These steps work for me:
Using Java 9, and NetBeans 9 (beta version) with Gluon IDE plugin 2.6.2, I've created a Gluon project (multi view with FXML). Of course, this will work with other IDEs as well.
I've checked that the gradle wrapper was using 4.3.1 (or superior).
I've modified the build.gradle file to use Gluon VM with jfxmobile 2.0.18:
build.gradle file:
buildscript {
repositories {
jcenter()
google()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:2.0.18'
}
}
and updated the dependencies:
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile 'com.gluonhq:charm:4.4.0-jdk9'
compile 'com.airhacks:afterburner.mfx:1.6.3'
compile 'javax.annotation:javax.annotation-api:1.3.2'
androidRuntime 'com.gluonhq:charm:4.4.1'
}
Then I just deployed the project to my iOS device without any issue.
Note that it may be convenient to clean your ~/.gvm cache, as it might contain classes from older versions that shouldn't be used anymore. Of course, you should also clean your project ./gradle and /build folders.

How do I get protobuf methods to resolve in intellij when using bazel?

I'm having an issue where I have a working java program that uses protobuf and is built using bazel, but where intellij doesn't recognize the method toByteArray.
I forked https://github.com/cgrushko/proto_library on my local machine, imported the workspace into intellij and built. I then added the following java main class:
package src;
import demo.PersonOuterClass;
public class Main {
public static void main(String argv[]) {
byte[] ba = PersonOuterClass.Person.newBuilder().setEmail("dwwd").build().toByteArray();
for (byte b : ba) {
System.out.println(b);
}
}
}
and the following bazel build rule
java_binary(
name = "Main",
main_class = "src.Main",
srcs = ["Main.java"],
deps = [":person_java_proto"]
)
The program builds and runs properly, but in intellij toByteArray() is red and intellij says that it can't resolve the method.
I suspect the issue is that generated Person extends com.google.protobuf.GeneratedMessageV3 but intellij doesn't know about GeneratedMessageV3 and that it extends a class, AbstractMessageLite, that defines the toByteArray method.
Anyone know how to fix either the bazel build target(s) or intellij so that toByteArray is resolved by the ide?
Thanks,
Tom.
I solved this problem by marking bazel-/external/java/com_google_protobuf_java/core/src/main/java as a source root. (Right click -> Mark Directory as -> Sources Root)
I fixed this on my Bazel project by adding com.google.protobuf:protobuf-java as a dependency for the Bazel library depending on protobuf.

Resources