1、問題:啟動后短暫白屏。
解決方法:
(1)隱藏白屏。
工程目錄下config.xml添加以下:
<preference name="SplashMaintainAspectRatio" value="true"/> <preference name="SplashScreen" value="screen"/> <preference name="SplashScreenDelay" value="30000"/> <preference name="AutoHideSplashScreen" value="false"/> <preference name="SplashShowOnlyFirstTime" value="false"/> <preference name="FadeSplashScreen" value="false"/> <feature name="SplashScreen"> <param name="android-package" value="org.apache.cordova.splashscreen.SplashScreen"/> </feature>
我這里的app.component.ts默認如下:
export class MyApp { rootPage = TabsPage; constructor(platform: Platform) { platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. StatusBar.styleDefault(); Splashscreen.hide(); //隱藏白屏 }); } }
所以不需要再修改。
(2)加載其他圖片
在index.html加載圖片,如:
<div class="appSplash"> <div style="font-size: 30px;text-align: center">這里可以放廣告圖片</div> <img src="./assets/img/qr_code.png" alt="" </div>
參考鏈接:http://www.jianshu.com/p/102bd23625cb
2、去除啟動時轉的圈圈:config.xml加上<preference name="ShowSplashScreenSpinner" value="false"/>
3、問題:APP啟動過慢。
解決方法:打包apk時,加上--prod
以下是本人的粗略測試:
| 紅米4X | DEVICE READY FIRED AFTER | |
| debug | 10.4s | 6559ms |
| debug+prod | 4.6s | 1522ms |
release版本和debug時間差不多。
4.打包apk時自動簽名
(1)生成簽名文件:
方法1:利用Android Studio生成。參考:http://www.jianshu.com/p/dfd98ad47af1
方法2:利用jdk的KeyTool生成。
命令行:keytool -genkey -v -keystore appDemo.jks -alias test -keyalg RSA -keysize 2048 -validity 10000
appDemo和test自命名,如圖:
注:確認信息是否有誤時,要輸入“是”/“否”。
可發現目錄下有appDemo.jks文件生成。
(2)自動簽名設置:
工程目錄/platforms/android目錄新建名為release-signing.properties的文件,內容如下:
storeFile=path to keystore
keyAlias=your key alias
storePassword=your store password
keyPassword=you key password
storeFile為appDemo.jks的路徑,且windows下路徑應使用Unix下的目錄分隔符/。
(3)打包時加上--release即可生成有簽名的apk。
