第十一堂 學習編譯與上架

Post on 07-Aug-2015

116 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

第十一堂:學習編譯與上架

柯力中 Jason Ko

Jason 的 Android 快樂應用程式學習班

課程內容• 編譯輸出 APK 檔

• 上架到 Play Store

• 關於 Gradle

Jason 的 Android 快樂應用程式學習班

編譯輸出 APK 檔

Jason 的 Android 快樂應用程式學習班

輸出 APK 步驟一

Jason 的 Android 快樂應用程式學習班

• 點擊 Build, 接著 Generate Signed APK

輸出 APK 步驟二

Jason 的 Android 快樂應用程式學習班

• 先產生一個 Key store, 點 Create new (keystore 是用來儲存一些認證資訊的 , play store 商店會以此資訊來辨別有沒有權限更新APP)

輸出 APK 步驟二

Jason 的 Android 快樂應用程式學習班

• 先產生一個 Key store, 點 Create new (keystore 是用來儲存一些認證資訊的 , play store 商店會以此資訊來辨別有沒有權限更新APP)

輸出 APK 步驟三

Jason 的 Android 快樂應用程式學習班

• 上方是 key store 檔案的密碼 , 下方是認證資訊

輸出 APK 步驟四

Jason 的 Android 快樂應用程式學習班

• 產生 key store 後 , 會回到一開始的畫面並填妥資料

輸出 APK 步驟五

Jason 的 Android 快樂應用程式學習班

• 選擇 APK 輸出位置 , 以及 Build Type, 按下 Finish 即可輸出

輸出 APK 步驟六

Jason 的 Android 快樂應用程式學習班

• 在位置資料夾可找到輸出的 apk1. .jks 是 keystore 的檔案 , 務必妥善保存 , 之後產生 apk 更新檔時會再用到2. .apk 就是我們要上架到 play store 的 APP 安裝檔

上架到 play store

Jason 的 Android 快樂應用程式學習班

上架到 play store 步驟一

Jason 的 Android 快樂應用程式學習班

• 搜索 google play developer console, 並點入

p.s 如沒有開發者帳號 , google 會要求買一個 , 約 NT$ 750

上架到 play store 步驟二

Jason 的 Android 快樂應用程式學習班

• 點選新增應用程式

上架到 play store 步驟三

Jason 的 Android 快樂應用程式學習班

• 上傳 APK

上架到 play store 步驟四

Jason 的 Android 快樂應用程式學習班

• 填寫商店資料 , 有打 * 就是必須填

上架到 play store 步驟五

Jason 的 Android 快樂應用程式學習班

• 填寫其他資訊

上架到 play store 步驟六

Jason 的 Android 快樂應用程式學習班

• 發佈應用程式

• Title 會影響搜索的排名 (SEO)

• 內容關鍵字會影響搜不搜得到

Jason 的 Android 快樂應用程式學習班

上架須知

關於 Gradle

Jason 的 Android 快樂應用程式學習班

什麼是 GRADLE• Automation Tool 自動化建置工具

• 可以做的事 : compile, test, package, deploy (ship), project dependencies…

• Gradle 是使用 Groovy 語言的腳本語言 ( 腳本語言是為了縮短 edit, compile, link, run 而開發的語言 , 一行行地運行 , 像 shell 一樣 )

為什麼是 GROOVY

• 語言精簡 ( Less verbose )

• 支援多種程式語言 ( Very flexible)

• DSL ( Domain Specific Language)

=> 很優 , 而且不用學 ! 我們只要會叫 Gradle 跑就好了 !

DSL 舉例Java 的 Swing GUI Toolkit

Groovy 的 SwingBuilder

取自: http://www.codedata.com.tw/java/groovy-tutorial-1-understanding-groovy/

基本指令• gradle -q tasks => 列出 tasks, -q 是 in

quiet mode

• gradle -q help => look help guide

• gradle properties => 列出此 project 的 properties

BUILD.GRADLE• build. gradle 是所有指令的集合檔 , 是學習的

重點 ~

• ex.

run by => gradle compileTask

JAVA PLUGIN• 使用 plugin => apply plugin: <plugin-

name>

• 使用 java plugin => apply plugin: “Java”

Java 有 4 種不同的 Configuration

• compile, runtime, testCompile, testRuntime

• 在這 4 種不同的 configuration, 我們可以指定不同的 dependencies

• for Android Project 大部份我們只用到 compile

Example 1

Marven Central 是遠端的資料庫 , Gradle 會到此資料庫下載 ,

我們還需指定所需 library 的 group, name, version

Example 2

Multiple Projects

settings.gradle

build.gradle

settings.gradle:

build.gradle:

ex. Project 的 build.gradle

Project 的 build.gradle 分拆

看看 Android Studio 內的 Project, 是不是長這樣 !

p.s 為了不搞混 , 我們稱 HelloCloudEndpoints

為 project,api, app 為 module

此例子中 , app 為手機程式 module, api 為 google

cloud module

Android Studio 下的 gradle

執行檔是 gradlew

Project 的 gradle 版本

gradle-wrapper.properties

在 project 檔案夾下

改這裡即可使用不同的 gradle 版本

記得 sync project with gradle

有修改 gradle 的 file, 就要 sync

App 的 build.gradle 1. apply “com.android.application” 的 plugin

2. 因為 apply 上面這個 plugin 所以有 android{} 這個 configuration element 可以用

會覆蓋 AndroidManifiest.xml

Compile SDK version

決定如何打包 APP, 有 release 跟 debug 兩種可用

App 的 build.gradle

include Libs 裡面的 jar 檔

jar 檔放這裡面

product flavors• 同一個專案 , 輸出不同的 APP ex. Demo version,

Full version• 在 gradle.build 裡的 Android {} 添加

productFlavors{}

product flavors

將不同的檔案放在各自的資

料夾裡

值得學的• 使用 Android Studio + App Engine + Cloud Endpoints

=> 1. 節省寫 web server api 的時間 !2. 節省解析文檔 (json, xml) 的時間節省 50% 時間!

• 可以參考 "App Engine Java Endpoints Module" Template

https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints

參考內容 :1. IROMIN Gradle Tutorial

http://rominirani.com/2014/07/28/gradle-tutorial-series-an-overview/

2. Wiki https://en.wikipedia.org/wiki/Gradle

Gradle 參考資料

top related