由于gradle在国外,所以访问起来特么慢,经常会超时。
在编译app的时候又会用到gradle,所以直接把gradle-6.5-all.zip下载后放到系统里面:
C:\Users\wbs\.gradle\wrapper\dists\gradle-6.5-all\2oz4ud9k3tuxjg84bbf55q0tn(可能不同)
即手动下载gradle包,将下载下来的压缩包放到:C:\Users\***\.gradle\wrapper\dists\gradle-自己版本-all\xxx目录下,最后两级根据个人情况修改其中***为用户名
然后再次编译就成功了
ionic cordova emulate android
> cordova.cmd build android --emulator Checking Java JDK and Android SDK versions ANDROID_SDK_ROOT=undefined (recommended setting) ANDROID_HOME=undefined (DEPRECATED) Using Android SDK: D:\android-sdk-windows <-------------> 0% CONFIGURING [1m 45s] > root project > Resolve files of :classpath > kotlin-reflect-1.3.72.jar > 769 KB/2.74 MB downloaded > root project > Resolve files of :classpath > fastutil-7.2.0.jar > 192 KB/16.51 MB downloaded > root project > Resolve files of :classpath > kotlin-compiler-embeddable-1.3.50.jar > 2.74 MB/34.92 MB downloaded > root project > Resolve files of :classpath > kotlin-gradle-plugin-1.3.50.jar > 1.09 MB/2.91 MB downloaded > root project > Resolve files of :classpath > kotlin-stdlib-1.3.72.jar > 362 KB/1.32 MB downloaded > root project > Resolve files of :classpath > gradle-4.0.0.jar > 87 KB/5.01 MB downloaded > root project > Resolve files of :classpath > bundletool-0.13.2.jar > 22.25 MB/30.83 MB downloaded > root project > Resolve files of :classpath > guava-28.1-jre.jar > 809 KB/2.63 MB downloaded ......
编译更换国内镜像方式:
找到build.gradle文件,修改里面的镜像地址,
D:\myApp\platforms\android\build.gradle
修改如下:
buildscript { ext.kotlin_version = '1.3.50' repositories { //google() //jcenter() //mavenCenral() maven{ url 'https://maven.aliyun.com/repository/google' } maven{ url 'https://maven.aliyun.com/repository/jcenter' } maven{url 'http://maven.aliyun.com/nexus/content/groups/public'} } dependencies { classpath 'com.android.tools.build:gradle:4.0.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { //google() // jcenter() //mavenCenral() maven{ url 'https://maven.aliyun.com/repository/google' } maven{ url 'https://maven.aliyun.com/repository/jcenter' } maven{url 'http://maven.aliyun.com/nexus/content/groups/public'} } //This replaces project.properties w.r.t. build settings project.ext { defaultBuildToolsVersion="29.0.2" //String defaultMinSdkVersion=22 //Integer - Minimum requirement is Android 5.1 defaultTargetSdkVersion=29 //Integer - We ALWAYS target the latest by default defaultCompileSdkVersion=29 //Integer - We ALWAYS compile with the latest by default } }
这样解决了超时问题
这样成功编译apk
> cordova.cmd build android --emulator Checking Java JDK and Android SDK versions ANDROID_SDK_ROOT=undefined (recommended setting) ANDROID_HOME=undefined (DEPRECATED) Using Android SDK: D:\android-sdk-windows Subproject Path: CordovaLib Subproject Path: app > Task :app:compileDebugJavaWithJavac 注: 某些输入文件使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.5/userguide/command_line_interface.html#sec:command_line_warnings BUILD SUCCESSFUL in 6m 0s 40 actionable tasks: 40 executed Built the following apk(s): D:\tools\www\wei1.top\xiaov\apps\myApp\platforms\android\app\build\outputs\apk\debug\app-debug.apk > native-run.cmd android --app platforms\android\app\build\outputs\apk\debug\app-debug.apk --virtual [native-run] ERR_SDK_NOT_FOUND: No valid Android SDK root found. [native-run] [native-run] More details for this error may be available online: [native-run] [native-run] https://github.com/ionic-team/native-run/wiki/Android-Errors [ERROR] An error occurred while running subprocess native-run. native-run.cmd android --app platforms\android\app\build\outputs\apk\debug\app-d... exited with exit code 1. Re-running this command with the --verbose flag may provide more information.
上面那个ERROR是模拟器sdk没有找到,不管了,手机安装就行了。