截至2024-07-23为止我的绝对是最新的,直接上步骤
(
成功条件:
1:java17(低了高了都不行测试版本20,18,11)
2:gradle-8.7(低了高了都不行测试版本8.9,8.3)
3:android studio 2024.1.1
4:VPN(必需品 Pig Farm)
)
1:环境部署
1.1:java的jdk:一定要18.0.0的不要以上的,android不兼容,链接兄弟们就自己找个吧
1.2:android studio: Android 移动应用开发者工具 – Android 开发者 | Android Developers
下载步骤直接随便找个博客跟着走就行,新版的跟旧版的差了几步但是不碍事
1.3:Cordova(新版的android studio从2024.1.1就开始不支持内置Cordova了 因为我的就是这个版本)
Gradle | Releases
直接下载二进制的8.7版本就行,8.9版本的不兼容
1.4:环境变量
_JAVA_OPTIONS:-Xmx512M
JAVA_HOME C:\Program Files\Java\jdk-17 (下面文章有解释)
path:
C:\Users\my\AppData\Local\Android\Sdk\gradle-8.7\bin(自己下载的路径)
GRADLE_HOME:C:\Users\my\AppData\Local\Android\Sdk\gradle-8.7\bin
2:创建项目
npm i -g cordova
cordova create hello com.example.hello HelloWorld
cd hello
添加编译 环境
cordova platform add ios
cordova platform add android
检查编辑环境
cordova platform ls
检查环境(安装的jdk等东西)
cordova requirements
如果按照我说的版本去安装绝对没问题,如果出了问题评论区留言
E:\work3\hello>cordova requirements
Requirements check results for android:
Java JDK: installed 1.8.0//java的jdk版本
Android SDK: installed true
Android target: installed android-35,android-34,android-32,android-29,android-28,android-22//android的版本
Gradle: installed C:\Users\my\AppData\Local\Android\Sdk\gradle-8.7\bin\gradle.BAT//Gradle的位置
3:打包
cordova build android
直接报错:
E:\work3\hello>cordova build android
Checking Java JDK and Android SDK versions
ANDROID_HOME=C:\Users\my\AppData\Local\Android\Sdk (recommended setting)
ANDROID_SDK_ROOT=C:\Users\my\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\my\AppData\Local\Android\Sdk
BUILD SUCCESSFUL in 2s
1 actionable task: 1 up-to-date
Subproject Path: CordovaLib
Subproject Path: app
Downloading https://services.gradle.org/distributions/gradle-8.7-bin.zip
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:994)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2729)
at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2641)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1824)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
at org.gradle.wrapper.Install.forceFetch(SourceFile:2)
at org.gradle.wrapper.Install$1.call(SourceFile:8)
at org.gradle.wrapper.GradleWrapperMain.main(SourceFile:67)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:505)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
... 13 more
Command failed with exit code 1: E:\work3\hello\platforms\android\tools\gradlew.bat cdvBuildDebug
E:\work3\hello>
正常现象:说发现了一个Gradle8.7版本的包,要去下载但是超时了(链接)
解决方法:一直执行这个命令直到下载开始(不需要VPN,不需要等待直接猛干就完了)
开始我也以为是VPN的问题但是发现它对VPN的消耗很少所以网的问题很小
我的第20几遍执行结果:
现在是下载下来这个包了但是它跟你的android版本不兼容了,需要去升级到34.0.0
点击ok等待下载就行
再次执行,执行的非常慢
E:\work3\hello>cordova run android
Checking Java JDK and Android SDK versions
ANDROID_HOME=C:\Users\my\AppData\Local\Android\Sdk (recommended setting)
ANDROID_SDK_ROOT=C:\Users\my\AppData\Local\Android\Sdk (DEPRECATED)
Using Android SDK: C:\Users\my\AppData\Local\Android\Sdk
BUILD SUCCESSFUL in 2s
1 actionable task: 1 up-to-date
Subproject Path: CordovaLib
Subproject Path: app
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'HelloWorld'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:8.3.0.
Required by:
project :
> No matching variant of com.android.tools.build:gradle:8.3.0 was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.7' but:
- Variant 'apiElements' declares a library, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
- Variant 'javadocElements' declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
- Variant 'runtimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
- Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
- Other compatible attribute:
- Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
- Variant 'sourcesElements' declares a component for use during runtime, and its dependencies declared externally:
- Incompatible because this component declares documentation and the consumer needed a library
- Other compatible attributes:
- Doesn't say anything about its elements (required them packaged as a jar)
- Doesn't say anything about its target Java version (required compatibility with Java 8)
- Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
> Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24.
Required by:
project :
> Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24.
> Could not get resource 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.9.24/kotlin-gradle-plugin-1.9.24.module'.
> Read timed out
* Try:
> Review the variant matching algorithm at https://docs.gradle.org/8.7/userguide/variant_attributes.html#sec:abm_algorithm.
> No matching variant errors are explained in more detail at https://docs.gradle.org/8.7/userguide/variant_model.html#sub:variant-no-match.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 6m 9s
Command failed with exit code 1: E:\work3\hello\platforms\android\tools\gradlew.bat cdvBuildDebug
E:\work3\hello>
降版本没有用报:Test of distribution url https://services.gradle.org/distributions/gradle-8.7-bin.zip failed. Please check the values set with --gradle-distribution-url and --gradle-version.
它找不到与之匹配的8.7版本(在下载一个内置版本来解决)
但这个方案尝试了不成功,先切换回来继续走8.7
上面那个报错说是:jdk版本不兼容冲突了
解决方案:安装java11
下载链接
直接运行打包(会出现长时间的下载大致内容就是它在安装很多依赖插件然后进行到哪里了等等)
不出意外又报错了:Android Gradle plugin requires Java 17 to run. You are currently using Java 11.
Android Gradle最低需要java17才能运行,ok继续升级版本
再次打包:还是报错不用管直接继续打包并且开启vpn(报错内容大概是:无法解析xx插件无法进行编译一般是由时间太长但是依赖还没有下载完整要么重复执行拼运气要么开启vpn重新下载)
最后等待所有依赖插件下载完毕
最后运行效果:
真的纯纯0到1开始搞了,搞之前我都不知道还有这个东西
版权归原作者 跟Bug双向奔赴 所有, 如有侵权,请联系我们删除。