跳到主要內容

在Mac上使用Ionic進行Android開發

首先要安裝Ionic
npm install -g cordova ionic 
註 npm:是Node Package Manager
註 cordova:是PhoneGap,在1.4版本以後都改名為cordova

接著安裝Android SDK(不過本人偷懶,直接安裝Android Studio)

安裝完後,就在個人資料夾更新 ~/.bash_profile 檔案
export ANDROID_HOME=/Applications/Android\ Studio.app/sdk
ANDROID_TOOLS=$ANDROID_HOME/tools/:$ANDROID_HOME/platform-tools
export PATH=$ANDROID_TOOLS:$PATH
接著安裝 Apache Ant
brew install ant
好了,環境完成接下來就來產生專案
ionic start myApp blank
產生myApp這個專案,先進到此目錄,然後新增android平台
cd myApp
ionic platform add android
接著編譯它
ionic build android
畫面上就會出現apk的位置

大功告成 :D

來源資料:

留言

這個網誌中的熱門文章

What is phpize

What is phpize According to the PHP official document : The phpize command is used to prepare the build environment for a PHP extension. If you need to build such an extension that from github or another code repositories, you can use  build tools to perform the build manually. 

AndroidManifest的小技巧

當在設定推播時,在  AndroidManifest.xml  上需要指定不同application id時該怎麼辦呢?(可能會有xxx.yyy.com.debug與xxx.yyy.com兩個版本) 有個簡單的小技巧可以實現這件事情。 <permission android:name= "${applicationId}.permission.C2D_MESSAGE" android:protectionLevel= "signature" /> <uses-permission android:name= "${applicationId}.permission.C2D_MESSAGE" /> 參考資料: Using build types in Gradle to run same app that uses ContentProvider on one device

Android 呼叫 zxing QR code scanner

今天弄個簡單的範例是關於執行QR code掃描的部分 這個方法是直接呼叫 Barcode scanner 的方法 首先在 build.gradle 的 dependencies 加上 compile 'com.google.zxing:android-integration:3.2.1' dependencies { ... compile 'com.google.zxing:android-integration:3.2.1' } 呼叫的方式則是在 Activity or Fragment 中加入執行的程式 IntentIntegrator scanner = new IntentIntegrator(mActivity); scanner. initiateScan (); 要如何得到掃描的值呢?只要 override onActivityResult 就可以囉! @Override protected void onActivityResult ( int requestCode, int resultCode, Intent data) { super . onActivityResult (requestCode, resultCode, data); IntentResult scanner = IntentIntegrator. parseActivityResult (requestCode, resultCode, data); if (scanner != null ) { String code = scanner. getContents (); // 掃描得到的字串 String format = scanner. getFormatName (); // 掃描的格式, 如 QR_CODE } } 附上參考的 java doc Class IntentIntegrator Class IntentResult