標籤:android開發
Android Studio 簡介
Android Studio 是Google近年來推薦的Android開發IDE,相對於Eclipse,它針對Android開發做了各種走心的最佳化,並提供了一系列方便的小工具。下面來體驗一下。
環境:
Windows 8.1 64bit
GiONEE C605
下載&調教
下載完雙擊一路下一步就可以了。
調教方面主要是主題和字型設定。相關的設定都在 File->settings 裡面
UI字型設定為雅黑14,編輯器字型設定為Consolas 16.
真機測試
首先建議給電腦裝上手機的驅動,最簡單的方法就是用企鵝的應用寶連一下,驅動就自動安裝好了。
建立一個測試工程,插上手機,run。
看一下目錄結構,和Eclipse的項目還是有點小區別的,最好切換到Project模式(左上方那裡),目錄挨個說說
頂層的目錄
1. App
應用相關檔案存放的位置,源碼,資源等。
2. .idea
一些meta資料存放的地方,比如Eclipse中的project.properties檔案。
3. build
這裡指的最外層的build,是gradle指令碼執行產生的檔案。
4. gradle
gradle構建指令碼存放的地方
app下的詳細的目錄
1. build
和eclipse裡面的build目錄類似,大部分是由java產生的位元組碼檔案。
2. libs
和eclipse裡面的build目錄類似,存放需要引用的.jar檔案
3. src
細分了java檔案和資源檔。
和Eclipse的區別有如下
1、Studio中有Project和Module的概念,前面說到Studio中一個視窗只能有一個項目,即Project,代表一個workspace,但是一個Project可以包含多個Module,比如你項目引用的Android Library, Java Library等,這些都可以看做是一個Module;
2、上述目錄中將java代碼和資源檔(圖片、布局檔案等)全部歸結為src,在src目錄下有一個main的分組,同時劃分出java和res兩個檔案夾,java檔案夾則相當於Eclipse下的src檔案夾,res目錄結構則一樣.
Modular 的概念
Modules are a "discrete unit of functionality that can be run, tested, and debugged independently" and are somewhat similar to an Eclipse project with a few key differences.
Each Module needs to have it‘s own Gradle build file(generally automatically generated for you when you create a new one, otherwise you can generate them if you are exporting a project from Eclipse). These Gradle files contain important details such as supported Android version ranges, dependencies and other meta-data about your Android project.
Just like in Eclipse, some Modules may be "Library Modules" which are conceptually the same as "Library projects."
Modular的建立直接File->create new 就可以了。
gradle入門
稍微瞭解了一下,感覺就是一個更加靈活的項目組態工具。
app/build.gradle內容如下
//聲明是Android程式apply plugin: ‘com.android.application‘android { //編譯的SDK compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { //應用的包名 applicationId "com.studiotest.river.testapplication" minSdkVersion 15 targetSdkVersion 22 versionCode 1 versionName "1.0" } //編譯選項 buildTypes { //Release編譯模式 release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘ } }}//包依賴dependencies { compile fileTree(dir: ‘libs‘, include: [‘*.jar‘]) compile ‘com.android.support:appcompat-v7:22.1.1‘}
gradle-wrapper.properties - 聲明了gradle的目錄與下載路徑以及當前項目使用的gradle版本
#Wed Apr 10 15:27:10 PDT 2013distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
build.gradle 英文注釋已經寫得很明白了,作為頂層的build檔案,可以添加適用於所有module的編譯選項,比如最小gradle版本。
repositories用於聲明倉庫的源。
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { repositories { jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:1.2.3‘ // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}allprojects { repositories { jcenter() }}
關於jcenter
JCenter is the place to find and share popular Apache Maven packages for use by Maven, Gradle, Ivy, SBT, etc.
For the most comprehensive collection of artifacts, point your Maven at: http://jcenter.bintray.com
Want to distribute your own packages through JCenter? You can link your package by clicking the "Include My Package" button.
And if you‘re into legacy, you can even synchronize your packages directly to Maven Central.
參考
Android Studio系列教程四--Gradle基礎 - http://stormzhang.com/devtools/2014/12/18/android-studio-tutorial4/
Migrating From Eclipse Projects - http://tools.android.com/tech-docs/new-build-system/migrating-from-eclipse-projects
Android Studio 初探