10_10_网站建站,产品如何做线上推广,wordpress固定链接index.php,wordpress版微信小程序当我们从Kotlin Multiplatform Wizard | JetBrains 下载ComposeMultiplatform项目时
会遇到无法正常编译/运行的情况#xff0c;一般网页和桌面是可以正常编译的#xff0c;
我这里着重解决如下问题 1:Gradle版本不兼容或者Gradle连接超时 2:JDK版本不兼容 3:Gradle依赖库连…当我们从Kotlin Multiplatform Wizard | JetBrains 下载ComposeMultiplatform项目时
会遇到无法正常编译/运行的情况一般网页和桌面是可以正常编译的
我这里着重解决如下问题 1:Gradle版本不兼容或者Gradle连接超时 2:JDK版本不兼容 3:Gradle依赖库连接超时-替换成国内镜像 4:Android环境编译 5:Android 运行到手机/模拟器 6:IOS平台后续补充 1:Gradle版本不兼容或者Gradle连接超时
The project is using an incompatible version (AGP 8.5.2) of the Android Gradle plugin. Latest supported version is AGP 8.2.0 See Android Studio AGP compatibility options. [Experimental] Enable sync with future AGP version. 该项目正在使用不兼容版本Android Gradle 插件 8.5.2 版的 Android Gradle 插件。所支持的最新版本是 Android Gradle 插件 8.2.0 版。 查看 Android Studio 与 Android Gradle 插件的兼容性选项。 [实验性] 启用与未来 Android Gradle 插件版本的同步功能。 下载最新版本IntelliJ IDEAIntelliJ IDEA 毫无疑问是软件开发者的首选 IDE。 It makes Java and Kotlin development a more productive and enjoyable experience.https://www.jetbrains.com.cn/idea/promo/?utm_sourcebaiduutm_mediumcpcutm_campaigncn-bai-br-intellij-ex-pcutm_contentintellij-coreutm_termidea
找到gradle/wrapper/gradle-wrapper.properties 文件将修改distributionUrl为合适的版本我们用由于国外很多gradle依赖链接需要翻墙我们可以用ai帮我们找合适的地址
Gradle国内镜像南京大学镜像站 下载目录https://mirrors.nju.edu.cn/gradle/我们可以找个相对合适的版本8.9 直接替换链接如图 右键复制地址 distributionUrlhttps\://services.gradle.org/distributions/gradle-8.9-bin.zip
修改为https://mirrors.nju.edu.cn/gradle/gradle-8.9-bin.ziphttps://mirrors.nju.edu.cn/gradle/gradle-8.9-bin.zip然后点击小象load图标 load Gradle Changes 同步 快捷键是(ctrlshifto) 2JDK版本不兼容 Your build is currently configured to use Java 21.0.2 and Gradle 8.5. Possible solution: - Use Java 17 as Gradle JVM: Open Gradle settings - Upgrade Gradle wrapper to 8.9 version and re-import the project 您的构建当前配置为使用 Java 21.0.2 版本和 Gradle 8.5 版本。 可能的解决方案 将 Java 17 用作 Gradle 的 Java 虚拟机JVM打开 Gradle 设置。将 Gradle 包装器升级到 8.5 版本然后重新导入项目。 打开工程结构窗口将SDK修改17
File-Project Structure-Project-SDK: 选择对应版本17 没有的话选择Edit 选择Add SDK选择本地JDK版本为什么用官方JDK因为有时候编译打包会莫名其妙的报错用官网就没问题血泪的教训
JDK17下载强烈推荐用官网的JDKhttps://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html
打开Settings输入Gradle JVM找到Build-BuildTools-Gradle-Gradle JVM将版本改成17 下载JDK1Java Archive Downloadshttps://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html下载对应的系统的版本例如 找到项目根目录local.properties文件添加本地配置属性 org.gradle.java.homeC\:\\Program Files\\Java\\jdk-173该项目正在使用不兼容版本安卓 Gradle 插件 8.5.2 版的安卓 Gradle 插件。 The project is using an incompatible version (AGP 8.5.2) of the Android Gradle plugin. Latest supported version is AGP 8.2.0 See Android Studio AGP compatibility options. [Experimental] Enable sync with future AGP version. 该项目正在使用不兼容版本安卓 Gradle 插件 8.5.2 版的安卓 Gradle 插件。所支持的最新版本是安卓 Gradle 插件 8.2.0 版。 查看安卓工作室与安卓 Gradle 插件的兼容性选项。 [实验性] 启用与未来安卓 Gradle 插件版本的同步功能。 解决办法1
[实验性的] 启用与未来 Android Gradle 插件AGP版本的同步。我们可以打开Settings勾选
Enable sync with future AGP version (Experimental)
然后再点击小象load图标 load Gradle Changes 同步 快捷键是(ctrlshifto) 解决办法2下载最新的IDEA版本
IntelliJ IDEA – 领先的 Java 和 Kotlin IDEhttps://www.jetbrains.com.cn/idea/promo/?utm_sourcebaiduutm_mediumcpcutm_campaigncn-bai-br-intellij-ex-pcutm_contentintellij-coreutm_termidea
3:Gradle依赖库连接超时-替换成国内镜像
在 Windows 系统中hosts 文件位于 C:\Windows\System32\Drivers\etc 文件夹中以记事本方式打开后在文件底部添加类似 “20.205.243.166 github.com” 的内容保存并关闭文件12.更改 DNS 服务器可以尝试更改 DNS 服务器地址为公共 DNS 服务如谷歌的 8.8.8.8 和 8.8.4.4 或Cloudflare的 1.1.1.1 和 1.0.0.1。在计算机的控制面板中找到网络和 Internet 设置点击正在使用的网络连接进入其属性设置在 IPv4 设置中选择 “使用以下 DNS 服务器地址”输入相应的 DNS 服务器地址并保存设置.
pluginManagement {repositories {// 阿里云镜像maven(https://maven.aliyun.com/release/)// 华为云镜像maven(https://mirrors.huaweicloud.com/repository/maven/)// 腾讯云镜像maven(https://mirrors.cloud.tencent.com/nexus/repository/maven-public/)maven(https://jitpack.io)maven(https://maven.aliyun.com/repository/gradle-plugin)maven(https://maven.aliyun.com/repository/google)maven(https://maven.aliyun.com/repository/central)maven(https://maven.aliyun.com/repository/public)//淘宝镜像源maven(https://registry.npmmirror.com)//腾讯云镜像源maven(https://mirrors.cloud.tencent.com/npm/)//官方 CNPM 镜像maven(https://r.cnpmjs.org)google {mavenContent {includeGroupAndSubgroups(androidx)includeGroupAndSubgroups(com.android)includeGroupAndSubgroups(com.google)}}mavenCentral()gradlePluginPortal()}
}dependencyResolutionManagement {repositories {// 阿里云镜像maven(https://maven.aliyun.com/release/)// 华为云镜像maven(https://mirrors.huaweicloud.com/repository/maven/)// 腾讯云镜像maven(https://mirrors.cloud.tencent.com/nexus/repository/maven-public/)maven(https://jitpack.io)maven(https://maven.aliyun.com/repository/gradle-plugin)maven(https://maven.aliyun.com/repository/google)maven(https://maven.aliyun.com/repository/central)maven(https://maven.aliyun.com/repository/public)//淘宝镜像源maven(https://registry.npmmirror.com)//腾讯云镜像源maven(https://mirrors.cloud.tencent.com/npm/)//官方 CNPM 镜像maven(https://r.cnpmjs.org)google {mavenContent {includeGroupAndSubgroups(androidx)includeGroupAndSubgroups(com.android)includeGroupAndSubgroups(com.google)}}mavenCentral()}
} 不管是运行Gradle的task哪个任务kotlin browser-wasmJsBrowserRun还是运行other-wasmJsRun提示的错误都可以用以上国内镜像源代替: Could not resolve com.yarnpkg:yarn:1.22.17. Required by: project : Could not resolve com.yarnpkg:yarn:1.22.17. Could not get resource https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-v1.22.17.tar.gz. Could not HEAD https://github.com/yarnpkg/yarn/releases/download/v1.22.17/yarn-v1.22.17.tar.gz. Got socket exception during request. It might be caused by SSL misconfiguration Connect to github.com:443 [github.com/20.205.243.166] failed: Connection timed out: no further information Connect to https://github.com:443 [github.com/20.205.243.166] failed: Connection timed out: no further information. If you are behind an HTTP proxy, please configure the proxy settings either in IDE or Gradle 4:Android环境编译
Could not find compile target android-34 for modules :composeApp, :shared
点击composeApp\src\androidMain\AndroidManifest.xml
会在右上角显示Install Android plugin 点击后依照提示Next就会自动下载安装然后重启IDE就可以使用了 SDK location not found. Define a valid SDK location with an ANDROID_HOME environment variable or by setting the sdk.dir path in your projects local properties file at D:\pro\ComposeMultiplatform\local.properties. 找到项目根目录local.properties文件添加本地配置属性输入你的Android SDK本地路径org.gradle.java.homeC\:\\Program Files\\Java\\jdk-17 sdk.dirD\:\\Program Files\\Android\\sdk Cannot locate tasks that match :composeApp:compileJava as task compileJava is ambiguous in project :composeApp. Candidates are: compileDebugAndroidTestJavaWithJavac, compileDebugJavaWithJavac, compileDebugUnitTestJavaWithJavac, compileReleaseJavaWithJavac, compileReleaseUnitTestJavaWithJavac. Clear Project 清除IDEA缓存 重启IDEA 打开settings配置Android SDK Manager 5:Android 运行到手机/模拟器
打开Gradle task列表点击android-sourceSets和signingReport 点击Idea的Run 运行栏打开EditConfigurations Run/Debug configurations选择android 如下图所示如果你的本地安装了android adb 现在你就可以在自己android手机上运行compose 6:IOS环境编译 后续补充
打开iosApp.xcodeproj 的projec.pb.xpbxproj 在右边会显示Install Multi-OS Engine plugin
点击安装以后 然后重启idea 在Run/Debug configuratios就可以看到 Multi-OS Engine plugin的配置不过博主没有ios和注册ios相关开发账号 后续补充