0


Cordova从0到1开始打包APP

截至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:创建项目

  1. npm i -g cordova
  1. cordova create hello com.example.hello HelloWorld
  1. cd hello

添加编译 环境

  1. cordova platform add ios
  2. cordova platform add android

检查编辑环境

  1. cordova platform ls

检查环境(安装的jdk等东西)

  1. cordova requirements

如果按照我说的版本去安装绝对没问题,如果出了问题评论区留言

  1. E:\work3\hello>cordova requirements
  2. Requirements check results for android:
  3. Java JDK: installed 1.8.0//java的jdk版本
  4. Android SDK: installed true
  5. Android target: installed android-35,android-34,android-32,android-29,android-28,android-22//android的版本
  6. Gradle: installed C:\Users\my\AppData\Local\Android\Sdk\gradle-8.7\bin\gradle.BAT//Gradle的位置

3:打包

  1. cordova build android

直接报错:

  1. E:\work3\hello>cordova build android
  2. Checking Java JDK and Android SDK versions
  3. ANDROID_HOME=C:\Users\my\AppData\Local\Android\Sdk (recommended setting)
  4. ANDROID_SDK_ROOT=C:\Users\my\AppData\Local\Android\Sdk (DEPRECATED)
  5. Using Android SDK: C:\Users\my\AppData\Local\Android\Sdk
  6. BUILD SUCCESSFUL in 2s
  7. 1 actionable task: 1 up-to-date
  8. Subproject Path: CordovaLib
  9. Subproject Path: app
  10. Downloading https://services.gradle.org/distributions/gradle-8.7-bin.zip
  11. Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
  12. at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:994)
  13. at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1367)
  14. at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1395)
  15. at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1379)
  16. at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
  17. at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
  18. at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2729)
  19. at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2641)
  20. at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1824)
  21. at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1492)
  22. at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:263)
  23. at org.gradle.wrapper.Install.forceFetch(SourceFile:2)
  24. at org.gradle.wrapper.Install$1.call(SourceFile:8)
  25. at org.gradle.wrapper.GradleWrapperMain.main(SourceFile:67)
  26. Caused by: java.io.EOFException: SSL peer shut down incorrectly
  27. at sun.security.ssl.InputRecord.read(InputRecord.java:505)
  28. at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
  29. ... 13 more
  30. Command failed with exit code 1: E:\work3\hello\platforms\android\tools\gradlew.bat cdvBuildDebug
  31. E:\work3\hello>

正常现象:说发现了一个Gradle8.7版本的包,要去下载但是超时了(链接)

解决方法:一直执行这个命令直到下载开始(不需要VPN,不需要等待直接猛干就完了)

开始我也以为是VPN的问题但是发现它对VPN的消耗很少所以网的问题很小

我的第20几遍执行结果:

现在是下载下来这个包了但是它跟你的android版本不兼容了,需要去升级到34.0.0

点击ok等待下载就行

再次执行,执行的非常慢

  1. E:\work3\hello>cordova run android
  2. Checking Java JDK and Android SDK versions
  3. ANDROID_HOME=C:\Users\my\AppData\Local\Android\Sdk (recommended setting)
  4. ANDROID_SDK_ROOT=C:\Users\my\AppData\Local\Android\Sdk (DEPRECATED)
  5. Using Android SDK: C:\Users\my\AppData\Local\Android\Sdk
  6. BUILD SUCCESSFUL in 2s
  7. 1 actionable task: 1 up-to-date
  8. Subproject Path: CordovaLib
  9. Subproject Path: app
  10. FAILURE: Build failed with an exception.
  11. * What went wrong:
  12. A problem occurred configuring root project 'HelloWorld'.
  13. > Could not resolve all artifacts for configuration ':classpath'.
  14. > Could not resolve com.android.tools.build:gradle:8.3.0.
  15. Required by:
  16. project :
  17. > 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:
  18. - Variant 'apiElements' declares a library, packaged as a jar, and its dependencies declared externally:
  19. - 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
  20. - Other compatible attribute:
  21. - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  22. - Variant 'javadocElements' declares a component for use during runtime, and its dependencies declared externally:
  23. - Incompatible because this component declares documentation and the consumer needed a library
  24. - Other compatible attributes:
  25. - Doesn't say anything about its elements (required them packaged as a jar)
  26. - Doesn't say anything about its target Java version (required compatibility with Java 8)
  27. - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  28. - Variant 'runtimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
  29. - Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
  30. - Other compatible attribute:
  31. - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  32. - Variant 'sourcesElements' declares a component for use during runtime, and its dependencies declared externally:
  33. - Incompatible because this component declares documentation and the consumer needed a library
  34. - Other compatible attributes:
  35. - Doesn't say anything about its elements (required them packaged as a jar)
  36. - Doesn't say anything about its target Java version (required compatibility with Java 8)
  37. - Doesn't say anything about org.gradle.plugin.api-version (required '8.7')
  38. > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24.
  39. Required by:
  40. project :
  41. > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24.
  42. > 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'.
  43. > Read timed out
  44. * Try:
  45. > Review the variant matching algorithm at https://docs.gradle.org/8.7/userguide/variant_attributes.html#sec:abm_algorithm.
  46. > No matching variant errors are explained in more detail at https://docs.gradle.org/8.7/userguide/variant_model.html#sub:variant-no-match.
  47. > Run with --stacktrace option to get the stack trace.
  48. > Run with --info or --debug option to get more log output.
  49. > Run with --scan to get full insights.
  50. > Get more help at https://help.gradle.org.
  51. BUILD FAILED in 6m 9s
  52. Command failed with exit code 1: E:\work3\hello\platforms\android\tools\gradlew.bat cdvBuildDebug
  53. 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开始搞了,搞之前我都不知道还有这个东西

标签: 前端 android cordov

本文转载自: https://blog.csdn.net/m0_72196169/article/details/140634980
版权归原作者 跟Bug双向奔赴 所有, 如有侵权,请联系我们删除。

“Cordova从0到1开始打包APP”的评论:

还没有评论