Android Studio 初探

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 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值