我在最新的 intellij 中創建了一個多平臺庫。我的 intellj 添加了過時的 gradle 版本 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"
我在上面的代碼中評論過。有人可以指導我如何將我的 gradle 版本更新到最新版本以及 4.1.2那段代碼的用途是什么?
我試圖洗掉一段代碼下面的 4.1.2 然后我遇到了問題
resolutionStrategy {
eachPlugin {
if (requested.id.namespace == "com.android") {
useModule("com.android.tools.build:gradle:4.1.2")
}
}
}
錯誤
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
構建.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 版本
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
在@PylypDukhov 建議之后,嘗試更新gradle 7.0.4我收到了這個奇怪的錯誤
錯誤
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"
添加了 androidMain
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.abc"/>
uj5u.com熱心網友回復:
4.1.2是android gradle 插件版本,與gradle 版本無關。
Android gradle 插件隨Android Studio一起提供,如果你想使用@Egor 提到的最新版本,你必須使用Android Studio。
IntelliJ IDEA延遲支持它們 - 目前最后支持的版本是7.0.4,這對我來說很好,你可能遇到的唯一問題是缺乏對Android 32目標版本的支持 - 但事實并非如此需要上傳應用程式并且可以在 32 臺設備上正常作業,您也可以使用最新插件在AS中構建發布版本,并在IDEA中開發,因為對我來說它似乎在 KMM 專案中性能更高。
uj5u.com熱心網友回復:
4.1.2 是版本號。要了解最新版本是什么,請訪問Google 的 Maven 存盤庫。在撰寫本文時,最新的穩定版本是 7.2.0,因此只需將“4.1.2”替換為“7.2.0”并重建專案即可。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/478347.html
