說(shuō)實(shí)話 開(kāi)始接觸這個(gè)工具 真的覺(jué)得很惡心 畢竟大陸被墻 很多東西用起來(lái)不是很方便 而且Eclipse轉(zhuǎn)到Android Studio還是一個(gè)跨度 廢話不多說(shuō) 下面 講下我遇到的問(wèn)題
1. 安裝的時(shí)候(Setup Wizard - Download Components) 這個(gè)要下載很長(zhǎng)時(shí)間 甚至下載不了 (PS: 這個(gè)選擇并下載2.25G的組件是studio的一個(gè)bug,評(píng)論里有人提醒,感謝這位同學(xué)。如果網(wǎng)速不行想跳過(guò)這步的可以在bin目錄的idea.properties增加一行:disable.android.first.run=true就行了,mac平臺(tái)的右鍵安裝包->Show Package Contents 就找到bin目錄了。)
2.新建項(xiàng)目成功后會(huì)下載Gradle,貌似這個(gè)過(guò)程不翻墻也是可以下載,但是訪問(wèn)特別慢,建議翻墻下載。那么下載的Gradle到什么地方呢? 打開(kāi)C:\Users\Administrator\.gradle\wrapper\dists\gradle-1.10-all\d90a2yjknzzhpcfgm937zpcte 你會(huì)看到需要的gradle版本 例如我的是gradle-1.10 我會(huì)去百度上搜這個(gè)下載 一大堆 下載之后把gradle-1.10-all.zip復(fù)制到此目錄下(C:\Users\Administrator\.gradle\wrapper\dists\gradle-1.10-all\d90a2yjknzzhpcfgm937zpcte)
注:如果是導(dǎo)入一個(gè)項(xiàng)目一直處于Building 那么去修改項(xiàng)目Gradle目錄下的gradle-wrapper.properties 文件里邊的distributionUrl 最后邊改成已經(jīng)下載的gradle版本例如 我已經(jīng)有g(shù)radle-2.2.1-all.zip 但是沒(méi)有g(shù)radle-2.4-all.zip的 所以我會(huì)改成distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
如果導(dǎo)入項(xiàng)目之后 下載Android studio那么結(jié)束掉任務(wù) 去修改項(xiàng)目根目錄下的build.gradle
改成你現(xiàn)在的版本
dependencies {
classpath 'com.android.tools.build:gradle:1.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
3. 關(guān)于build.gradle的配置:
主工程app:
apply plugin: 'com.android.application' 表示申明此工程為主工程
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar']) 默認(rèn)不需要多解釋
compile project(':StudioKlowerBase')} 申明主工程依賴的Library 注意拼寫(xiě)規(guī)則, 名字要與你的Library名字一樣
buildTypes { release { minifyEnabled true(表示打包簽名的時(shí)候 是正式包 會(huì)執(zhí)行混淆代碼)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
定義代碼混淆文件 注意:proguard-rules.pro要放在主工程的目錄下
}}
完整代碼如下:
- apply plugin: 'com.android.application'
- android {
- compileSdkVersion 19
- buildToolsVersion "19.1.0"
- defaultConfig {
- applicationId "com.klowerbase.test"
- minSdkVersion 11
- targetSdkVersion 19
- versionCode 1
- versionName "1.0"
- }
- buildTypes {
- release {
- minifyEnabled true
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile project(':StudioKlowerBase')
- }
--Library 工程的配置apply plugin: 'android-library'定義為L(zhǎng)ibrary
dependencies { classpath 'com.android.tools.build:gradle:1.2.2' 定義編譯的gradle版本
}
完整代碼如下:
- buildscript {
- repositories {
- mavenCentral()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.2.2'
- }
- }
- apply plugin: 'android-library'
- dependencies {
- compile fileTree(include: '*.jar', dir: 'libs')
- }
- android {
- compileSdkVersion 19
- buildToolsVersion "19.1.0"
- sourceSets {
- main {
- manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = ['src']
- resources.srcDirs = ['src']
- aidl.srcDirs = ['src']
- renderscript.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = ['assets']
- }
- // Move the tests to tests/java, tests/res, etc...
- instrumentTest.setRoot('tests')
- // Move the build types to build-types/<type>
- // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
- // This moves them out of them default location under src/<type>/... which would
- // conflict with src/ being used by the main source set.
- // Adding new build types or product flavors should be accompanied
- // by a similar customization.
- debug.setRoot('build-types/debug')
- release.setRoot('build-types/release')
- }
- }
項(xiàng)目的配置 代碼如下
- // 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.2'
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
- }
- allprojects {
- repositories {
- jcenter()
- }
- }
- 解決Task '' not found in root project '***'.
- 方法1:刪掉.iml里的<component name="FacetManager"> ... </component>
- 方法2:刪掉.iml跟.idea文件夾 重新導(dǎo)入程序
- 經(jīng)過(guò)實(shí)驗(yàn):第二種方法 有效
- 由于我用的gradle-2.2.1 項(xiàng)目結(jié)構(gòu)有些變化,如下截圖:
- <img src="http://img.blog.csdn.net/20150720130051120?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
最后在附上一些常用的快捷鍵:Ctrl+Alt+L 格式化代碼
Ctrl+Alt+space 代碼提示
Ctrl+Alt+O 優(yōu)化導(dǎo)入的類和包
Alt+Insert 生成代碼(如get,set方法,構(gòu)造函數(shù)等)
Ctrl+Shift+Space 自動(dòng)補(bǔ)全代碼
Ctrl+空格 代碼提示
Ctrl+R 替換
Ctrl+Y 刪除行(ctrl+x不是刪除行,是剪切。如果不選中,則為剪切當(dāng)行。ths for 貌似掉線)Ctrl+D 復(fù)制行Ctrl+/ 或 Ctrl+Shift+/ 注釋(// 或者/*...*/ )
聯(lián)系客服