使用ionic serve或模拟器在浏览器中测试您的应用程序在您的应用程序开发过程中快速,轻松和方便,但最终您将不得不在设备上进行测试。

它不仅是准确测试应用程序行为和执行方式的唯一方式,而且许多Ionic Native插件只有在实际硬件上运行时才能正常工作。

Android Devices

部署到Android设备是一个相当简单的过程。如果您有一个可行的Android开发环境,则可以开始使用了。

Requirements

  • Java JDK
  • Android Studio
  • Updated Android SDK tools, platform and component dependencies. Available through Android Studio’s SDK Manager

Production Builds

ionic cordova run android --prod --release
# or
ionic cordova build android --prod --release

(Mac上)问题: ionic 2 - Error Could not find an installed version of Gradle either in Android Studio 解决方法: brew install gradle (速度慢需要挂代理)

此命令会将 minify your app’s code as Ionic’s source,并从APK中删除任何调试功能。将应用程序部署到Google Play商店时通常会使用此功能。

...
Subproject Path: app
Could not unzip /Users/tyrad/.gradle/wrapper/dists/gradle-4.1-all/bzyivzo6n839fup2jbap0tjew/gradle-4.1-all.zip to /Users/tyrad/.gradle/wrapper/dists/gradle-4.1-all/bzyivzo6n839fup2jbap0tjew.
Reason: error in opening zip file
Exception in thread "main" 
java.util.zip.ZipException: error in opening zip file
....

解决方法删除rm gradle-4.1-all.zip

Sign Android APK

iOS

ionic cordova build ios --prod

发现编译报错如下,但是不影响platforms/ios下的iOS项目文件的正常使用。

 typescript error 
            Type MyviewsPage in /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/pages/myviews/myviews.ts is part of 
            the declarations of 2 modules: AppModule in 
            /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/app/app.module.ts and MyviewsPageModule in 
            /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/pages/myviews/myviews.module.ts! Please consider moving 
            MyviewsPage in /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/pages/myviews/myviews.ts to a higher 
            module that imports AppModule in /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/app/app.module.ts and 
            MyviewsPageModule in /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/pages/myviews/myviews.module.ts. 
            You can also create a new NgModule that exports and includes MyviewsPage in 
            /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/pages/myviews/myviews.ts then import that NgModule in 
            AppModule in /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/app/app.module.ts and MyviewsPageModule in 
            /Users/tyrad/Desktop/angular5/ionic/appTutorial/src/pages/myviews/myviews.module.ts. 

app.module.ts中移除了相应的引用,问题解决。