說實話 開始接觸這個工具 真的認為非常惡心 畢竟大陸被墻? 非常多東西用起來不是非常方便 并且Eclipse轉到Android Studio還是一個跨度 廢話不多說? 以下 講下我遇到的問題
1. 安裝的時候(Setup Wizard - Download Components) 這個要下載非常長時間 甚至下載不了 (PS: 這個選擇并下載2.25G的組件是studio的一個bug,評論里有人提醒,感謝這位同學。
假設網速不行想跳過這步的能夠在bin文件夾的idea.properties添加一行:disable.android.first.run=true即可了。mac平臺的右鍵安裝包->Show Package Contents 就找到bin文件夾了。)
?
2.新建項目成功后會下載Gradle,貌似這個過程不FQ也是能夠下載,可是訪問特別慢,建議FQ下載。那么下載的Gradle到什么地方呢?? 打開C:\Users\Administrator\.gradle\wrapper\dists\gradle-1.10-all\d90a2yjknzzhpcfgm937zpcte 你會看到須要的gradle版本號 比如我的是gradle-1.10 我會去百度上搜這個下載 一大堆 下載之后把gradle-1.10-all.zip拷貝到此文件夾下(C:\Users\Administrator\.gradle\wrapper\dists\gradle-1.10-all\d90a2yjknzzhpcfgm937zpcte)
?
注:假設是導入一個項目一直處于Building 那么去改動項目Gradle文件夾下的gradle-wrapper.properties 文件中邊的distributionUrl 最后邊改成已經下載的gradle版本號比如 我已經有gradle-2.2.1-all.zip 可是沒有gradle-2.4-all.zip的 所以我會改成distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
?
假設導入項目之后 下載Android studio那么結束掉任務 去改動項目根文件夾下的build.gradle
改成你如今的版本號
?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. 關于build.gradle的配置:
?? 主projectapp:
??? apply plugin: 'com.android.application'? 表示申明此project為主project
?
?dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])? 默認不須要多解釋
compile project(':StudioKlowerBase')}? 申明主工程依賴的Library 注意拼寫規則, 名字要與你的Library名字一樣
?
buildTypes {release {minifyEnabled true(表示打包簽名的時候 是正式包 會運行混淆代碼)
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
定義代碼混淆文件 注意:proguard-rules.pro要放在主project的文件夾下
}
}
完整代碼例如以下:
apply plugin: 'com.android.application'android {compileSdkVersion 19buildToolsVersion "19.1.0"defaultConfig {applicationId "com.klowerbase.test"minSdkVersion 11targetSdkVersion 19versionCode 1versionName "1.0"}buildTypes {release {minifyEnabled trueproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}
}dependencies {compile fileTree(dir: 'libs', include: ['*.jar'])compile project(':StudioKlowerBase')
}
--Library 工程的配置
apply plugin: 'android-library'定義為Library
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 19buildToolsVersion "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')}
}
項目的配置 代碼例如以下
// 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目錄 又一次導入程序
經過實驗:另外一種方法 有效
因為我用的gradle-2.2.1 項目結構有些變化,例如以下截圖:
<img src="https://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 優化導入的類和包
Alt+Insert 生成代碼(如get,set方法,構造函數等)
Ctrl+Shift+Space 自己主動補全代碼
Ctrl+空格 代碼提示
Ctrl+R 替換
Ctrl+Y 刪除行(ctrl+x不是刪除行。是剪切。
假設不選中,則為剪切當行。
ths for 貌似掉線) Ctrl+D 復制行 Ctrl+/ 或 Ctrl+Shift+/? 凝視(// 或者/*...*/ )
?
?
?
?
?
?
?
?
?
?
?