I am discovering the new plugins declaration in Gradle. First applying below in the root Gradle file
plugins {
id("com.android.application") version "7.2" apply false
id("com.android.library") version "7.2" apply false
}
instead of
classpath 'com.android.tools.build:gradle:7.2.0'
And I also need the Gradle plugin in buildSrc so I have below in there, too
plugins {
`kotlin-dsl`
}
gradlePlugin {
plugins {
register("LibraryCommonPlugin") {
id = "libraryCommonPlugin"
implementationClass = "LibraryCommonPlugin"
}
}
}
repositories {
mavenCentral()
gradlePluginPortal()
google()
}
dependencies {
compileOnly(libs.plugin.android)
compileOnly(libs.plugin.kotlin)
implementation(libs.plugin.gradleVersions)
implementation(libs.kotlin)
compileOnly(gradleApi())
compileOnly(localGroovy())
}
And I have a common Gradle file that applies the plugin in child modules if is used
android_defaults.gradle
apply from: "$rootDir/buildsystem/helper.gradle"
apply plugin: "libraryCommonPlugin"
android {
defaultConfig {
...
app/build.gradle.kts
plugins {
id("com.android.application")
kotlin("android")
kotlin("kapt")
}
apply(from = "../buildsystem/android_defaults.gradle")
but then IDE throws an exception when I try to build
What went wrong: A problem occurred evaluating script.
com/android/build/gradle/AppPlugin
Caused by: java.lang.NoClassDefFoundError:
com/android/build/gradle/AppPlugin
Problems occuring from this custom plugin
class LibraryCommonPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.plugins.all { plugin ->
when (plugin) {
is AppPlugin -> target.configureAndroid()
is LibraryPlugin -> target.configureLibrary()
is KotlinBasePluginWrapper -> target.configureWithKotlinPlugin()
}
true
}
}
private fun Project.configureAndroid() {
androidDependencies()
baseKotlinModuleDependencies()
extensions.getByType<AppExtension>().configure()
}
private fun Project.configureLibrary() {
androidDependencies()
baseKotlinModuleDependencies()
extensions.getByType<LibraryExtension>().configure()
}
private fun Project.configureWithKotlinPlugin() {
baseKotlinDependencies()
tasks.withType<KotlinCompile>().configureEach {
this.kotlinOptions.jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
}
private fun BaseExtension.configure() {
setCompileSdkVersion(ProjectConfig.compileSdkVersion)
with(defaultConfig) {
minSdk = ProjectConfig.minSdkVersion
targetSdk = ProjectConfig.targetSdkVersion
vectorDrawables.useSupportLibrary = true
}
with(compileOptions) {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
isCoreLibraryDesugaringEnabled = true
}
}
private fun Project.androidDependencies() {
commonAndroidDependencies()
}
private fun Project.commonAndroidDependencies() {
dependencies {
add("coreLibraryDesugaring", Dependencies.Tools.desugarJdkLibs)
}
}
private const val IMPLEMENTATION = "implementation"
private const val LINT_CHECKS = "lintChecks"
private fun Project.baseKotlinDependencies() {
dependencies {
add(IMPLEMENTATION, Dependencies.Base.kotlin)
add(IMPLEMENTATION, Dependencies.Base.kotlinReflect)
}
}
private fun Project.baseKotlinModuleDependencies() {
dependencies {
add(LINT_CHECKS, project(Dependencies.Modules.Base.customLint))
}
}
So how can I have the Gradle plugin works for the both places?
Thanks!
Related
I have a ToolWindowFactory class like this
class MyToolWindowFactory : ToolWindowFactory {
private val sharedFlow = MutableSharedFlow<String>(replay = 1)
override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
CoroutineScope(Dispatchers.IO).launch {
sharedFlow.emit("VALUE")
}
CoroutineScope(Dispatchers.IO).launch {
sharedFlow.collectLatest {
println("$it")
}
}
}
}
I use SharedFlow for variables, but I get this error after run.
Exception in thread "DefaultDispatcher-worker-3" java.lang.NoClassDefFoundError: Could not initialize class kotlinx.coroutines.CoroutineExceptionHandlerImplKt
at kotlinx.coroutines.CoroutineExceptionHandlerKt.handleCoroutineException(CoroutineExceptionHandler.kt:33)
at kotlinx.coroutines.DispatchedTask.handleFatalException$kotlinx_coroutines_core(DispatchedTask.kt:95)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:64)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Does ShareStateFlow work in Intelji Plugin?
build.gradle
plugins {
id 'org.jetbrains.intellij' version '1.5.2'
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.9"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version = '2021.3.3'
}
patchPluginXml {
changeNotes = """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}
test {
useJUnitPlatform()
}
We are creating an app using KMM. But we are facing an issue, kSoap2 Library works fine in the android app but when this library used in Shared Directory of Android Studio, it doesn't work and gives error. The Same thing applies to Calendar. It is also not working, when writing Calendar.getInstance() the error says
Cannot access 'Kotlin.Cloneable'' which is a supertype of
'java.util.Calendar'. Check your module classpath for missing or
conflicting dependencies
build.gradle.kts(for Shared)
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("com.android.library")
}
repositories {
google()
mavenCentral()
}
kotlin {
android()
val iosTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iosTarget("ios") {
binaries {
framework {
baseName = "shared"
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
// implementation("com.facebook.android:facebook-android-sdk:[5,6)")
// implementation("com.google.android.material:material:1.3.0")
// implementation("com.google.firebase:firebase-messaging:10.2.1")
// implementation("com.google.android.gms:play-services:10.2.1")
// implementation("com.google.android.gms:play-services-ads:10.2.1")
// implementation("com.google.firebase:firebase-core:10.2.1")
// implementation("com.google.firebase:firebase-auth:10.2.1")
// implementation("com.github.siyamed:android-shape-imageview:0.9.+#AndreiA")
// implementation("com.github.barteksc:android-pdf-viewer:3.1.0-beta.1")
// implementation("org.apache.commons:commons-io:1.3.2")
implementation("com.google.android.material:material:1.3.0")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("androidx.legacy:legacy-support-v13:1.0.0")
implementation("androidx.core:core:1.0.0")
implementation("androidx.legacy:legacy-support-v4:1.0.0")
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
implementation("com.android.support.constraint:constraint-layout:")
implementation("com.google.firebase:firebase-messaging:10.2.1")
implementation("com.google.android.gms:play-services:10.2.1")
implementation("com.google.android.gms:play-services-ads:10.2.1")
implementation("com.google.firebase:firebase-core:10.2.1")
implementation("com.google.firebase:firebase-auth:10.2.1")
implementation("com.github.siyamed:android-shape-imageview:0.9.+#AndreiA")
implementation("com.facebook.android:facebook-android-sdk:[5,6)")
implementation("androidx.mediarouter:mediarouter:1.0.0")
implementation("androidx.vectordrawable:vectordrawable:1.0.0")
implementation("com.github.barteksc:android-pdf-viewer:3.1.0-beta.1")
implementation("org.apache.commons:commons-io:1.3.2")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.30")
}
}
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 iosMain by getting
val iosTest by getting
}
}
apply { plugin("com.google.gms.google-services") }
android {
compileSdkVersion(30)
sourceSets["main"].manifest.srcFile("src//androidMain//AndroidManifest.xml")
defaultConfig {
minSdkVersion(17)
targetSdkVersion(30)
}
}
val packForXcode by tasks.creating(Sync::class) {
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode)
val targetDir = File(buildDir, "xcode-frameworks")
group = "build"
dependsOn(framework.linkTask)
inputs.property("mode", mode)
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)
dependencies {
implementation(files("/Users/mbp/AndroidStudioProjects/PashtoLibrary/androidApp/libs/ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar"))
implementation(files("/Users/mbp/AndroidStudioProjects/PashtoLibrary/androidApp/libs/org.apache.commons.net_2.0.0.v200905272248.jar"))
}
build.gradle.kts(for AndroidApp):
import org.jetbrains.kotlin.gradle.targets.js.npm.includedRange
plugins {
id("com.android.application")
kotlin("android")
}
repositories {
google()
jcenter()
}
dependencies {
/*implementation(project(":shared"))
implementation("com.google.android.material:material:1.3.0")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("androidx.constraintlayout:constraintlayout:2.0.4")*/
implementation(project(":shared"))
implementation("androidx.multidex:multidex:2.0.0")
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation(files("libs/ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar"))
implementation(files("libs/pinchzoom.jar"))
implementation(files("libs/org.apache.commons.net_2.0.0.v200905272248.jar"))
implementation(files("libs/StartAppInApp-3.4.2.jar"))
implementation(files("libs/picasso-2.5.2.jar"))
// implementation("com.google.android.material:material:1.3.0")
// implementation("androidx.appcompat:appcompat:1.2.0")
//
// implementation("androidx.appcompat:appcompat:1.0.0")
// implementation("androidx.legacy:legacy-support-v13:1.0.0")
// implementation("androidx.core:core:1.0.0")
// implementation("androidx.legacy:legacy-support-v4:1.0.0")
//
//
// implementation("androidx.constraintlayout:constraintlayout:1.1.3")
// implementation("com.android.support.constraint:constraint-layout:")
// implementation("com.google.firebase:firebase-messaging:10.2.1")
// implementation("com.google.android.gms:play-services:10.2.1")
// implementation("com.google.android.gms:play-services-ads:10.2.1")
// implementation("com.google.firebase:firebase-core:10.2.1")
// implementation("com.google.firebase:firebase-auth:10.2.1")
// implementation("com.github.siyamed:android-shape-imageview:0.9.+#AndreiA")
// implementation("com.facebook.android:facebook-android-sdk:[5,6)")
// implementation("androidx.mediarouter:mediarouter:1.0.0")
// implementation("androidx.vectordrawable:vectordrawable:1.0.0")
// implementation("com.github.barteksc:android-pdf-viewer:3.1.0-beta.1")
// implementation("org.apache.commons:commons-io:1.3.2")
//
//
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.30")
}
apply { plugin("com.google.gms.google-services") }
android {
compileSdkVersion(30)
defaultConfig {
applicationId = "co.beyondsolutions.libraryapp"
minSdkVersion(17)
targetSdkVersion(30)
versionCode = 1
versionName = "1.0"
multiDexEnabled = true
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
}
All your android dependencies should be moved to the androidMain sourceSet from commonMain.
As a general rule in common you can only have dependencies that can compile to all your targets. Since your android dependencies are under the common source set it doesn't really know how to compile those to iOS
Here's an example of using the Android Arch viewmodel: https://github.com/halcyonmobile/MultiplatformPlayground/blob/master/common/src/androidMain/kotlin/com/halcyonmobile/multiplatformplayground/shared/CoroutineViewModel.kt
I am attempting to use kotlinx.serialization in a multiplatform (JVM/JS) project.
When I add #Serializable annotation to some data classes in some class in common module:
#Serializable
data class User(
val user: String
)
The build succeeds without errors, but it doesn't look like the encoders/decoders are generated.
In build/generated-src I don't see any related kotlin files which provide the encodeToString extension function, and when I try to use something like:
JSON.encodeToString(User(login = "X"))
I get an Unresolved reference error:
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline fun <reified T> StringFormat.encodeToString(value: TypeVariable(T)): String defined in kotlinx.serialization
Any help to resolve this would be appreciated. Thanks in advance.
My build.gradle.kts:
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
/* buildscript {
dependencies {
val kotlinVersion: String by System.getProperties()
classpath(kotlin("serialization", version = kotlinVersion))
}
} */
plugins {
val kotlinVersion: String by System.getProperties()
kotlin("multiplatform") version kotlinVersion
id("kotlinx-serialization") version kotlinVersion
val kvisionVersion: String by System.getProperties()
id("kvision") version kvisionVersion
}
version = "1.0.0-SNAPSHOT"
group = "tech.lorefnon"
repositories {
mavenCentral()
jcenter()
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-js-wrappers") }
maven { url = uri("https://dl.bintray.com/rjaros/kotlin") }
maven { url = uri("https://repo.spring.io/milestone") }
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") }
mavenLocal()
}
// Versions
val kotlinVersion: String by System.getProperties()
val kvisionVersion: String by System.getProperties()
val ktorVersion: String by project
val logbackVersion: String by project
val commonsCodecVersion: String by project
val webDir = file("src/frontendMain/web")
val mainClassName = "io.ktor.server.netty.EngineMain"
kotlin {
jvm("backend") {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
}
js("frontend") {
browser {
runTask {
outputFileName = "main.bundle.js"
sourceMaps = false
devServer = KotlinWebpackConfig.DevServer(
open = false,
port = 3000,
proxy = mapOf(
"/kv/*" to "http://localhost:8080",
"/login" to "http://localhost:8080",
"/logout" to "http://localhost:8080",
"/kvws/*" to mapOf("target" to "ws://localhost:8080", "ws" to true)
),
contentBase = listOf("$buildDir/processedResources/frontend/main")
)
}
webpackTask {
outputFileName = "main.bundle.js"
}
testTask {
useKarma {
useChromeHeadless()
}
}
}
binaries.executable()
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
api("pl.treksoft:kvision-server-ktor:$kvisionVersion")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1")
}
kotlin.srcDir("build/generated-src/common")
kotlin.srcDir("src/commonMain/kotlin")
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val backendMain by getting {
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation("com.auth0:java-jwt:3.11.0")
implementation("io.ktor:ktor-server-netty:$ktorVersion")
implementation("io.ktor:ktor-auth:$ktorVersion")
implementation("io.ktor:ktor-auth-jwt:$ktorVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation("commons-codec:commons-codec:$commonsCodecVersion")
implementation("org.redisson:redisson:3.14.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.4.2")
}
}
val backendTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
}
}
val frontendMain by getting {
resources.srcDir(webDir)
dependencies {
implementation("pl.treksoft:kvision:$kvisionVersion")
implementation("pl.treksoft:kvision-redux:${kvisionVersion}")
implementation("pl.treksoft:kvision-bootstrap:$kvisionVersion")
implementation("pl.treksoft:kvision-bootstrap-select:$kvisionVersion")
implementation("pl.treksoft:kvision-datacontainer:$kvisionVersion")
implementation("pl.treksoft:kvision-bootstrap-dialog:$kvisionVersion")
implementation("pl.treksoft:kvision-fontawesome:$kvisionVersion")
implementation("pl.treksoft:kvision-i18n:$kvisionVersion")
implementation(npm("redux-logger", "3.0.6"))
}
kotlin.srcDir("build/generated-src/frontend")
}
val frontendTest by getting {
dependencies {
implementation(kotlin("test-js"))
implementation("pl.treksoft:kvision-testutils:$kvisionVersion:tests")
}
}
}
}
fun getNodeJsBinaryExecutable(): String {
val nodeDir = NodeJsRootPlugin.apply(project).nodeJsSetupTaskProvider.get().destination
val isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
val nodeBinDir = if (isWindows) nodeDir else nodeDir.resolve("bin")
val command = NodeJsRootPlugin.apply(project).nodeCommand
val finalCommand = if (isWindows && command == "node") "node.exe" else command
return nodeBinDir.resolve(finalCommand).absolutePath
}
afterEvaluate {
tasks {
getByName("frontendProcessResources", Copy::class) {
dependsOn("compileKotlinFrontend")
exclude("**/*.pot")
doLast("Convert PO to JSON") {
destinationDir.walkTopDown().filter {
it.isFile && it.extension == "po"
}.forEach {
exec {
executable = getNodeJsBinaryExecutable()
args(
"$buildDir/js/node_modules/gettext.js/bin/po2json",
it.absolutePath,
"${it.parent}/${it.nameWithoutExtension}.json"
)
println("Converted ${it.name} to ${it.nameWithoutExtension}.json")
}
it.delete()
}
}
}
create("frontendArchive", Jar::class).apply {
dependsOn("frontendBrowserProductionWebpack")
group = "package"
archiveAppendix.set("frontend")
val distribution =
project.tasks.getByName("frontendBrowserProductionWebpack", KotlinWebpack::class).destinationDirectory!!
from(distribution) {
include("*.*")
}
from(webDir)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
into("/assets")
inputs.files(distribution, webDir)
outputs.file(archiveFile)
manifest {
attributes(
mapOf(
"Implementation-Title" to rootProject.name,
"Implementation-Group" to rootProject.group,
"Implementation-Version" to rootProject.version,
"Timestamp" to System.currentTimeMillis()
)
)
}
}
getByName("backendProcessResources", Copy::class) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
getByName("backendJar").group = "package"
create("jar", Jar::class).apply {
dependsOn("frontendArchive", "backendJar")
group = "package"
manifest {
attributes(
mapOf(
"Implementation-Title" to rootProject.name,
"Implementation-Group" to rootProject.group,
"Implementation-Version" to rootProject.version,
"Timestamp" to System.currentTimeMillis(),
"Main-Class" to mainClassName
)
)
}
val dependencies = configurations["backendRuntimeClasspath"].filter { it.name.endsWith(".jar") } +
project.tasks["backendJar"].outputs.files +
project.tasks["frontendArchive"].outputs.files
dependencies.forEach {
if (it.isDirectory) from(it) else from(zipTree(it))
}
exclude("META-INF/*.RSA", "META-INF/*.SF", "META-INF/*.DSA")
inputs.files(dependencies)
outputs.file(archiveFile)
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
create("backendRun", JavaExec::class) {
dependsOn("compileKotlinBackend")
group = "run"
main = mainClassName
classpath =
configurations["backendRuntimeClasspath"] + project.tasks["compileKotlinBackend"].outputs.files +
project.tasks["backendProcessResources"].outputs.files
workingDir = buildDir
}
getByName("compileKotlinBackend") {
dependsOn("compileKotlinMetadata")
}
getByName("compileKotlinFrontend") {
dependsOn("compileKotlinMetadata")
}
}
}
And gradle.properties:
javaVersion=1.8
#Plugins
systemProp.kotlinVersion=1.4.20
systemProp.serializationVersion=1.0.1
#Dependencies
systemProp.kvisionVersion=3.17.2
ktorVersion=1.4.3
commonsCodecVersion=1.10
logbackVersion=1.2.3
kotlin.mpp.stability.nowarn=true
kotlin.js.compiler=legacy
org.gradle.jvmargs=-Xmx2g
And settings.gradle.kts:
pluginManagement {
repositories {
mavenCentral()
jcenter()
maven { url = uri("https://plugins.gradle.org/m2/") }
maven { url = uri("https://dl.bintray.com/kotlin/kotlin-eap") }
maven { url = uri("https://kotlin.bintray.com/kotlinx") }
maven { url = uri("https://dl.bintray.com/rjaros/kotlin") }
mavenLocal()
}
resolutionStrategy {
eachPlugin {
when {
requested.id.id == "kotlinx-serialization" -> useModule("org.jetbrains.kotlin:kotlin-serialization:${requested.version}")
requested.id.id == "kvision" -> useModule("pl.treksoft:kvision-gradle-plugin:${requested.version}")
}
}
}
}
rootProject.name = "test"
I often face same problem. You just need to add import:
import kotlinx.serialization.encodeToString
You probably don't want to add import manually, I usually start typing encodeToStr and, wait suggestions to appear and choose encodeToString(value: T), this will add needed import.
I believe it's a bug that IDE don't give you a suggestion to import, and give us this error instead.
I’ve been struggling with this issue since days but can’t find any solution so I hope I can get any help here.
I created a Multiplatform project with Mobile Application template from IntelliJ IDEA 2020.2.1 and since project setup androidMain and AndroidTest folders are not recognised as module. This seems not to be a problem when launching androidApp task or PackForXcode as references to expect/actual definitions are resolved but idea suggestions shows anyway how androidMain reference seems to be wrong as reference seems to be resolved from parent vpayConnectLib module as per screenshot.
I use a standard android() target
When launching compileDebugAndroidTestKotlinAndroid task this error is highlighted
I tried to create new projects with different templates but androidMain and androidTest folders are not considered module since the beginning with all projects template
Is this a know bug or I am doing something wrong? Here’s root project gradle file with versions I am using
Hre's my root project gradle file:
buildscript {
repositories {
gradlePluginPortal()
jcenter()
google()
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.0")
classpath("com.android.tools.build:gradle:4.0.1")
classpath("com.squareup.sqldelight:gradle-plugin:1.4.3")
classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8")
}
}
group = "com.retailinmotion"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
and here's shared library gradle file
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("com.android.library")
id("kotlin-android-extensions")
id("com.squareup.sqldelight")
id("org.sonarqube")
jacoco
}
group = "com.retailinmotion"
version = "1.0-SNAPSHOT"
repositories {
gradlePluginPortal()
google()
jcenter()
mavenCentral()
}
sqldelight {
database("vPayConnectDatabase") {
packageName = "com.retailinmotion.vpayconnect"
sourceFolders = listOf("sqldelight")
}
}
task<JacocoReport>("jacocoTestReport") {
dependsOn("testDebugUnitTest")
reports {
xml.isEnabled = true
csv.isEnabled = false
html.isEnabled = true
}
sourceDirectories.setFrom(files(fileTree("../vPayConnectLib")))
classDirectories.setFrom(files(fileTree("build/tmp/kotlin-classes/debug")))
executionData.setFrom(file("build/jacoco/testDebugUnitTest.exec"))
}
sonarqube {
properties {
property("sonar.sourceEncoding", "UTF-8")
property("sonar.java.coveragePlugin", "jacoco")
property("sonar.sources", "src/commonMain/kotlin, src/iosMain/kotlin, src/androidMain/kotlin")
property("sonar.tests", "src/commonTest/kotlin, src/iosTest/kotlin, src/androidTest/kotlin")
property("sonar.binaries", "build/tmp/kotlin-classes/debug")
property("sonar.java.binaries", "build/tmp/kotlin-classes/debug")
property("sonar.java.test.binaries", "build/tmp/kotlin-classes/debugUnitTest")
property("sonar.junit.reportPaths", "build/test-results/testDebugUnitTest")
property("sonar.jacoco.reportPaths", "build/jacoco/testDebugUnitTest.exec")
property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml")
}
}
kotlin {
android()
iosArm64("ios") {
binaries {
framework {
baseName = "vPayConnectLib"
}
}
compilations["main"].cinterops {
//import Datecs library
val datecs by creating {
packageName ("com.retailinmotion.datecs")
defFile = file("$projectDir/src/iosMain/c_interop/Datecs.def")
includeDirs ("$projectDir/src/iosMain/c_interop/Datecs/")
}
//import Datecs Utils library
val datecsutils by creating {
packageName ("com.retailinmotion.datecsutils")
defFile = file("$projectDir/src/iosMain/c_interop/DatecsUtils.def")
includeDirs ("$projectDir/src/iosMain/c_interop/DatecsUtils/")
}
//import Magtek library
val magtek by creating {
packageName ("com.retailinmotion.magtek")
defFile = file("$projectDir/src/iosMain/c_interop/Magtek.def")
includeDirs ("$projectDir/src/iosMain/c_interop/Magtek")
}
}
}
iosX64(){
binaries {
framework {
baseName = "vPayConnectLib"
}
}
compilations["main"].cinterops {
//import Datecs library
val datecs by creating {
packageName ("com.retailinmotion.datecs")
defFile = file("$projectDir/src/iosMain/c_interop/Datecs.def")
includeDirs ("$projectDir/src/iosMain/c_interop/Datecs/")
}
//import Datecs Utils library
val datecsutils by creating {
packageName ("com.retailinmotion.datecsutils")
defFile = file("$projectDir/src/iosMain/c_interop/DatecsUtils.def")
includeDirs ("$projectDir/src/iosMain/c_interop/DatecsUtils/")
}
//import Magtek library
val magtek by creating {
packageName ("com.retailinmotion.magtek")
defFile = file("$projectDir/src/iosMain/c_interop/Magtek.def")
includeDirs ("$projectDir/src/iosMain/c_interop/Magtek")
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.squareup.sqldelight:runtime:1.4.3")
}
}
val commonTest by getting {
dependsOn(commonMain)
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
implementation("org.jetbrains.kotlin:kotlin-test-junit:1.4.10")
}
}
val androidMain by getting {
dependencies {
implementation("androidx.core:core-ktx:1.3.1")
implementation("com.squareup.sqldelight:android-driver:1.4.3")
}
}
val androidTest by getting {
dependsOn(androidMain)
}
val iosMain by getting {
dependencies {
implementation("com.squareup.sqldelight:native-driver:1.4.3")
}
}
val iosTest by getting {
dependsOn(iosMain)
}
val iosX64Main by getting {
dependsOn(iosMain)
}
val iosX64Test by getting {
dependsOn(iosTest)
}
}
tasks {
register("universalFramework", org.jetbrains.kotlin.gradle.tasks.FatFrameworkTask::class) {
val debugMode = "DEBUG"
val mode = System.getenv("CONFIGURATION") ?: debugMode
baseName = "vPayConnectLib"
val iosArm64Framework = iosArm64("ios").binaries.getFramework(mode)
val iosX64Framework = iosX64().binaries.getFramework(mode)
from(
iosArm64Framework,
iosX64Framework
)
destinationDir = buildDir.resolve("xcode-universal-framework")
group = "Universal framework"
description = "Builds a universal (fat) $mode framework"
dependsOn(iosArm64Framework.linkTask)
dependsOn(iosX64Framework.linkTask)
}
}
}
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(24)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
}
}
val packForXcode by tasks.creating(Sync::class) {
group = "build"
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets.getByName<KotlinNativeTarget>("ios").binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
val targetDir = File(buildDir, "xcode-frameworks")
from({ framework.outputDirectory })
into(targetDir)
}
tasks.getByName("build").dependsOn(packForXcode)
Any help is appreciated,
Thanks
I've created a multiplatform library that I consume in a different multiplatform project. After including the dependency I am able to use the libraries in commonMain without issue and all targets build without errors. However, intellij autocomplete does not know about my new types. I have invalidated caches and restarted the application many times, but it just cannot find this type. Anybody encountered this?
just in case, here is my build.gradle.kts:
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
buildscript {
repositories {
jcenter()
}
}
plugins {
kotlin("multiplatform") version "1.3.61"
}
repositories {
jcenter()
maven( "https://dl.bintray.com/kotlin/ktor" )
mavenCentral()
mavenLocal()
}
val ktor_version = "1.1.3"
val logback_version = "1.2.3"
kotlin {
js {
browser { }
}
jvm {
compilations.named("main") {
tasks.getByName<Copy>(processResourcesTaskName) {
dependsOn("jsBrowserWebpack")
tasks.named<KotlinWebpack>("jsBrowserWebpack") {
from(entry.name, destinationDirectory)
}
}
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(kotlin("stdlib-common"))
api("github.fatalcatharsis:constraint:1.0-SNAPSHOT")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
val jvmMain by getting {
dependencies {
implementation( kotlin("stdlib-jdk8"))
implementation( "io.ktor:ktor-server-netty:$ktor_version")
implementation( "io.ktor:ktor-html-builder:$ktor_version")
implementation( "ch.qos.logback:logback-classic:$logback_version")
}
}
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-testng"))
}
}
val jsMain by getting {
dependencies {
implementation( kotlin("stdlib-js"))
}
}
val jsTest by getting {
dependencies {
implementation( kotlin("test-js"))
}
}
}
}
tasks.register<JavaExec>("run") {
dependsOn("jvmJar")
group = "application"
main = "sample.SampleJvmKt"
val t = tasks.named<Jar>("jvmJar")
classpath(configurations.named("jvmRuntimeClasspath"), t.get() )
}