我使用ionic创建了一个应用程序:
ionic start MyFirstApp blank
cd MyFirstApp
ionic serve
ionic platform add android
ionic build android
ionic emulate android
除了模拟器步骤外,一切都很成功。模拟器启动,但我得到“不幸的是,MyFirstApp已停止”。一切都是全新的,开箱即用,无需更改代码。
下一步是什么?如何调试出错的地方?
修改
这是我拨打ionic build android
时显示的输出:
C:\Users\Colin\Documents\Ionic\MyFirstApp>ionic build android
add to body class: platform-android
Running command: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\cordova\build.bat
Buildfile: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\build.xml
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 23.0.2
[checkenv] Installed at C:\Program Files\Eclipse\adt-bundle-windows-x86_64-20140702\sdk
-setup:
[echo] Project Name: MyFirstApp
[gettype] Project Type: Application
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 20.0.0
[echo] Resolving Build Target for MyFirstApp...
[gettarget] Project Target: Android 4.4.2
[gettarget] API level: 19
[echo] ----------
[echo] Creating output directories if needed...
[echo] ----------
[echo] Resolving Dependencies for MyFirstApp...
[dependency] Library dependencies:
[dependency]
[dependency] ------------------
[dependency] Ordered libraries:
[dependency]
[dependency] ------------------
[echo] ----------
[echo] Building Libraries with 'debug'...
nodeps:
-set-mode-check:
-set-debug-files:
-check-env:
[checkenv] Android SDK Tools Revision 23.0.2
[checkenv] Installed at C:\Program Files\Eclipse\adt-bundle-windows-x86_64-20140702\sdk
-setup:
[echo] Project Name: MyFirstApp
[gettype] Project Type: Android Library
-set-debug-mode:
-debug-obfuscation-check:
-pre-build:
-build-setup:
[getbuildtools] Using latest Build Tools: 20.0.0
[echo] Resolving Build Target for MyFirstApp...
[gettarget] Project Target: Android 4.4.2
[gettarget] API level: 19
[echo] ----------
[echo] Creating output directories if needed...
[echo] ----------
[echo] Resolving Dependencies for MyFirstApp...
[dependency] Library dependencies:
[dependency] No Libraries
[dependency]
[dependency] ------------------
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[echo] ----------
[echo] Handling Resources...
[aapt] Found new input file
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.
-pre-compile:
-compile:
[echo] Creating library output jar file...
-post-compile:
-obfuscate:
-dex:
[echo] Library project: do not convert bytecode...
-crunch:
[crunch] Crunching PNG Files in source dir: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\res
[crunch] To destination dir: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build\res
[crunch] Crunched 0 PNG files to update cache
-package-resources:
[echo] Library project: do not package resources...
-package:
[echo] Library project: do not package apk...
-post-package:
-do-debug:
[echo] Library project: do not create apk...
[propertyfile] Updating property file: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build\build.prop
[propertyfile] Updating property file: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build\build.prop
[propertyfile] Updating property file: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build\build.prop
[propertyfile] Updating property file: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build\build.prop
-post-build:
debug:
-code-gen:
[mergemanifest] Found Deleted Target File
[mergemanifest] Merging AndroidManifest files into one.
[mergemanifest] Manifest merger disabled. Using project manifest only.
[echo] Handling aidl files...
[aidl] No AIDL files to compile.
[echo] ----------
[echo] Handling RenderScript files...
[echo] ----------
[echo] Handling Resources...
[aapt] Found Deleted Target File
[aapt] Generating resource IDs...
[echo] ----------
[echo] Handling BuildConfig class...
[buildconfig] No need to generate new BuildConfig.
-pre-compile:
[echo] Set jars path to: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build\classes.jar
-compile:
[javac] Compiling 2 source files to C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\classes
-post-compile:
-obfuscate:
-dex:
[dex] input: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\classes
[dex] input: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build\classes.jar
[dex] Using Pre-Dexed classes-3a52ec06bbf9dc987d551c9695e3393a.jar <- C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build\classes.jar
[dex] Found Deleted Target File
[dex] Converting compiled files and external libraries into C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\classes.dex...
[dx] Merged dex A (12 defs/8.7KiB) with dex B (209 defs/317.1KiB). Result is 221 defs/396.2KiB. Took 0.2s
-crunch:
[crunch] Crunching PNG Files in source dir: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\res
[crunch] To destination dir: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\res
[crunch] Crunched 0 PNG files to update cache
-package-resources:
[aapt] Found Deleted Target File
[aapt] Creating full resource package...
-package:
[apkbuilder] Found Deleted Target File
[apkbuilder] Creating MyFirstApp-debug-unaligned.apk and signing it with a debug key...
-post-package:
-do-debug:
[zipalign] Running zip align on final apk...
[echo] Debug Package: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\MyFirstApp-debug.apk
[propertyfile] Updating property file: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\build.prop
[propertyfile] Updating property file: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\build.prop
[propertyfile] Updating property file: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\build.prop
[propertyfile] Updating property file: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\build.prop
-post-build:
[move] Moving 1 file to C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build
[move] Moving 1 file to C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\CordovaLib\ant-build
debug:
BUILD SUCCESSFUL
Total time: 4 seconds
Using apk: C:\Users\Colin\Documents\Ionic\MyFirstApp\platforms\android\ant-build\MyFirstApp-debug-unaligned.apk
编辑2 这是android list avd
Available Android Virtual Devices:
Name: Nexus7
Device: Nexus 7 (Google)
Path: C:\Users\Colin\.android\avd\Nexus7.avd
Target: Android 4.4W (API level 20)
Tag/ABI: android-wear/armeabi-v7a
Skin: WVGA800
答案 0 :(得分:8)
在我看来,更简单/更好的解决方案是在chrome上使用chrome:// inspect工具。
使用
在Android上启动应用离子运行android
打开Chrome并转到:chrome:// inspect - 这将列出您已连接的设备。
使用chrome dev工具检查应用程序,就像检查任何其他网页一样。
答案 1 :(得分:4)
请确保为模拟器创建了正确的avd配置。
输入android list avd
并查看输出。什么是第一个在那里列出的avd?如果它显示较旧的API级别(例如:7)
API level 9 and higher is required, API level 15和高优先级。您不能使用API 20 Android Wear AVD,因为它仅用于测试磨损设备。
您可以使用android delete avd -n Name
删除现有的广告素材(用您的Name
替换)。
使用android create avd --name test15 --target android-15 --abi x86
确保android list avd
显示您的avd是第一个列出的。
我按照相同的步骤操作,我使用的是Windows,我的ionic build android
输出与您的相似;我能够ionic emulate android
使用API-15,请参阅下面的内容: