Cordova无法在Android模拟器中运行应用问题求助
解决Cordova/Ionic模拟器无限打印圆点的问题
我之前也遭遇过这个烦人的问题——明明构建成功了,命令行却一直打圆点,模拟器死活不弹出来。先看看你提供的运行日志(已经格式化好了):
$ ionic cordova emulate android Running app-scripts build: --platform android --target cordova [14:49:14] build dev started ... [14:49:14] clean started ... [14:49:14] clean finished in 3 ms [14:49:14] copy started ... [14:49:14] deeplinks started ... [14:49:14] deeplinks finished in 23 ms [14:49:14] transpile started ... [14:49:17] transpile finished in 3.65 s [14:49:17] preprocess started ... [14:49:17] preprocess finished in 1 ms [14:49:17] webpack started ... [14:49:17] copy finished in 3.79 s [14:49:23] webpack finished in 5.63 s [14:49:23] sass started ... Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning. [14:49:24] sass finished in 1.19 s [14:49:24] postprocess started ... [14:49:24] postprocess finished in 6 ms [14:49:24] lint started ... [14:49:24] build dev finished in 10.62 s > cordova emulate android Android Studio project detected ANDROID_HOME=/Users/jgallaso/Library/Developer/Xamarin/android-sdk-macosx JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home studio Subproject Path: CordovaLib Subproject Path: app publishNonDefault is deprecated and has no effect anymore. All variants are now published. The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead. at build_ebvy0tyue1c6qxpdm1duui607.run(/Users/jgallaso/Projects/aerogear/apps/ionic-showcase-template/platforms/android/app/build.gradle:143) :CordovaLib:preBuild UP-TO-DATE :CordovaLib:preDebugBuild UP-TO-DATE :CordovaLib:compileDebugAidl UP-TO-DATE :CordovaLib:compileDebugRenderscript UP-TO-DATE :CordovaLib:checkDebugManifest UP-TO-DATE :CordovaLib:generateDebugBuildConfig UP-TO-DATE :CordovaLib:prepareLintJar UP-TO-DATE :CordovaLib:generateDebugResValues UP-TO-DATE :CordovaLib:generateDebugResources UP-TO-DATE :CordovaLib:packageDebugResources UP-TO-DATE :CordovaLib:platformAttrExtractor UP-TO-DATE :CordovaLib:processDebugManifest UP-TO-DATE :CordovaLib:processDebugResources UP-TO-DATE :CordovaLib:generateDebugSources UP-TO-DATE :CordovaLib:javaPreCompileDebug UP-TO-DATE :CordovaLib:compileDebugJavaWithJavac UP-TO-DATE :CordovaLib:processDebugJavaRes NO-SOURCE :CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug UP-TO-DATE :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:compileDebugAidl UP-TO-DATE :CordovaLib:packageDebugRenderscript NO-SOURCE :app:compileDebugRenderscript UP-TO-DATE :app:checkDebugManifest UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:prepareLintJar UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:createDebugCompatibleScreenManifests UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:splitsDiscoveryTaskDebug UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:javaPreCompileDebug UP-TO-DATE :app:compileDebugJavaWithJavac UP-TO-DATE :app:compileDebugNdk NO-SOURCE :app:compileDebugSources UP-TO-DATE :CordovaLib:mergeDebugShaders UP-TO-DATE :CordovaLib:compileDebugShaders UP-TO-DATE :CordovaLib:generateDebugAssets UP-TO-DATE :CordovaLib:mergeDebugAssets UP-TO-DATE :app:mergeDebugShaders UP-TO-DATE :app:compileDebugShaders UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:transformClassesWithStackFramesFixerForDebug UP-TO-DATE :app:transformClassesWithDesugarForDebug UP-TO-DATE :app:transformClassesWithDexBuilderForDebug UP-TO-DATE :app:transformDexArchiveWithExternalLibsDexMergerForDebug UP-TO-DATE :app:transformDexArchiveWithDexMergerForDebug UP-TO-DATE :CordovaLib:compileDebugNdk NO-SOURCE :CordovaLib:mergeDebugJniLibFolders UP-TO-DATE :CordovaLib:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE :CordovaLib:transformNativeLibsWithIntermediateJniLibsForDebug UP-TO-DATE :app:mergeDebugJniLibFolders UP-TO-DATE :app:transformNativeLibsWithMergeJniLibsForDebug UP-TO-DATE :app:processDebugJavaRes NO-SOURCE :app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE :app:validateSigningDebug :app:packageDebug UP-TO-DATE :app:assembleDebug UP-TO-DATE :app:cdvBuildDebug UP-TO-DATE BUILD SUCCESSFUL in 1s 46 actionable tasks: 1 executed, 45 up-to-date [14:49:28] lint finished in 3.36 s Built the following apk(s): /Users/jgallaso/Projects/aerogear/apps/ionic-showcase-template/platforms/android/app/build/outputs/apk/debug/app-debug.apk ANDROID_HOME=/Users/jgallaso/Library/Developer/Xamarin/android-sdk-ma
从日志能看出来,APK已经成功构建完成了,但命令行卡在启动模拟器的环节,大概率是Cordova找不到模拟器、adb连接异常,或者模拟器启动超时导致的。试试下面这几个解决方案:
- 先手动启动模拟器:打开Android Studio的AVD Manager,启动你要测试的模拟器,等模拟器完全加载好之后,再重新执行
ionic cordova emulate android命令。有时候Cordova自动启动模拟器会超时,手动启动能避开这个问题。 - 检查adb连接状态:打开终端执行
adb devices,看看列表里有没有你的模拟器设备。如果没有,先重启adb服务:
然后再运行命令试试。adb kill-server adb start-server - 指定具体的模拟器设备:如果你的电脑上有多个模拟器,Cordova可能不知道该选哪个。先列出所有可用的模拟器:
然后用emulator -list-avds--target参数指定模拟器名称,比如:ionic cordova run android --emulator --target="Pixel_3a_API_30" - 清理并重新添加Android平台:有时候平台文件会有缓存或损坏,执行以下命令重置平台:
之后再重新构建运行。ionic cordova platform rm android ionic cordova platform add android - 检查环境变量配置:确认你的
ANDROID_HOME和JAVA_HOME路径正确,并且Android SDK的emulator目录已经添加到系统环境变量的PATH里——Cordova需要找到模拟器的启动命令才能正常打开它。
这些方法应该能解决你遇到的问题,我当时就是用手动启动模拟器+重置adb的方式搞定的。
内容的提问来源于stack exchange,提问作者josemigallas
相关产品推荐
相关产品推荐

