I created a library in multiplatform in latest intellij. My intellj added the outdated gradle version
settings.gradle.kts
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:4.1.2"). // How to update to latest version and what is the use of 4.1.2?
}
}
}
}
rootProject.name = "xyz"
I commented above in my code. Can someone guide how can I update my gradle version to latest and what is the use of 4.1.2 that piece of code?
I tried to remove 4.1.2 below piece of code then I am getting issue
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:4.1.2")
}
}
}
Error
Build file '/Users/vmodi/IdeaProjects/abc/build.gradle.kts' line: 1
Plugin [id: 'com.android.application'] was not found in any of the following sources:
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
build.gradle.kts
plugins {
kotlin("multiplatform") version "1.6.21"
id("com.android.application")
}
group = "com.abc"
version = "0.0.1"
repositories {
google()
mavenCentral()
}
kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
val ktorVersion = "2.0.0"
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("io.ktor:ktor-client-auth:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.3.2")
implementation("io.insert-koin:koin-core:3.2.0-beta-1")
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-client-logging-jvm:$ktorVersion")
}
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)
dependencies {
implementation("io.ktor:ktor-client-darwin:$ktorVersion")
}
}
}
}
}
android {
compileSdk = 21
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
applicationId = "com.abc.kotlinmultiplatform"
minSdk = 21
targetSdk = 31
}
#Suppress("UnstableApiUsage")
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
IntelliJ version
IntelliJ IDEA 2022.1.1 (Ultimate Edition)
Build #IU-221.5591.52, built on May 10, 2022
Licensed to Vivek Modi
For educational use only.
Runtime version: 11.0.14.1+1-b2043.45 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 11.6.5
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 16
Non-Bundled Plugins:
com.intellij.nativeDebug (221.5591.54)
org.jetbrains.kotlin-js-inspection-pack-plugin (0.0.9)
Kotlin: 221-1.6.21-release-337-IJ5591.52
After #PylypDukhov suggestion, trying to update gradle 7.0.4 I am getting this weird error
error
Failed to query the value of property 'namespace'.
Package Name not found in /Users/vmodi/IdeaProjects/abc/src/androidMain/AndroidManifest.xml, and namespace not specified. Please specify a namespace for the generated R and BuildConfig classes via android.namespace in the module's build.gradle file like so:
android {
namespace 'com.example.namespace'
}
settings.gradle.kts
pluginManagement {
repositories {
google()
gradlePluginPortal()
mavenCentral()
}
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:7.0.4")
}
}
}
}
rootProject.name = "LetsGetCheckedKotlinMultiplatform"
Added androidMain
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.abc"/>
4.1.2 is android gradle plugin version, it's not related to gradle version.
Android gradle plugin is shipped with Android Studio, if you wanna use latest version mentioned by #Egor, you have to use Android Studio.
IntelliJ IDEA supports them with a delay - the last supported version at the moment is 7.0.4, which works fine to me, the only problem you might have with it is the lack of support for the 32 target version of Android - but it's not required to upload the app and will work fine on 32 devices, also you can build release version in AS with newest plugin, and develop in IDEA, as to me it seems more performant in KMM projects.
4.1.2 is the version number. To find out what the latest version is, visit Google's Maven Repository. At the time of writing, the latest stable version is 7.2.0, so simply replace "4.1.2" with "7.2.0" and rebuild the project.
Related
I have an app coded in react native that I'm trying to upload to the google play store, but I'm running into some issues when I am trying to compile the .aab file.
Whenever i try to reload my gradle project I am greeted with 356 errors all relating to the version of kotlin used to compile.
(This is the error message:
e: E: ... \App\node_modules\react-native-gradle-plugin\src\main\kotlin\com\facebook\react\utils\TaskUtils.kt: (24, 12): Class 'kotlin.collections.ArraysKt___ArraysKt' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.8.0, expected version is 1.6.0.
The class is loaded from C:/Users/USERNAME/.gradle/wrapper/dists/gradle-8.0-rc-1-bin/di0yrgntpr7ydpxe8yasu72eh/gradle-8.0-rc-1/lib/kotlin-stdlib-1.8.0-RC2.jar!/kotlin/collections/ArraysKt___ArraysKt.class)
I have already changed my build.gradle file to include the current versions of gradle and kotlin, this is what it looks like:
buildscript {
ext.kotlin_version = '1.8.0'
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
//kotlin_version = '1.8.0' //use latest
if (System.properties['os.arch'] == "aarch64") {
// For M1 Users we need to use the NDK 24 which added support for aarch64
ndkVersion = "24.0.8215888"
} else {
// Otherwise we default to the side-by-side NDK version from AGP.
ndkVersion = "21.4.7075529"
}
}
//ext.kotlin_version = '1.7.21' //use latest
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:8.0.0-alpha11")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("com.android.tools.build:gradle:8.0.0-alpha11")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
//implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
mavenCentral {
// We don't want to fetch react-native from Maven Central as there are
// older versions over there.
content {
excludeGroup "com.facebook.react"
}
}
google()
maven { url 'https://www.jitpack.io' }
}
}
Any help would be greatly appreciated!
1、ext.kotlin_version = '1.6.0'
2、Setting the following in the project build.gradle:
change "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" version to "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0
3、Setting the following in the app build.gradle:
check 'androidx.core:core-ktx:1.6.0' version
Because attribute "$kotlin_version" has been updated
Working on an Android project that has a lot of KMM modules, so I've tough I would extract a common gradle file and simply use it from the project specific gradle files.
My common gradle file is shared-library.gradle.kts
package commons
import dependencies.Dependencies
import dependencies.TestDependencies
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.apollographql.apollo3")
id("com.android.library")
}
version = "1.0"
kotlin {
android()
iosX64()
iosArm64()
iosSimulatorArm64()
sourceSets {
val commonMain by getting {
dependencies {
implementation(Dependencies.Koin.CORE)
implementation(Dependencies.Result.KMM)
implementation(Dependencies.Coroutines.CORE)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(TestDependencies.KOIN)
}
}
val androidMain by getting
val androidTest by getting
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)
}
}
}
android {
compileSdk = BuildAndroidConfig.COMPILE_SDK_VERSION
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = BuildAndroidConfig.MIN_SDK_VERSION
targetSdk = BuildAndroidConfig.TARGET_SDK_VERSION
}
}
And then I can go use it like this from a build.gradle.kts
import dependencies.Dependencies
plugins {
id("commons.shared-library")
}
....
This all works great except the id("com.apollographql.apollo3") part, when added in the shared gradle file I get the following compilation error
org.gradle.internal.exceptions.LocationAwareException: Precompiled script plugin '/Users/calin/Playground/SharedAppSample/buildSrc/src/main/kotlin/commons/shared-library.gradle.kts' line: 1
Plugin [id: 'com.apollographql.apollo3'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
I see that the plugin is available as a gradle plugin https://plugins.gradle.org/search?term=com.apollographql.apollo3
And I have setting.gradle.kts configured like this
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
But for some reason the KMM Gradle file will ignore this configuration (maybe?)
The error says that it can't use the plugin repositories because no version is provided.
- Plugin Repositories (plugin dependency must include a version number for this source)
There are a few different ways of providing a version. Using buildSrc is my preferred way.
If shared-library.gradle.kts is a buildSrc convention plugin, then add a dependency using the plugins Maven coordinates (not the plugin ID!) in ./buildSrc/build.gradle.kts.
The Maven coordinates are available from the Gradle plugin portal
// ./buildSrc/build.gradle.kts
...
dependencies {
implementation("com.apollographql.apollo3:apollo-gradle-plugin:3.5.0")
}
Try adding the version after the apollo plugin id
plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.apollographql.apollo3").version("3.6.2")
id("com.android.library")
}
Make sure the version matches the apollo-runtime version in dependencies, if you have it.
I have just updated my current android application to use java 11, build tools 32.0.0 and
heres the android studio details im using
Android Studio Bumblebee | 2021.1.1 Beta 5
Build #AI-211.7628.21.2111.7956428, built on November 30, 2021
Runtime version: 11.0.11+0-b60-7590822 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.7
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 12
Registry: external.system.auto.import.disabled=true
Non-Bundled Plugins: org.jetbrains.kotlin (211-1.6.10-release-923-AS7442.40)
now im seeing this build warning
Warning: This version only understands SDK XML versions up to 2 but an SDK XML file of version 3 was encountered. This can happen if you use versions of Android Studio and the command-line tools that were released at different times.
my gradle resembles this:-
buildscript {
ext.kotlin_version = "1.6.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40.5'
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
my app gradle resembles this:-
android {
compileSdkVersion 31
buildToolsVersion "32.0.0"
defaultConfig {
applicationId "com.my.app"
minSdkVersion 26
targetSdkVersion 31
versionCode 3
versionName "1.2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
I searched my entire code base and cannot find any xml version other that "1.0".
is this a known feature of android studio?
how can i remove this warning?
put this line in your build.gradle(project) file
classpath "com.android.tools.build:gradle:7.1.3"
just update the emulator to a newer version (from 9th to 12th)
https://developer.android.com/studio/known-issues#ki-android-11-db-inspector
Tools-> SDK manager -> Android SDK -> (select the version you want here) -> ok -> ok -> wait for the installation to finish, and voila, you're done
also try to put a higher version of the bulid.gradle file like: classpath 'com.android.tools.build:gradle:7.1.3'
поместите эту строку в файл build.gradle(project)
classpath "com.android.tools.build:gradle:7.1.3"
Go to build.gradle
If you are using latest try to put a lower version of the bulid.gradle file like:
classpath 'com.android.tools.build:gradle:7.0.0'
then run the project. it works for me.
I have a kotlin multiplatofrm library that is included into an Android and iOS app.
In my android project include it as a composite build (MyLib). But Intellisense is not working at all for all code from in MyLib, though the whole thing compiles fine. I am using Android Studio. What could be wrong and how can I debug it?
rootProject.name='xxx'
includeBuild 'MyLib'
include ':common'
include ':app'
MyLib's build.gradle.kts looks as follows:
plugins {
kotlin("multiplatform") version "1.5.31"
kotlin("native.cocoapods") version "1.5.31"
}
repositories {
mavenCentral()
maven { setUrl("https://dl.bintray.com/kotlin/kotlinx.html/") }
}
group = "com.xxx.MyLib"
// CocoaPods requires the podspec to have a version.
version = "1.0"
kotlin {
ios()
jvm {
compilations.all {
kotlinOptions.jvmTarget = "1.8"
}
testRuns["test"].executionTask.configure {
useJUnit()
}
}
cocoapods {
ios.deploymentTarget = "11.4"
frameworkName = "MyLib"
summary = "xxx"
homepage = "xxx"
podfile = project.file("../../iOS-App/Podfile")
}
sourceSets {
commonMain {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.5.31")
implementation("com.badoo.reaktive:reaktive:1.2.0")
implementation("com.badoo.reaktive:reaktive-annotations:1.2.0")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.1")
implementation("com.russhwolf:multiplatform-settings-no-arg:0.8.1")
implementation("net.swiftzer.semver:semver:1.1.1")
}
}
}
}
tasks.withType<GenerateModuleMetadata> {
enabled = true
}
I think this is likely related to https://youtrack.jetbrains.com/issue/KTIJ-18903
I had the same issue and it drove me crazy. How can one write code nowadays without Intellisense (answer: you can't).
I tried a ton of things (all the usual and unusual stuff you do when Android Studio / IntelliJ act up). Ultimately I upgraded to Kotlin 1.6.0-RC2 (from 1.5.31) -> https://github.com/JetBrains/kotlin/releases/tag/v1.6.0-RC2.
Part of that is upgrading the Kotlin Plugin:
Another part is the Kotlin Gradle Plugin dependency:
org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0-RC2
And last but not least I had to downgrade the corouting dependency (from 1.5.2):
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC
After that everything was back to normal.
Today I updated gradle and kotlin dependencies in android studio.
The new versions are these:
kotlin_version = "1.5.10"
...
jacoco {
toolVersion = "0.8.6"
}
...
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
The test coverage report task fails with the following error:
2021-05-27T16:57:49.150+0200 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':consumerkit:testDebugUnitTestCoverage'.
2021-05-27T16:57:49.304+0200 [DEBUG] [org.codehaus.groovy.vmplugin.VMPluginFactory] Trying to create VM plugin `org.codehaus.groovy.vmplugin.v9.Java9` by checking `java.lang.Module`, but failed:
java.lang.ClassNotFoundException: java.lang.Module
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.groovy.vmplugin.VMPluginFactory.lambda$createPlugin$0(VMPluginFactory.java:61)
at java.security.AccessController.doPrivileged(Native Method)
For Kotlin 1.5 you should use JaCoCo 0.8.7 instead of 0.8.6 - see https://github.com/jacoco/jacoco/pull/1164 and the full changelog at https://www.jacoco.org/jacoco/trunk/doc/changes.html
Example snippet:
// build.gradle or build.gradle.kts
jacoco {
toolVersion = "0.8.7"
}
I already had the
jacoco {
toolVersion = "0.8.7"
}
configured but it was not working anyway, what fixed the problem was to follow this comment here
In your module build.gradle switch back to:
android {
//....
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
don't worry, it won't break anything if you were not using Java 11 language features yet, AGP 7 is still compatible with JDK 8 as target.
Then you need to force AGP to use the 0.8.7 version and not the default 0.8.3 one. In your allprojects block in the root build.gradle file, add this:
allprojects {
//... other things
// workaround to fix an auto-import of a lower Jacoco version
resolutionStrategy {
eachDependency { details ->
if ('org.jacoco' == details.requested.group) {
details.useVersion "0.8.7"
}
}
}
}
and now it should work using:
AGP 7.0.X
Kotlin 1.5.X
JDK 11 (embedded with AS)
Simply doing
jacoco {
toolVersion = "0.8.7"
}
was not enough for me. I also had to override the version that Android was using so that the androidJacocoAnt dependency also uses 0.8.7. (./gradlew app:dependencies) Simply add this to your gradle too
android.jacoco.version = "0.8.7"
It's quite old thread, but these solutions did not solve my problems completely in Android project (actually written in Java - not in Kotlin), so I will add my solutions here. Maybe someone will find it helpful.
Except of updating jacoco toolVersion to 0.8.7, I also had to update execution data in my jacoco config as follows:
project.afterEvaluate {
tasks.create(name: "${unitTestTask}Coverage", type: JacocoReport,
dependsOn: [
"$unitTestTask",
":sdk:testDebugUnitTest",
":sdk:connectedCheck"
]) {
/* all jacoco custom configuration goes here... */
executionData(fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
"outputs/code_coverage/debugAndroidTest/connected/*coverage.ec"
]))
}
}
in this configuration I had to add the following line:
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec"
which wasn't there before because file with generated report used by sonar was generated in the new location. Report is generated with gradle task testDebugUnitTestCoverage. After all of that, I'm able to generate test coverage report including connected/instrumentation Android tests and regular unit tests in java via sonar.