I am trying to build a Kotlin multiplatform project to serve as a shared module for iOS and Android app. I am trying to integrate SQLDelight but I am stuck with this error while syncing Gradle. The following are the error and the build.gradle file respectively.
Error
Could not resolve com.squareup.sqldelight:native-driver:1.3.0.
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at
https://docs.gradle.org/current/userguide/declaring_repositories.html
build.gradle
buildscript {
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
classpath 'com.squareup.sqldelight:gradle-plugin:1.3.0'
}
}
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.72'
}
repositories {
mavenCentral()
jcenter()
google()
}
group 'com.example'
version '0.0.1'
apply plugin: 'com.squareup.sqldelight'
apply plugin: 'maven-publish'
def ktor_version = '1.3.2'
kotlin {
jvm()
// This is for iPhone simulator
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device
iosX64("ios") {
binaries {
framework()
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
implementation "com.squareup.sqldelight:native-driver:1.3.0"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
jvmMain {
dependencies {
implementation kotlin('stdlib')
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
implementation "com.squareup.sqldelight:sqlite-driver:1.3.0"
}
}
jvmTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
dependencies {
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
implementation "com.squareup.sqldelight:native-driver:1.3.0"
}
}
iosTest {
}
}
}
configurations {
compileClasspath
}
I removed the
implementation "com.squareup.sqldelight:native-driver:1.3.0" from commonMain's dependecies.
It worked.
Working build.gradle:
buildscript {
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
classpath 'com.squareup.sqldelight:gradle-plugin:1.3.0'
}
}
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.3.72'
}
repositories {
mavenCentral()
jcenter()
google()
}
group 'com.example'
version '0.0.1'
apply plugin: 'com.squareup.sqldelight'
apply plugin: 'maven-publish'
def ktor_version = '1.3.2'
kotlin {
jvm()
// This is for iPhone simulator
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device
iosX64("ios") {
binaries {
framework()
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
jvmMain {
dependencies {
implementation kotlin('stdlib')
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
implementation "com.squareup.sqldelight:sqlite-driver:1.3.0"
}
}
jvmTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
dependencies {
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
implementation "com.squareup.sqldelight:native-driver:1.3.0"
}
}
iosTest {
}
}
}
configurations {
compileClasspath
}
Related
When I am importing antlr, as in below
import org.antlr.v4.runtime.*
...
I get the error message saying Unresolved reference: antlr.
Not quite sure if you need this info, but my build.gradle is currently as follows:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
id 'org.jetbrains.intellij' version '1.2.1'
id 'java'
}
group 'me.ylee'
version '1.0-SNAPSHOT'
repositories {
google()
mavenLocal()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.21"
implementation "net.java.dev.jna:jna:5.11.0"
// Dependency on local binaries
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
intellij {
plugins = ['Kotlin', 'java']
}
compileKotlin {
kotlinOptions.jvmTarget = '1.8'
}
compileTestKotlin {
kotlinOptions.jvmTarget = '1.8'
}
How can I successfully import the antlr? Do I need to include antlr somewhere in the build.gradle?
Any help would be appreciated!
I have figured it out. I realized I needed to add antlr-related dependencies as shown in the revised build.gradle as shown below:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.6.10'
id 'org.jetbrains.intellij' version '1.2.1'
id 'java'
id 'antlr'
}
group 'me.ylee'
version '1.0-SNAPSHOT'
repositories {
google()
mavenLocal()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.6.0"
implementation 'org.jetbrains.kotlin:kotlin-compiler-embeddable:1.6.21'
implementation "net.java.dev.jna:jna:5.11.0"
antlr 'org.antlr:antlr4:4.10.1'
implementation 'org.antlr:antlr4-runtime:4.10.1'
// Dependency on local binaries
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
intellij {
plugins = ['Kotlin', 'java']
}
compileKotlin {
kotlinOptions.jvmTarget = '1.8'
}
compileTestKotlin {
kotlinOptions.jvmTarget = '1.8'
}
I'm using Ktor client and I'm trying to implement post requests using the serialization provided by the framework.
For some odd reason adding serialization works on the server side but not the client side.
Gradle
plugins {
application
kotlin("jvm") version "1.6.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.6.10"
}
repositories {
mavenCentral()
maven { url = uri("https://maven.pkg.jetbrains.space/public/p/ktor/eap") }
}
dependencies {
// Ktor server
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version")
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
// Ktor client
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-cio:$ktor_version")
implementation("io.ktor:ktor-client-json:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
// Arrow
implementation("io.arrow-kt:arrow-core:1.0.1")
// Tests
implementation("ch.qos.logback:logback-classic:$logback_version")
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
}
In my client side
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.plugins.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.util.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.*
#Serializable
data class TastyCredentials(val login: String, val password: String)
#OptIn(InternalAPI::class)
class TastyWorksBroker() : Broker {
companion object {
val client = HttpClient(CIO) {
install(JsonFeature) // JsonFeature is not recognized by IntelliJ
defaultRequest {
url(baseUrl)
contentType(ContentType.Application.Json)
}
}
}
override suspend fun connect(): Boolean {
val response: HttpResponse = client.post("/sessions") {
body = TastyCredentials(login, password)
}
//
}
install(JsonFeature) does not work, I also tried this:
install(ContentNegotiation) {
json()
}
Does not work either...
Any help?
I actually needed to add another dependency for the client side content negotiation
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
Solved
How to connect Kotlin Coroutines in LibGDX?
At the moment, the latest version of Kotlin coroutines: 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
build.gradle (App):
Desctop:
project(":desktop") {
apply plugin: "java-library"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
// Kotlin Coroutines / Flow
def kotlinCoroutinesFlow = "1.5.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-
core:$kotlinCoroutinesFlow"
}
}
Core:
project(":core") {
apply plugin: "java-library"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
// Kotlin Coroutines / Flow
def kotlinCoroutinesFlow = "1.5.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesFlow"
}
}
Android:
project(":android") {
apply plugin: "com.android.application"
configurations { natives }
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
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"
// Kotlin Coroutines / Flow
def kotlinCoroutinesFlow = "1.5.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesFlow"
}
}
iOS:
project(":ios") {
apply plugin: "java-library"
apply plugin: "robovm"
dependencies {
implementation project(":core")
api "com.mobidevelop.robovm:robovm-rt:$roboVMVersion"
api "com.mobidevelop.robovm:robovm-cocoatouch:$roboVMVersion"
api "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
// Kotlin Coroutines / Flow
def kotlinCoroutinesFlow = "1.5.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinCoroutinesFlow"
}
}
I am using android studio 3.0, and i downloaded a project from http://www.androidbootstrap.com and when i import that project it gives me error as "Gradle sync failed: CreateProcess error=2, The system cannot find the file specified".
This type of question and respective answers already posted but non of them solve my problem due to this reason i am posting this question please understand this.
the Gradle Script>build.gradle is:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
allprojects {
repositories {
jcenter()
}
}
and app\build.gradle is:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath 'io.fabric.tools:gradle:1.19.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
repositories {
maven { url 'https://github.com/donnfelker/mvn-repo/raw/master/' }
mavenLocal()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
def computeVersionCode() {
if (System.env.BUILD_NUMBER) { // Check if there is a system build number.
return "$System.env.BUILD_NUMBER".toInteger()
} else if (System.env.CIRCLE_BUILD_NUM) { // Check to see if this is built on circle CI
return "$System.env.CIRCLE_BUILD_NUM".toInteger()
} else {
return 1 // if none is found, default to 1.
}
}
def computeVersionName() {
return "1." + computeVersionCode()
}
//noinspection GroovyUnusedAssignment
def gitSha = 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim()
android {
compileSdkVersion 23
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 18
targetSdkVersion 23
versionCode computeVersionCode()
versionName computeVersionName()
// Enable this if you want to use Build.GIT_SHA in your code somewhere.
// This will give you the last GIT_SHA that was committed
// buildConfigField "String", "GIT_SHA", "\"${gitSha}\""
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
// Exclude file to avoid
// Error: Duplicate files during packaging of APK
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'LICENSE.txt'
}
signingConfigs {
// Uncomment and set values and then this will work
// release {
// storeFile file(System.getenv('ANDROID_KEYSTORE_PATH'))
// storePassword System.getenv('ANDROID_STORE_PASS')
// keyAlias System.getenv('ANDROID_KEY_ALIAS')
// keyPassword System.getenv('ANDROID_KEY_PASS')
// }
}
lintOptions {
abortOnError false
}
buildTypes {
debug {
applicationIdSuffix '.debug'
minifyEnabled false
// zipAlign false // this is default for debug
}
release {
// minifyEnabled true
// proguardFile '..\proguard.cfg'
// signingConfig signingConfigs.release
// zipAlign true // this is default for release
// testPackageName 'example.com.tests'
// testInstrumentationRunner 'android.test.InstrumentationTestRunner' // this is the default
}
}
}
dependencies {
// Android Support Libs
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.code.gson:gson:2.3'
// Dependency Injection
compile 'com.google.dagger:dagger:2.0'
// View Injection
compile 'com.jakewharton:butterknife:7.0.1'
// Logging
compile 'com.jakewharton.timber:timber:3.0.2'
compile 'com.actionbarsherlock:viewpagerindicator:2.4.1'
compile 'com.nineoldandroids:library:2.4.0'
// Event Bus
compile 'com.squareup:otto:1.3.5'
// Image Loading
compile 'com.squareup.picasso:picasso:1.1.1'
// HTTP
compile 'com.squareup.retrofit:retrofit:1.5.1'
// Fabric/Crashlytics
compile('com.crashlytics.sdk.android:crashlytics:2.2.3#aar') {
transitive = true
}
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.4'
// Set this dependency to use JUnit 4 rules
androidTestCompile 'com.android.support.test:rules:0.4'
// Set this dependency to build and run Espresso tests
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
// Contrib
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
// http://stackoverflow.com/a/30931887/5210
exclude group: 'com.android.support', module: 'appcompat'
exclude group: 'com.android.support', module: 'support-v4'
exclude module: 'recyclerview-v7'
}
// Set this dependency to build and run UI Automator tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
apt 'com.google.dagger:dagger-compiler:2.0'
provided 'javax.annotation:jsr250-api:1.0'
}
Try instead proxy settings of your project.
From my testing, both
task taskA {
doFirst {
println("$name first")
}
doLast {
println("$name second")
}
}
and
task taskB {
doLast {
println("$name first")
println("$name second")
}
}
executes in the same order.
What is the significance of having a separate doFirst block? Can something else happen between the execution of doFirst and doLast?
I have gone through the gradle docs section on tasks. The examples also seem to use just doLast